From fe498e5edaaedcd5f4fe9fe9c14ee23c5cf879dc Mon Sep 17 00:00:00 2001 From: Adam S Levy Date: Mon, 27 Aug 2018 10:02:41 -0800 Subject: [PATCH 1/7] build(go111): Add go module support --- .gitignore | 2 ++ go.mod | 3 +++ go.sum | 4 ++++ gocomplete/go.mod | 6 ++++++ gocomplete/go.sum | 6 ++++++ 5 files changed, 21 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 gocomplete/go.mod create mode 100644 gocomplete/go.sum diff --git a/.gitignore b/.gitignore index 1363720..293955f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea coverage.txt +gocomplete/gocomplete +example/self/self diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fef0c44 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/posener/complete + +require github.com/hashicorp/go-multierror v1.0.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d2f1330 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= diff --git a/gocomplete/go.mod b/gocomplete/go.mod new file mode 100644 index 0000000..d312331 --- /dev/null +++ b/gocomplete/go.mod @@ -0,0 +1,6 @@ +module gocomplete + +require ( + github.com/hashicorp/go-multierror v1.0.0 // indirect + github.com/posener/complete v1.1.2 +) diff --git a/gocomplete/go.sum b/gocomplete/go.sum new file mode 100644 index 0000000..75d894d --- /dev/null +++ b/gocomplete/go.sum @@ -0,0 +1,6 @@ +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/posener/complete v1.1.2 h1:fS9GkqLN9DIpHg9j3fAPHdj5P3LhzxuoSybQd1v26IE= +github.com/posener/complete v1.1.2/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= From 5b53660969130ac18dbf017947bcf6c0004d36ff Mon Sep 17 00:00:00 2001 From: Adam S Levy Date: Mon, 27 Aug 2018 11:57:08 -0800 Subject: [PATCH 2/7] fix(go clean): Added missing flags Added missing flags go clean -cache -testcache -modcache --- gocomplete/complete.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gocomplete/complete.go b/gocomplete/complete.go index 7b95c1a..d32b62d 100644 --- a/gocomplete/complete.go +++ b/gocomplete/complete.go @@ -449,7 +449,7 @@ func main() { "-unusedfuncs": complete.PredictAnything, "-unusedresult": complete.PredictNothing, "-unusedstringmethods": complete.PredictAnything, - "-v": complete.PredictNothing, + "-v": complete.PredictNothing, }, Args: anyGo, }, @@ -458,10 +458,13 @@ func main() { clean := complete.Command{ Flags: complete.Flags{ - "-i": complete.PredictNothing, - "-r": complete.PredictNothing, - "-n": complete.PredictNothing, - "-x": complete.PredictNothing, + "-i": complete.PredictNothing, + "-r": complete.PredictNothing, + "-n": complete.PredictNothing, + "-x": complete.PredictNothing, + "-cache": complete.PredictNothing, + "-testcache": complete.PredictNothing, + "-modcache": complete.PredictNothing, }, Args: complete.PredictOr(anyPackage, ellipsis), } From 7516f04703c57869792fcd33ef1369de6e18122d Mon Sep 17 00:00:00 2001 From: Adam S Levy Date: Mon, 27 Aug 2018 11:59:20 -0800 Subject: [PATCH 3/7] feat(help,mod): Add completion for `go help` and `go mod` Go 1.11 introduces module support which adds a whole new set of commands. Add those commands for modules and also add the completion for the help commands and topics. --- gocomplete/complete.go | 117 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/gocomplete/complete.go b/gocomplete/complete.go index d32b62d..95f2002 100644 --- a/gocomplete/complete.go +++ b/gocomplete/complete.go @@ -480,6 +480,121 @@ func main() { Args: anyGo, } + modDownload := complete.Command{ + Flags: complete.Flags{ + "-json": complete.PredictNothing, + }, + Args: anyPackage, + } + + modEdit := complete.Command{ + Flags: complete.Flags{ + "-fmt": complete.PredictNothing, + "-module": complete.PredictNothing, + "-print": complete.PredictNothing, + + "-exclude": anyPackage, + "-dropexclude": anyPackage, + "-replace": anyPackage, + "-dropreplace": anyPackage, + "-require": anyPackage, + "-droprequire": anyPackage, + }, + Args: complete.PredictFiles("go.mod"), + } + + modGraph := complete.Command{} + + modInit := complete.Command{ + Args: complete.PredictAnything, + } + + modTidy := complete.Command{ + Flags: complete.Flags{ + "-v": complete.PredictNothing, + }, + } + + modVendor := complete.Command{ + Flags: complete.Flags{ + "-v": complete.PredictNothing, + }, + } + + modVerify := complete.Command{} + + modWhy := complete.Command{ + Flags: complete.Flags{ + "-m": complete.PredictNothing, + "-vendor": complete.PredictNothing, + }, + Args: anyPackage, + } + + modHelp := complete.Command{ + Sub: complete.Commands{ + "download": complete.Command{}, + "edit": complete.Command{}, + "graph": complete.Command{}, + "init": complete.Command{}, + "tidy": complete.Command{}, + "vendor": complete.Command{}, + "verify": complete.Command{}, + "why": complete.Command{}, + }, + } + + mod := complete.Command{ + Sub: complete.Commands{ + "download": modDownload, + "edit": modEdit, + "graph": modGraph, + "init": modInit, + "tidy": modTidy, + "vendor": modVendor, + "verify": modVerify, + "why": modWhy, + "help": modHelp, + }, + } + + help := complete.Command{ + Sub: complete.Commands{ + "bug": complete.Command{}, + "build": complete.Command{}, + "clean": complete.Command{}, + "doc": complete.Command{}, + "env": complete.Command{}, + "fix": complete.Command{}, + "fmt": complete.Command{}, + "generate": complete.Command{}, + "get": complete.Command{}, + "install": complete.Command{}, + "list": complete.Command{}, + "mod": modHelp, + "run": complete.Command{}, + "test": complete.Command{}, + "tool": complete.Command{}, + "version": complete.Command{}, + "vet": complete.Command{}, + "buildmode": complete.Command{}, + "c": complete.Command{}, + "cache": complete.Command{}, + "environment": complete.Command{}, + "filetype": complete.Command{}, + "go.mod": complete.Command{}, + "gopath": complete.Command{}, + "gopath-get": complete.Command{}, + "goproxy": complete.Command{}, + "importpath": complete.Command{}, + "modules": complete.Command{}, + "module-get": complete.Command{}, + "packages": complete.Command{}, + "testflag": complete.Command{}, + "testfunc": complete.Command{}, + }, + } + // commands that also accepts the build flags for name, options := range build.Flags { test.Flags[name] = options @@ -507,6 +622,8 @@ func main() { "bug": bug, "fix": fix, "version": version, + "mod": mod, + "help": help, }, GlobalFlags: complete.Flags{ "-h": complete.PredictNothing, From f8e8106b9d8842bb4f7f42ebba46e273312d67d3 Mon Sep 17 00:00:00 2001 From: Adam S Levy Date: Wed, 29 Aug 2018 09:34:52 -0800 Subject: [PATCH 4/7] ci(go1.11): Add module support for go 1.11 CI testing --- .travis.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c2798f8..284ab63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,19 @@ language: go sudo: false go: + - 1.11 + - 1.10.x - 1.9 - 1.8 before_install: - - go get -u -t ./... - - go get -u gopkg.in/alecthomas/gometalinter.v1 + - GO111MODULE=on go get -u -t ./... + - GO111MODULE=on go get -u gopkg.in/alecthomas/gometalinter.v1 - gometalinter.v1 --install script: - gometalinter.v1 --config metalinter.json ./... - - ./test.sh + - GO111MODULE=on ./test.sh after_success: - bash <(curl -s https://codecov.io/bash) From 2ef7ee53077638b8fe50193632a9cce43b14596e Mon Sep 17 00:00:00 2001 From: Adam S Levy Date: Wed, 29 Aug 2018 09:41:37 -0800 Subject: [PATCH 5/7] ci(gometalinter): Use gometalinter.v2 over v1 --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 284ab63..3208066 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,12 +7,12 @@ go: - 1.8 before_install: - - GO111MODULE=on go get -u -t ./... - - GO111MODULE=on go get -u gopkg.in/alecthomas/gometalinter.v1 - - gometalinter.v1 --install + - go get -u -t ./... + - go get -u gopkg.in/alecthomas/gometalinter.v2 + - gometalinter.v2 --install script: - - gometalinter.v1 --config metalinter.json ./... + - gometalinter.v2 --config metalinter.json ./... - GO111MODULE=on ./test.sh after_success: From 8200804f123c4addbbee90b9f48698fb0608cbc7 Mon Sep 17 00:00:00 2001 From: Adam S Levy Date: Wed, 29 Aug 2018 09:47:36 -0800 Subject: [PATCH 6/7] refactor(log,cmd/install/fish): Small refactors to pass gometalinter.v2 --- cmd/install/fish.go | 2 +- log.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/install/fish.go b/cmd/install/fish.go index f04e7c3..6b588db 100644 --- a/cmd/install/fish.go +++ b/cmd/install/fish.go @@ -46,5 +46,5 @@ end complete -c {{.Cmd}} -a "(__complete_{{.Cmd}})" `)).Execute(&buf, params) - return string(buf.Bytes()) + return buf.String() } diff --git a/log.go b/log.go index 797a80c..c302955 100644 --- a/log.go +++ b/log.go @@ -1,7 +1,6 @@ package complete import ( - "io" "io/ioutil" "log" "os" @@ -15,7 +14,7 @@ import ( var Log = getLogger() func getLogger() func(format string, args ...interface{}) { - var logfile io.Writer = ioutil.Discard + var logfile = ioutil.Discard if os.Getenv(envDebug) != "" { logfile = os.Stderr } From dcfd7da4e1804e7fa63d06a2071e68e8e347c40b Mon Sep 17 00:00:00 2001 From: Eyal Posener Date: Sun, 9 Sep 2018 17:44:11 +0300 Subject: [PATCH 7/7] Disable gometalinter I will move the repo to golangci.com linter later on --- .travis.yml | 3 --- metalinter.json | 21 --------------------- 2 files changed, 24 deletions(-) delete mode 100644 metalinter.json diff --git a/.travis.yml b/.travis.yml index 3208066..2fae945 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,11 +8,8 @@ go: before_install: - go get -u -t ./... - - go get -u gopkg.in/alecthomas/gometalinter.v2 - - gometalinter.v2 --install script: - - gometalinter.v2 --config metalinter.json ./... - GO111MODULE=on ./test.sh after_success: diff --git a/metalinter.json b/metalinter.json deleted file mode 100644 index 799c1d0..0000000 --- a/metalinter.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "Vendor": true, - "DisableAll": true, - "Enable": [ - "gofmt", - "goimports", - "interfacer", - "goconst", - "misspell", - "unconvert", - "gosimple", - "golint", - "structcheck", - "deadcode", - "vet" - ], - "Exclude": [ - "initTests is unused" - ], - "Deadline": "2m" -}