Bump github.com/hashicorp/terraform-plugin-docs from 0.7.0 to 0.13.0
Bumps [github.com/hashicorp/terraform-plugin-docs](https://github.com/hashicorp/terraform-plugin-docs) from 0.7.0 to 0.13.0. - [Release notes](https://github.com/hashicorp/terraform-plugin-docs/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-docs/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/terraform-plugin-docs/compare/v0.7.0...v0.13.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-docs dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
2
vendor/github.com/posener/complete/.gitignore
generated
vendored
2
vendor/github.com/posener/complete/.gitignore
generated
vendored
@ -1,2 +1,4 @@
|
||||
.idea
|
||||
coverage.txt
|
||||
gocomplete/gocomplete
|
||||
example/self/self
|
||||
|
19
vendor/github.com/posener/complete/.travis.yml
generated
vendored
19
vendor/github.com/posener/complete/.travis.yml
generated
vendored
@ -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
|
@ -1,27 +1,29 @@
|
||||
# complete
|
||||
|
||||
A tool for bash writing bash completion in go, and bash completion for the go command line.
|
||||
|
||||
[](https://travis-ci.org/posener/complete)
|
||||
[](https://codecov.io/gh/posener/complete)
|
||||
[](https://golangci.com/r/github.com/posener/complete)
|
||||
[](http://godoc.org/github.com/posener/complete)
|
||||
[](https://goreportcard.com/report/github.com/posener/complete)
|
||||
[](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) .
|
||||
|
||||
Here is an [example](./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.
|
||||
|
||||
|
||||
---
|
||||
|
||||
Created by [goreadme](https://github.com/apps/goreadme)
|
24
vendor/github.com/posener/complete/args.go
generated
vendored
24
vendor/github.com/posener/complete/args.go
generated
vendored
@ -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
|
||||
}
|
||||
|
||||
|
2
vendor/github.com/posener/complete/cmd/cmd.go
generated
vendored
2
vendor/github.com/posener/complete/cmd/cmd.go
generated
vendored
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
13
vendor/github.com/posener/complete/cmd/install/bash.go
generated
vendored
13
vendor/github.com/posener/complete/cmd/install/bash.go
generated
vendored
@ -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)
|
||||
}
|
||||
|
||||
|
47
vendor/github.com/posener/complete/cmd/install/fish.go
generated
vendored
47
vendor/github.com/posener/complete/cmd/install/fish.go
generated
vendored
@ -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
|
||||
}
|
||||
|
33
vendor/github.com/posener/complete/cmd/install/install.go
generated
vendored
33
vendor/github.com/posener/complete/cmd/install/install.go
generated
vendored
@ -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
|
||||
|
5
vendor/github.com/posener/complete/cmd/install/utils.go
generated
vendored
5
vendor/github.com/posener/complete/cmd/install/utils.go
generated
vendored
@ -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
|
||||
|
13
vendor/github.com/posener/complete/cmd/install/zsh.go
generated
vendored
13
vendor/github.com/posener/complete/cmd/install/zsh.go
generated
vendored
@ -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)
|
||||
}
|
||||
|
||||
|
39
vendor/github.com/posener/complete/complete.go
generated
vendored
39
vendor/github.com/posener/complete/complete.go
generated
vendored
@ -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
|
||||
}
|
||||
return line, true
|
||||
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, point, true
|
||||
}
|
||||
|
||||
func (c *Complete) output(options []string) {
|
||||
|
110
vendor/github.com/posener/complete/doc.go
generated
vendored
Normal file
110
vendor/github.com/posener/complete/doc.go
generated
vendored
Normal file
@ -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
|
9
vendor/github.com/posener/complete/goreadme.json
generated
vendored
Normal file
9
vendor/github.com/posener/complete/goreadme.json
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"badges": {
|
||||
"travis_ci": true,
|
||||
"code_cov": true,
|
||||
"golang_ci": true,
|
||||
"go_doc": true,
|
||||
"goreadme": true
|
||||
}
|
||||
}
|
3
vendor/github.com/posener/complete/log.go
generated
vendored
3
vendor/github.com/posener/complete/log.go
generated
vendored
@ -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
|
||||
}
|
||||
|
19
vendor/github.com/posener/complete/match/file.go
generated
vendored
19
vendor/github.com/posener/complete/match/file.go
generated
vendored
@ -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)
|
||||
}
|
6
vendor/github.com/posener/complete/match/match.go
generated
vendored
6
vendor/github.com/posener/complete/match/match.go
generated
vendored
@ -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
|
9
vendor/github.com/posener/complete/match/prefix.go
generated
vendored
9
vendor/github.com/posener/complete/match/prefix.go
generated
vendored
@ -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)
|
||||
}
|
21
vendor/github.com/posener/complete/metalinter.json
generated
vendored
21
vendor/github.com/posener/complete/metalinter.json
generated
vendored
@ -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"
|
||||
}
|
74
vendor/github.com/posener/complete/predict_files.go
generated
vendored
74
vendor/github.com/posener/complete/predict_files.go
generated
vendored
@ -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
|
||||
}
|
||||
|
12
vendor/github.com/posener/complete/test.sh
generated
vendored
12
vendor/github.com/posener/complete/test.sh
generated
vendored
@ -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
|
46
vendor/github.com/posener/complete/utils.go
generated
vendored
46
vendor/github.com/posener/complete/utils.go
generated
vendored
@ -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
|
||||
}
|
Reference in New Issue
Block a user