vendor: github.com/posener/complete@v1.2.1

go get github.com/posener/complete@v1.2.1
go mod tidy
go mod vendor
This commit is contained in:
Radek Simko 2019-02-21 09:07:42 +00:00
parent c9e6bc4937
commit 52b38a486a
No known key found for this signature in database
GPG Key ID: 1F1C84FE689A88D7
16 changed files with 67 additions and 46 deletions

2
go.mod
View File

@ -99,7 +99,7 @@ require (
github.com/packer-community/winrmcp v0.0.0-20180102160824-81144009af58
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c // indirect
github.com/pkg/errors v0.0.0-20170505043639-c605e284fe17 // indirect
github.com/posener/complete v1.1.1
github.com/posener/complete v1.2.1
github.com/satori/go.uuid v0.0.0-20160927100844-b061729afc07 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/sirupsen/logrus v1.1.1 // indirect

2
go.sum
View File

@ -309,6 +309,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
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.1 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6DI=
github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E=
github.com/prometheus/client_golang v0.8.0 h1:1921Yw9Gc3iSc4VQh3PIoOqgPCZS7G/4xQNVUp8Mda8=
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=

View File

@ -1,2 +1,4 @@
.idea
coverage.txt
gocomplete/gocomplete
example/self/self

View File

@ -1,17 +1,16 @@
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
- gometalinter.v1 --install
script:
- gometalinter.v1 --config metalinter.json ./...
- ./test.sh
- GO111MODULE=on ./test.sh
after_success:
- bash <(curl -s https://codecov.io/bash)

View File

@ -57,11 +57,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
}

View File

@ -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")
}
}

View File

@ -16,7 +16,10 @@ type fish struct {
func (f fish) Install(cmd, bin string) error {
completionFile := filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd))
completeCmd := f.cmd(cmd, bin)
completeCmd, err := f.cmd(cmd, bin)
if err != nil {
return err
}
if _, err := os.Stat(completionFile); err == nil {
return fmt.Errorf("already installed at %s", completionFile)
}
@ -33,10 +36,10 @@ func (f fish) Uninstall(cmd, bin string) error {
return os.Remove(completionFile)
}
func (f fish) cmd(cmd, bin string) string {
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) = ""
@ -44,7 +47,10 @@ function __complete_{{.Cmd}}
{{.Bin}}
end
complete -c {{.Cmd}} -a "(__complete_{{.Cmd}})"
`)).Execute(&buf, params)
return string(buf.Bytes())
`))
err := tmpl.Execute(&buf, params)
if err != nil {
return "", err
}
return buf.String(), nil
}

View File

@ -51,7 +51,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)
}
}

View File

@ -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

View File

@ -10,14 +10,16 @@ import (
"fmt"
"io"
"os"
"strconv"
"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 +57,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)
@ -79,12 +86,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) {

3
vendor/github.com/posener/complete/go.mod generated vendored Normal file
View File

@ -0,0 +1,3 @@
module github.com/posener/complete
require github.com/hashicorp/go-multierror v1.0.0

4
vendor/github.com/posener/complete/go.sum generated vendored Normal file
View File

@ -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=

View File

@ -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
}

View File

@ -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"
}

View File

@ -4,6 +4,7 @@ A tool for bash writing bash completion in go, and bash completion for the go co
[![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)

2
vendor/modules.txt vendored
View File

@ -406,7 +406,7 @@ github.com/oklog/run
github.com/packer-community/winrmcp/winrmcp
# github.com/pkg/errors v0.0.0-20170505043639-c605e284fe17
github.com/pkg/errors
# github.com/posener/complete v1.1.1
# github.com/posener/complete v1.2.1
github.com/posener/complete
github.com/posener/complete/cmd/install
github.com/posener/complete/cmd