From 7469ab04d15d70d4e99e0f795817b540175cb31a Mon Sep 17 00:00:00 2001 From: Daniel Wu Date: Sat, 26 Aug 2023 22:38:21 -0400 Subject: [PATCH] add windows support --- cli/.gitignore | 1 + cli/.goreleaser.yaml | 18 ++++---- cli/completions.sh | 9 ++++ cli/go.mod | 10 ++-- cli/go.sum | 16 +++---- ...exec_bash_cmd.go => exec_bash_cmd_unix.go} | 37 +-------------- cli/pkg/exec_bash_cmd_windows.go | 46 +++++++++++++++++++ go.work | 3 ++ go.work.sum | 15 ++++++ 9 files changed, 99 insertions(+), 56 deletions(-) create mode 100755 cli/completions.sh rename cli/pkg/{exec_bash_cmd.go => exec_bash_cmd_unix.go} (66%) create mode 100644 cli/pkg/exec_bash_cmd_windows.go create mode 100644 go.work create mode 100644 go.work.sum diff --git a/cli/.gitignore b/cli/.gitignore index cde012322..a73a37a5f 100644 --- a/cli/.gitignore +++ b/cli/.gitignore @@ -1,2 +1,3 @@ dist/ +completions \ No newline at end of file diff --git a/cli/.goreleaser.yaml b/cli/.goreleaser.yaml index a65edfee5..beba5b4d1 100644 --- a/cli/.goreleaser.yaml +++ b/cli/.goreleaser.yaml @@ -4,8 +4,8 @@ before: hooks: # You may remove this if you don't use go modules. - go mod tidy - # you may remove this if you don't need go generate - - go generate ./... + # generate completion script + - ./completions.sh builds: - env: - CGO_ENABLED=0 @@ -13,6 +13,7 @@ builds: - linux - windows - darwin + binary: cli archives: - format: tar.gz @@ -26,19 +27,20 @@ archives: {{- if .Arm }}v{{ .Arm }}{{ end }} # use zip for windows archives format_overrides: - - goos: windows - format: zip + - goos: windows + format: zip + files: + - completions/* checksum: - name_template: 'checksums.txt' + name_template: "checksums.txt" snapshot: name_template: "{{ incpatch .Version }}-next" changelog: sort: asc filters: exclude: - - '^docs:' - - '^test:' - + - "^docs:" + - "^test:" # The lines beneath this are called `modelines`. See `:help modeline` # Feel free to remove those if you don't want/use them. # yaml-language-server: $schema=https://goreleaser.com/static/schema.json diff --git a/cli/completions.sh b/cli/completions.sh new file mode 100755 index 000000000..5688be19e --- /dev/null +++ b/cli/completions.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# completions.sh +set -e +rm -rf completions +mkdir completions + +for sh in bash zsh fish; do + go run main.go completion "$sh" >"completions/cli.$sh" +done \ No newline at end of file diff --git a/cli/go.mod b/cli/go.mod index d68c1b8a7..c2177502c 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -3,26 +3,26 @@ module github.com/DSGT-DLP/Deep-Learning-Playground/cli go 1.21.0 require ( - github.com/creack/pty v1.1.18 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.16.0 - golang.org/x/term v0.11.0 ) require ( + github.com/creack/pty v1.1.18 github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/pelletier/go-toml/v2 v2.0.9 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/subosito/gotenv v1.4.2 // indirect + github.com/subosito/gotenv v1.6.0 // indirect golang.org/x/sys v0.11.0 // indirect - golang.org/x/text v0.9.0 // indirect + golang.org/x/term v0.11.0 + golang.org/x/text v0.12.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/cli/go.sum b/cli/go.sum index 0aa2f3427..553c7ce1a 100644 --- a/cli/go.sum +++ b/cli/go.sum @@ -144,8 +144,8 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= -github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0= +github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -176,10 +176,10 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= -github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -330,8 +330,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/cli/pkg/exec_bash_cmd.go b/cli/pkg/exec_bash_cmd_unix.go similarity index 66% rename from cli/pkg/exec_bash_cmd.go rename to cli/pkg/exec_bash_cmd_unix.go index d7a4be7df..a12c4c9be 100644 --- a/cli/pkg/exec_bash_cmd.go +++ b/cli/pkg/exec_bash_cmd_unix.go @@ -1,3 +1,5 @@ +//go:build !windows + package pkg import ( @@ -52,38 +54,3 @@ func ExecBashCmd(dir string, name string, arg ...string) { go func() { io.Copy(ptmx, os.Stdin) }() io.Copy(os.Stdout, ptmx) } - -/* -func ExecBashCmd2(dir string, name string, arg ...string) { - // Use this if the pty one doesn't work - bash_cmd := exec.Command(name, arg...) - bash_cmd.Dir = dir - fmt.Println(strings.Join(bash_cmd.Args, " ")) - - stdoutPipe, _ := bash_cmd.StdoutPipe() - stderrPipe, _ := bash_cmd.StderrPipe() - err := bash_cmd.Start() - if err != nil { - fmt.Println("Error starting cmd: ", err) - return - } - var wg sync.WaitGroup - wg.Add(2) - - go func() { - defer wg.Done() - io.Copy(os.Stdout, stdoutPipe) - }() - - go func() { - defer wg.Done() - io.Copy(os.Stderr, stderrPipe) - }() - - wg.Wait() - err = bash_cmd.Wait() - if err != nil { - fmt.Println("Error waiting for cmd: ", err) - return - } -}*/ diff --git a/cli/pkg/exec_bash_cmd_windows.go b/cli/pkg/exec_bash_cmd_windows.go new file mode 100644 index 000000000..d31a70e0a --- /dev/null +++ b/cli/pkg/exec_bash_cmd_windows.go @@ -0,0 +1,46 @@ +//go:build windows + +package pkg + +import ( + "fmt" + "io" + "os" + "os/exec" + "strings" + "sync" +) + +func ExecBashCmd(dir string, name string, arg ...string) { + // Use this if the pty one doesn't work + bash_cmd := exec.Command(name, arg...) + bash_cmd.Dir = dir + fmt.Println(strings.Join(bash_cmd.Args, " ")) + + stdoutPipe, _ := bash_cmd.StdoutPipe() + stderrPipe, _ := bash_cmd.StderrPipe() + err := bash_cmd.Start() + if err != nil { + fmt.Println("Error starting cmd: ", err) + return + } + var wg sync.WaitGroup + wg.Add(2) + + go func() { + defer wg.Done() + io.Copy(os.Stdout, stdoutPipe) + }() + + go func() { + defer wg.Done() + io.Copy(os.Stderr, stderrPipe) + }() + + wg.Wait() + err = bash_cmd.Wait() + if err != nil { + fmt.Println("Error waiting for cmd: ", err) + return + } +} diff --git a/go.work b/go.work new file mode 100644 index 000000000..5eb68700d --- /dev/null +++ b/go.work @@ -0,0 +1,3 @@ +go 1.21.0 + +use ./cli diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 000000000..cfc5d0dec --- /dev/null +++ b/go.work.sum @@ -0,0 +1,15 @@ +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=