diff --git a/go.mod b/go.mod index 598e7b496ad..1ad01609ef0 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/operator-framework/api v0.14.1-0.20220413143725-33310d6154f3 github.com/operator-framework/operator-lifecycle-manager v0.21.2 github.com/pborman/uuid v1.2.1 - github.com/posener/complete v1.1.1 + github.com/posener/complete v1.2.3 github.com/redhat-developer/alizer/go v0.0.0-20220530162645-f27a60be88a1 github.com/redhat-developer/service-binding-operator v1.0.1-0.20211222115357-5b7bbba3bfb3 github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 diff --git a/go.sum b/go.sum index 1441be43d68..d1e33f3f0f4 100644 --- a/go.sum +++ b/go.sum @@ -1016,8 +1016,9 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= github.com/prometheus/client_golang v0.0.0-20180209125602-c332b6f63c06/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= diff --git a/scripts/generate-mod.sh b/scripts/generate-mod.sh index 25d89df32a2..18b373fa117 100755 --- a/scripts/generate-mod.sh +++ b/scripts/generate-mod.sh @@ -25,6 +25,7 @@ go mod edit -replace github.com/apcera/gssapi=github.com/openshift/gssapi@v0.0.0 # Upgrades recommended by Dependabot go mod edit -require github.com/pborman/uuid@v1.2.1 +go mod edit -require github.com/posener/complete@v1.2.3 go mod tidy -compat=1.17 # why? diff --git a/vendor/github.com/posener/complete/.gitignore b/vendor/github.com/posener/complete/.gitignore index 1363720813e..293955f99ac 100644 --- a/vendor/github.com/posener/complete/.gitignore +++ b/vendor/github.com/posener/complete/.gitignore @@ -1,2 +1,4 @@ .idea coverage.txt +gocomplete/gocomplete +example/self/self diff --git a/vendor/github.com/posener/complete/.travis.yml b/vendor/github.com/posener/complete/.travis.yml index c2798f8f376..6ba8d865b13 100644 --- a/vendor/github.com/posener/complete/.travis.yml +++ b/vendor/github.com/posener/complete/.travis.yml @@ -1,17 +1,16 @@ language: go -sudo: false go: - - 1.9 - - 1.8 - -before_install: - - go get -u -t ./... - - go get -u gopkg.in/alecthomas/gometalinter.v1 - - gometalinter.v1 --install + - tip + - 1.12.x + - 1.11.x + - 1.10.x script: - - gometalinter.v1 --config metalinter.json ./... - - ./test.sh + - go test -race -coverprofile=coverage.txt -covermode=atomic ./... after_success: - bash <(curl -s https://codecov.io/bash) + +matrix: + allow_failures: + - go: tip \ No newline at end of file diff --git a/vendor/github.com/posener/complete/readme.md b/vendor/github.com/posener/complete/README.md similarity index 74% rename from vendor/github.com/posener/complete/readme.md rename to vendor/github.com/posener/complete/README.md index 2a999ba7620..dcc6c89324e 100644 --- a/vendor/github.com/posener/complete/readme.md +++ b/vendor/github.com/posener/complete/README.md @@ -1,27 +1,29 @@ # complete -A tool for bash writing bash completion in go, and bash completion for the go command line. - [![Build Status](https://travis-ci.org/posener/complete.svg?branch=master)](https://travis-ci.org/posener/complete) [![codecov](https://codecov.io/gh/posener/complete/branch/master/graph/badge.svg)](https://codecov.io/gh/posener/complete) +[![golangci](https://golangci.com/badges/github.com/posener/complete.svg)](https://golangci.com/r/github.com/posener/complete) [![GoDoc](https://godoc.org/github.com/posener/complete?status.svg)](http://godoc.org/github.com/posener/complete) -[![Go Report Card](https://goreportcard.com/badge/github.com/posener/complete)](https://goreportcard.com/report/github.com/posener/complete) +[![goreadme](https://goreadme.herokuapp.com/badge/posener/complete.svg)](https://goreadme.herokuapp.com) + +Package complete provides a tool for bash writing bash completion in go, and bash completion for the go command line. Writing bash completion scripts is a hard work. This package provides an easy way to create bash completion scripts for any command, and also an easy way to install/uninstall the completion of the command. -## go command bash completion +#### Go Command Bash Completion -In [gocomplete](./gocomplete) there is an example for bash completion for the `go` command line. +In [./cmd/gocomplete](./cmd/gocomplete) there is an example for bash completion for the `go` command line. This is an example that uses the `complete` package on the `go` command - the `complete` package -can also be used to implement any completions, see [Usage](#usage). +can also be used to implement any completions, see #usage. -### Install +#### Install 1. Type in your shell: -``` + +```go go get -u github.com/posener/complete/gocomplete gocomplete -install ``` @@ -30,13 +32,13 @@ gocomplete -install Uninstall by `gocomplete -uninstall` -### Features +#### Features - Complete `go` command, including sub commands and all flags. - Complete packages names or `.go` files when necessary. - Complete test names after `-run` flag. -## complete package +#### Complete package Supported shells: @@ -44,7 +46,7 @@ Supported shells: - [x] zsh - [x] fish -### Usage +#### Usage Assuming you have program called `run` and you want to have bash completion for it, meaning, if you type `run` then space, then press the `Tab` key, @@ -52,7 +54,7 @@ the shell will suggest relevant complete options. In that case, we will create a program called `runcomplete`, a go program, with a `func main()` and so, that will make the completion of the `run` -program. Once the `runcomplete` will be in a binary form, we could +program. Once the `runcomplete` will be in a binary form, we could `runcomplete -install` and that will add to our shell all the bash completion options for `run`. @@ -109,9 +111,21 @@ func main() { } ``` -### Self completing program +#### Self completing program In case that the program that we want to complete is written in go we can make it self completing. +Here is an example: [./example/self/main.go](./example/self/main.go) . + +## Sub Packages + +* [cmd](./cmd): Package cmd used for command line options for the complete tool + +* [gocomplete](./gocomplete): Package main is complete tool for the go command line + +* [match](./match): Package match contains matchers that decide if to apply completion. + + +--- -Here is an [example](./example/self/main.go) +Created by [goreadme](https://github.com/apps/goreadme) diff --git a/vendor/github.com/posener/complete/args.go b/vendor/github.com/posener/complete/args.go index 1ba4d69198f..3340285e1c7 100644 --- a/vendor/github.com/posener/complete/args.go +++ b/vendor/github.com/posener/complete/args.go @@ -28,6 +28,8 @@ type Args struct { // Directory gives the directory of the current written // last argument if it represents a file name being written. // in case that it is not, we fall back to the current directory. +// +// Deprecated. func (a Args) Directory() string { if info, err := os.Stat(a.Last); err == nil && info.IsDir() { return fixPathForm(a.Last, a.Last) @@ -57,11 +59,20 @@ func newArgs(line string) Args { } } +// splitFields returns a list of fields from the given command line. +// If the last character is space, it appends an empty field in the end +// indicating that the field before it was completed. +// If the last field is of the form "a=b", it splits it to two fields: "a", "b", +// So it can be completed. func splitFields(line string) []string { parts := strings.Fields(line) + + // Add empty field if the last field was completed. if len(line) > 0 && unicode.IsSpace(rune(line[len(line)-1])) { parts = append(parts, "") } + + // Treat the last field if it is of the form "a=b" parts = splitLastEqual(parts) return parts } @@ -74,16 +85,17 @@ func splitLastEqual(line []string) []string { return append(line[:len(line)-1], parts...) } +// from returns a copy of Args of all arguments after the i'th argument. func (a Args) from(i int) Args { - if i > len(a.All) { - i = len(a.All) + if i >= len(a.All) { + i = len(a.All) - 1 } - a.All = a.All[i:] + a.All = a.All[i+1:] - if i > len(a.Completed) { - i = len(a.Completed) + if i >= len(a.Completed) { + i = len(a.Completed) - 1 } - a.Completed = a.Completed[i:] + a.Completed = a.Completed[i+1:] return a } diff --git a/vendor/github.com/posener/complete/cmd/cmd.go b/vendor/github.com/posener/complete/cmd/cmd.go index 7137dee1783..b99fe529011 100644 --- a/vendor/github.com/posener/complete/cmd/cmd.go +++ b/vendor/github.com/posener/complete/cmd/cmd.go @@ -103,7 +103,7 @@ func (f *CLI) AddFlags(flags *flag.FlagSet) { fmt.Sprintf("Uninstall completion for %s command", f.Name)) } if flags.Lookup("y") == nil { - flags.BoolVar(&f.yes, "y", false, "Don't prompt user for typing 'yes'") + flags.BoolVar(&f.yes, "y", false, "Don't prompt user for typing 'yes' when installing completion") } } diff --git a/vendor/github.com/posener/complete/cmd/install/bash.go b/vendor/github.com/posener/complete/cmd/install/bash.go index a287f998655..17c64de1362 100644 --- a/vendor/github.com/posener/complete/cmd/install/bash.go +++ b/vendor/github.com/posener/complete/cmd/install/bash.go @@ -10,20 +10,25 @@ type bash struct { rc string } -func (b bash) Install(cmd, bin string) error { +func (b bash) IsInstalled(cmd, bin string) bool { completeCmd := b.cmd(cmd, bin) - if lineInFile(b.rc, completeCmd) { + return lineInFile(b.rc, completeCmd) +} + +func (b bash) Install(cmd, bin string) error { + if b.IsInstalled(cmd, bin) { return fmt.Errorf("already installed in %s", b.rc) } + completeCmd := b.cmd(cmd, bin) return appendToFile(b.rc, completeCmd) } func (b bash) Uninstall(cmd, bin string) error { - completeCmd := b.cmd(cmd, bin) - if !lineInFile(b.rc, completeCmd) { + if !b.IsInstalled(cmd, bin) { return fmt.Errorf("does not installed in %s", b.rc) } + completeCmd := b.cmd(cmd, bin) return removeFromFile(b.rc, completeCmd) } diff --git a/vendor/github.com/posener/complete/cmd/install/fish.go b/vendor/github.com/posener/complete/cmd/install/fish.go index f04e7c3ac60..2b64bfc832b 100644 --- a/vendor/github.com/posener/complete/cmd/install/fish.go +++ b/vendor/github.com/posener/complete/cmd/install/fish.go @@ -14,37 +14,56 @@ type fish struct { configDir string } -func (f fish) Install(cmd, bin string) error { - completionFile := filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd)) - completeCmd := f.cmd(cmd, bin) +func (f fish) IsInstalled(cmd, bin string) bool { + completionFile := f.getCompletionFilePath(cmd) if _, err := os.Stat(completionFile); err == nil { - return fmt.Errorf("already installed at %s", completionFile) + return true + } + return false +} + +func (f fish) Install(cmd, bin string) error { + if f.IsInstalled(cmd, bin) { + return fmt.Errorf("already installed at %s", f.getCompletionFilePath(cmd)) + } + + completionFile := f.getCompletionFilePath(cmd) + completeCmd, err := f.cmd(cmd, bin) + if err != nil { + return err } return createFile(completionFile, completeCmd) } func (f fish) Uninstall(cmd, bin string) error { - completionFile := filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd)) - if _, err := os.Stat(completionFile); err != nil { + if !f.IsInstalled(cmd, bin) { return fmt.Errorf("does not installed in %s", f.configDir) } + completionFile := f.getCompletionFilePath(cmd) return os.Remove(completionFile) } -func (f fish) cmd(cmd, bin string) string { +func (f fish) getCompletionFilePath(cmd string) string { + return filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd)) +} + +func (f fish) cmd(cmd, bin string) (string, error) { var buf bytes.Buffer params := struct{ Cmd, Bin string }{cmd, bin} - template.Must(template.New("cmd").Parse(` + tmpl := template.Must(template.New("cmd").Parse(` function __complete_{{.Cmd}} - set -lx COMP_LINE (string join ' ' (commandline -o)) - test (commandline -ct) = "" + set -lx COMP_LINE (commandline -cp) + test -z (commandline -ct) and set COMP_LINE "$COMP_LINE " {{.Bin}} end -complete -c {{.Cmd}} -a "(__complete_{{.Cmd}})" -`)).Execute(&buf, params) - - return string(buf.Bytes()) +complete -f -c {{.Cmd}} -a "(__complete_{{.Cmd}})" +`)) + err := tmpl.Execute(&buf, params) + if err != nil { + return "", err + } + return buf.String(), nil } diff --git a/vendor/github.com/posener/complete/cmd/install/install.go b/vendor/github.com/posener/complete/cmd/install/install.go index 4a706242f44..884c23f5b46 100644 --- a/vendor/github.com/posener/complete/cmd/install/install.go +++ b/vendor/github.com/posener/complete/cmd/install/install.go @@ -5,11 +5,13 @@ import ( "os" "os/user" "path/filepath" + "runtime" "github.com/hashicorp/go-multierror" ) type installer interface { + IsInstalled(cmd, bin string) bool Install(cmd, bin string) error Uninstall(cmd, bin string) error } @@ -36,6 +38,24 @@ func Install(cmd string) error { return err } +// IsInstalled returns true if the completion +// for the given cmd is installed. +func IsInstalled(cmd string) bool { + bin, err := getBinaryPath() + if err != nil { + return false + } + + for _, i := range installers() { + installed := i.IsInstalled(cmd, bin) + if installed { + return true + } + } + + return false +} + // Uninstall complete command given: // cmd: is the command name func Uninstall(cmd string) error { @@ -51,7 +71,7 @@ func Uninstall(cmd string) error { for _, i := range is { errI := i.Uninstall(cmd, bin) if errI != nil { - multierror.Append(err, errI) + err = multierror.Append(err, errI) } } @@ -59,7 +79,16 @@ func Uninstall(cmd string) error { } func installers() (i []installer) { - for _, rc := range [...]string{".bashrc", ".bash_profile", ".bash_login", ".profile"} { + // The list of bash config files candidates where it is + // possible to install the completion command. + var bashConfFiles []string + switch runtime.GOOS { + case "darwin": + bashConfFiles = []string{".bash_profile"} + default: + bashConfFiles = []string{".bashrc", ".bash_profile", ".bash_login", ".profile"} + } + for _, rc := range bashConfFiles { if f := rcFile(rc); f != "" { i = append(i, bash{f}) break diff --git a/vendor/github.com/posener/complete/cmd/install/utils.go b/vendor/github.com/posener/complete/cmd/install/utils.go index bb709bc6cd9..d34ac8cae8b 100644 --- a/vendor/github.com/posener/complete/cmd/install/utils.go +++ b/vendor/github.com/posener/complete/cmd/install/utils.go @@ -115,7 +115,10 @@ func removeContentToTempFile(name, content string) (string, error) { if str == content { continue } - wf.WriteString(str + "\n") + _, err = wf.WriteString(str + "\n") + if err != nil { + return "", err + } prefix = prefix[:0] } return wf.Name(), nil diff --git a/vendor/github.com/posener/complete/cmd/install/zsh.go b/vendor/github.com/posener/complete/cmd/install/zsh.go index a625f53cf0c..29950ab171f 100644 --- a/vendor/github.com/posener/complete/cmd/install/zsh.go +++ b/vendor/github.com/posener/complete/cmd/install/zsh.go @@ -11,12 +11,17 @@ type zsh struct { rc string } -func (z zsh) Install(cmd, bin string) error { +func (z zsh) IsInstalled(cmd, bin string) bool { completeCmd := z.cmd(cmd, bin) - if lineInFile(z.rc, completeCmd) { + return lineInFile(z.rc, completeCmd) +} + +func (z zsh) Install(cmd, bin string) error { + if z.IsInstalled(cmd, bin) { return fmt.Errorf("already installed in %s", z.rc) } + completeCmd := z.cmd(cmd, bin) bashCompInit := "autoload -U +X bashcompinit && bashcompinit" if !lineInFile(z.rc, bashCompInit) { completeCmd = bashCompInit + "\n" + completeCmd @@ -26,11 +31,11 @@ func (z zsh) Install(cmd, bin string) error { } func (z zsh) Uninstall(cmd, bin string) error { - completeCmd := z.cmd(cmd, bin) - if !lineInFile(z.rc, completeCmd) { + if !z.IsInstalled(cmd, bin) { return fmt.Errorf("does not installed in %s", z.rc) } + completeCmd := z.cmd(cmd, bin) return removeFromFile(z.rc, completeCmd) } diff --git a/vendor/github.com/posener/complete/complete.go b/vendor/github.com/posener/complete/complete.go index 185d1e8bd2e..423cbec6c17 100644 --- a/vendor/github.com/posener/complete/complete.go +++ b/vendor/github.com/posener/complete/complete.go @@ -1,8 +1,3 @@ -// Package complete provides a tool for bash writing bash completion in go. -// -// Writing bash completion scripts is a hard work. This package provides an easy way -// to create bash completion scripts for any command, and also an easy way to install/uninstall -// the completion of the command. package complete import ( @@ -10,14 +5,16 @@ import ( "fmt" "io" "os" + "strconv" + "strings" "github.com/posener/complete/cmd" - "github.com/posener/complete/match" ) const ( - envComplete = "COMP_LINE" - envDebug = "COMP_DEBUG" + envLine = "COMP_LINE" + envPoint = "COMP_POINT" + envDebug = "COMP_DEBUG" ) // Complete structs define completion for a command with CLI options @@ -55,13 +52,18 @@ func (c *Complete) Run() bool { // For installation: it assumes that flags were added and parsed before // it was called. func (c *Complete) Complete() bool { - line, ok := getLine() + line, point, ok := getEnv() if !ok { // make sure flags parsed, // in case they were not added in the main program return c.CLI.Run() } - Log("Completing line: %s", line) + + if point >= 0 && point < len(line) { + line = line[:point] + } + + Log("Completing phrase: %s", line) a := newArgs(line) Log("Completing last field: %s", a.Last) options := c.Command.Predict(a) @@ -70,7 +72,7 @@ func (c *Complete) Complete() bool { // filter only options that match the last argument matches := []string{} for _, option := range options { - if match.Prefix(option, a.Last) { + if strings.HasPrefix(option, a.Last) { matches = append(matches, option) } } @@ -79,12 +81,19 @@ func (c *Complete) Complete() bool { return true } -func getLine() (string, bool) { - line := os.Getenv(envComplete) +func getEnv() (line string, point int, ok bool) { + line = os.Getenv(envLine) if line == "" { - return "", false + return + } + point, err := strconv.Atoi(os.Getenv(envPoint)) + if err != nil { + // If failed parsing point for some reason, set it to point + // on the end of the line. + Log("Failed parsing point %s: %v", os.Getenv(envPoint), err) + point = len(line) } - return line, true + return line, point, true } func (c *Complete) output(options []string) { diff --git a/vendor/github.com/posener/complete/doc.go b/vendor/github.com/posener/complete/doc.go new file mode 100644 index 00000000000..0ae09a1b74c --- /dev/null +++ b/vendor/github.com/posener/complete/doc.go @@ -0,0 +1,110 @@ +/* +Package complete provides a tool for bash writing bash completion in go, and bash completion for the go command line. + +Writing bash completion scripts is a hard work. This package provides an easy way +to create bash completion scripts for any command, and also an easy way to install/uninstall +the completion of the command. + +Go Command Bash Completion + +In ./cmd/gocomplete there is an example for bash completion for the `go` command line. + +This is an example that uses the `complete` package on the `go` command - the `complete` package +can also be used to implement any completions, see #usage. + +Install + +1. Type in your shell: + + go get -u github.com/posener/complete/gocomplete + gocomplete -install + +2. Restart your shell + +Uninstall by `gocomplete -uninstall` + +Features + +- Complete `go` command, including sub commands and all flags. +- Complete packages names or `.go` files when necessary. +- Complete test names after `-run` flag. + +Complete package + +Supported shells: + +- [x] bash +- [x] zsh +- [x] fish + +Usage + +Assuming you have program called `run` and you want to have bash completion +for it, meaning, if you type `run` then space, then press the `Tab` key, +the shell will suggest relevant complete options. + +In that case, we will create a program called `runcomplete`, a go program, +with a `func main()` and so, that will make the completion of the `run` +program. Once the `runcomplete` will be in a binary form, we could +`runcomplete -install` and that will add to our shell all the bash completion +options for `run`. + +So here it is: + + import "github.com/posener/complete" + + func main() { + + // create a Command object, that represents the command we want + // to complete. + run := complete.Command{ + + // Sub defines a list of sub commands of the program, + // this is recursive, since every command is of type command also. + Sub: complete.Commands{ + + // add a build sub command + "build": complete.Command { + + // define flags of the build sub command + Flags: complete.Flags{ + // build sub command has a flag '-cpus', which + // expects number of cpus after it. in that case + // anything could complete this flag. + "-cpus": complete.PredictAnything, + }, + }, + }, + + // define flags of the 'run' main command + Flags: complete.Flags{ + // a flag -o, which expects a file ending with .out after + // it, the tab completion will auto complete for files matching + // the given pattern. + "-o": complete.PredictFiles("*.out"), + }, + + // define global flags of the 'run' main command + // those will show up also when a sub command was entered in the + // command line + GlobalFlags: complete.Flags{ + + // a flag '-h' which does not expects anything after it + "-h": complete.PredictNothing, + }, + } + + // run the command completion, as part of the main() function. + // this triggers the autocompletion when needed. + // name must be exactly as the binary that we want to complete. + complete.New("run", run).Run() + } + +Self completing program + +In case that the program that we want to complete is written in go we +can make it self completing. +Here is an example: ./example/self/main.go . + +*/ +package complete diff --git a/vendor/github.com/posener/complete/goreadme.json b/vendor/github.com/posener/complete/goreadme.json new file mode 100644 index 00000000000..025ec76c98a --- /dev/null +++ b/vendor/github.com/posener/complete/goreadme.json @@ -0,0 +1,9 @@ +{ + "badges": { + "travis_ci": true, + "code_cov": true, + "golang_ci": true, + "go_doc": true, + "goreadme": true + } +} \ No newline at end of file diff --git a/vendor/github.com/posener/complete/log.go b/vendor/github.com/posener/complete/log.go index 797a80ced3a..c3029556e50 100644 --- a/vendor/github.com/posener/complete/log.go +++ b/vendor/github.com/posener/complete/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 } diff --git a/vendor/github.com/posener/complete/match/file.go b/vendor/github.com/posener/complete/match/file.go deleted file mode 100644 index 051171e8a11..00000000000 --- a/vendor/github.com/posener/complete/match/file.go +++ /dev/null @@ -1,19 +0,0 @@ -package match - -import "strings" - -// File returns true if prefix can match the file -func File(file, prefix string) bool { - // special case for current directory completion - if file == "./" && (prefix == "." || prefix == "") { - return true - } - if prefix == "." && strings.HasPrefix(file, ".") { - return true - } - - file = strings.TrimPrefix(file, "./") - prefix = strings.TrimPrefix(prefix, "./") - - return strings.HasPrefix(file, prefix) -} diff --git a/vendor/github.com/posener/complete/match/match.go b/vendor/github.com/posener/complete/match/match.go deleted file mode 100644 index 812fcac96b3..00000000000 --- a/vendor/github.com/posener/complete/match/match.go +++ /dev/null @@ -1,6 +0,0 @@ -package match - -// Match matches two strings -// it is used for comparing a term to the last typed -// word, the prefix, and see if it is a possible auto complete option. -type Match func(term, prefix string) bool diff --git a/vendor/github.com/posener/complete/match/prefix.go b/vendor/github.com/posener/complete/match/prefix.go deleted file mode 100644 index 9a01ba63a4e..00000000000 --- a/vendor/github.com/posener/complete/match/prefix.go +++ /dev/null @@ -1,9 +0,0 @@ -package match - -import "strings" - -// Prefix is a simple Matcher, if the word is it's prefix, there is a match -// Match returns true if a has the prefix as prefix -func Prefix(long, prefix string) bool { - return strings.HasPrefix(long, prefix) -} diff --git a/vendor/github.com/posener/complete/metalinter.json b/vendor/github.com/posener/complete/metalinter.json deleted file mode 100644 index 799c1d03f25..00000000000 --- a/vendor/github.com/posener/complete/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" -} diff --git a/vendor/github.com/posener/complete/predict_files.go b/vendor/github.com/posener/complete/predict_files.go index c8adf7e806c..25ae2d51440 100644 --- a/vendor/github.com/posener/complete/predict_files.go +++ b/vendor/github.com/posener/complete/predict_files.go @@ -5,8 +5,6 @@ import ( "os" "path/filepath" "strings" - - "github.com/posener/complete/match" ) // PredictDirs will search for directories in the given started to be typed @@ -53,7 +51,7 @@ func predictFiles(a Args, pattern string, allowFiles bool) []string { return nil } - dir := a.Directory() + dir := directory(a.Last) files := listFiles(dir, pattern, allowFiles) // add dir if match @@ -62,6 +60,19 @@ func predictFiles(a Args, pattern string, allowFiles bool) []string { return PredictFilesSet(files).Predict(a) } +// directory gives the directory of the given partial path +// in case that it is not, we fall back to the current directory. +func directory(path string) string { + if info, err := os.Stat(path); err == nil && info.IsDir() { + return fixPathForm(path, path) + } + dir := filepath.Dir(path) + if info, err := os.Stat(dir); err == nil && info.IsDir() { + return fixPathForm(path, dir) + } + return "./" +} + // PredictFilesSet predict according to file rules to a given set of file names func PredictFilesSet(files []string) PredictFunc { return func(a Args) (prediction []string) { @@ -70,7 +81,7 @@ func PredictFilesSet(files []string) PredictFunc { f = fixPathForm(a.Last, f) // test matching of file to the argument - if match.File(f, a.Last) { + if matchFile(f, a.Last) { prediction = append(prediction, f) } } @@ -106,3 +117,58 @@ func listFiles(dir, pattern string, allowFiles bool) []string { } return list } + +// MatchFile returns true if prefix can match the file +func matchFile(file, prefix string) bool { + // special case for current directory completion + if file == "./" && (prefix == "." || prefix == "") { + return true + } + if prefix == "." && strings.HasPrefix(file, ".") { + return true + } + + file = strings.TrimPrefix(file, "./") + prefix = strings.TrimPrefix(prefix, "./") + + return strings.HasPrefix(file, prefix) +} + +// fixPathForm changes a file name to a relative name +func fixPathForm(last string, file string) string { + // get wording directory for relative name + workDir, err := os.Getwd() + if err != nil { + return file + } + + abs, err := filepath.Abs(file) + if err != nil { + return file + } + + // if last is absolute, return path as absolute + if filepath.IsAbs(last) { + return fixDirPath(abs) + } + + rel, err := filepath.Rel(workDir, abs) + if err != nil { + return file + } + + // fix ./ prefix of path + if rel != "." && strings.HasPrefix(last, ".") { + rel = "./" + rel + } + + return fixDirPath(rel) +} + +func fixDirPath(path string) string { + info, err := os.Stat(path) + if err == nil && info.IsDir() && !strings.HasSuffix(path, "/") { + path += "/" + } + return path +} diff --git a/vendor/github.com/posener/complete/test.sh b/vendor/github.com/posener/complete/test.sh deleted file mode 100644 index 56bfcf15d16..00000000000 --- a/vendor/github.com/posener/complete/test.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -e -echo "" > coverage.txt - -for d in $(go list ./... | grep -v vendor); do - go test -v -race -coverprofile=profile.out -covermode=atomic $d - if [ -f profile.out ]; then - cat profile.out >> coverage.txt - rm profile.out - fi -done \ No newline at end of file diff --git a/vendor/github.com/posener/complete/utils.go b/vendor/github.com/posener/complete/utils.go deleted file mode 100644 index 58b8b792776..00000000000 --- a/vendor/github.com/posener/complete/utils.go +++ /dev/null @@ -1,46 +0,0 @@ -package complete - -import ( - "os" - "path/filepath" - "strings" -) - -// fixPathForm changes a file name to a relative name -func fixPathForm(last string, file string) string { - // get wording directory for relative name - workDir, err := os.Getwd() - if err != nil { - return file - } - - abs, err := filepath.Abs(file) - if err != nil { - return file - } - - // if last is absolute, return path as absolute - if filepath.IsAbs(last) { - return fixDirPath(abs) - } - - rel, err := filepath.Rel(workDir, abs) - if err != nil { - return file - } - - // fix ./ prefix of path - if rel != "." && strings.HasPrefix(last, ".") { - rel = "./" + rel - } - - return fixDirPath(rel) -} - -func fixDirPath(path string) string { - info, err := os.Stat(path) - if err == nil && info.IsDir() && !strings.HasSuffix(path, "/") { - path += "/" - } - return path -} diff --git a/vendor/modules.txt b/vendor/modules.txt index e04a192f7a4..d7393aab1ac 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -607,12 +607,11 @@ github.com/pkg/errors # github.com/pmezard/go-difflib v1.0.0 ## explicit github.com/pmezard/go-difflib/difflib -# github.com/posener/complete v1.1.1 -## explicit +# github.com/posener/complete v1.2.3 +## explicit; go 1.13 github.com/posener/complete github.com/posener/complete/cmd github.com/posener/complete/cmd/install -github.com/posener/complete/match # github.com/prometheus/client_golang v1.12.1 ## explicit; go 1.13 github.com/prometheus/client_golang/prometheus