mirror of
https://github.com/spf13/cobra
synced 2025-05-06 13:27:26 +00:00
Merge remote-tracking branch 'upstream/master' into required_flags_func
This commit is contained in:
commit
a953d2898e
5 changed files with 53 additions and 37 deletions
|
@ -1,3 +1,49 @@
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
references:
|
||||||
|
workspace: &workspace
|
||||||
|
/go/src/github.com/spf13/cobra
|
||||||
|
|
||||||
|
run_tests: &run_tests
|
||||||
|
run:
|
||||||
|
name: "All Commands"
|
||||||
|
command: |
|
||||||
|
mkdir -p bin
|
||||||
|
curl -Lso bin/shellcheck https://github.com/caarlos0/shellcheck-docker/releases/download/v0.4.6/shellcheck
|
||||||
|
chmod +x bin/shellcheck
|
||||||
|
go get -t -v ./...
|
||||||
|
PATH=$PATH:$PWD/bin go test -v ./...
|
||||||
|
go build
|
||||||
|
if [ -z $NOVET ]; then
|
||||||
|
diff -u <(echo -n) <(go tool vet . 2>&1 | grep -vE 'ExampleCommand|bash_completions.*Fprint');
|
||||||
|
fi
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
go-current:
|
||||||
|
docker:
|
||||||
|
- image: circleci/golang:1.11
|
||||||
|
working_directory: *workspace
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- *run_tests
|
||||||
|
- run:
|
||||||
|
name: "Check formatting"
|
||||||
|
command: diff -u <(echo -n) <(gofmt -d -s .)
|
||||||
|
go-previous:
|
||||||
|
docker:
|
||||||
|
- image: circleci/golang:1.10
|
||||||
|
working_directory: *workspace
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- *run_tests
|
||||||
|
go-latest:
|
||||||
|
docker:
|
||||||
|
- image: circleci/golang:latest
|
||||||
|
working_directory: *workspace
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- *run_tests
|
||||||
|
|
||||||
workflows:
|
workflows:
|
||||||
version: 2
|
version: 2
|
||||||
main:
|
main:
|
||||||
|
@ -5,34 +51,3 @@ workflows:
|
||||||
- go-current
|
- go-current
|
||||||
- go-previous
|
- go-previous
|
||||||
- go-latest
|
- go-latest
|
||||||
base: &base
|
|
||||||
working_directory: /go/src/github.com/spf13/cobra
|
|
||||||
steps:
|
|
||||||
- checkout
|
|
||||||
- run:
|
|
||||||
name: "All Commands"
|
|
||||||
command: |
|
|
||||||
mkdir -p bin
|
|
||||||
curl -Lso bin/shellcheck https://github.com/caarlos0/shellcheck-docker/releases/download/v0.4.6/shellcheck
|
|
||||||
chmod +x bin/shellcheck
|
|
||||||
go get -t -v ./...
|
|
||||||
PATH=$PATH:$PWD/bin go test -v ./...
|
|
||||||
go build
|
|
||||||
diff -u <(echo -n) <(gofmt -d -s .)
|
|
||||||
if [ -z $NOVET ]; then
|
|
||||||
diff -u <(echo -n) <(go tool vet . 2>&1 | grep -vE 'ExampleCommand|bash_completions.*Fprint');
|
|
||||||
fi
|
|
||||||
version: 2
|
|
||||||
jobs:
|
|
||||||
go-current:
|
|
||||||
docker:
|
|
||||||
- image: circleci/golang:1.10.0
|
|
||||||
<<: *base
|
|
||||||
go-previous:
|
|
||||||
docker:
|
|
||||||
- image: circleci/golang:1.9.4
|
|
||||||
<<: *base
|
|
||||||
go-latest:
|
|
||||||
docker:
|
|
||||||
- image: circleci/golang:latest
|
|
||||||
<<: *base
|
|
||||||
|
|
|
@ -2,9 +2,11 @@ language: go
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- go: 1.9.4
|
- go: 1.10.x
|
||||||
- go: 1.10.0
|
- go: 1.11.x
|
||||||
- go: tip
|
- go: tip
|
||||||
|
- go: 1.11.x
|
||||||
|
script: diff -u <(echo -n) <(gofmt -d -s .)
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- go: tip
|
- go: tip
|
||||||
|
|
||||||
|
@ -15,7 +17,6 @@ before_install:
|
||||||
script:
|
script:
|
||||||
- PATH=$PATH:$PWD/bin go test -v ./...
|
- PATH=$PATH:$PWD/bin go test -v ./...
|
||||||
- go build
|
- go build
|
||||||
- diff -u <(echo -n) <(gofmt -d -s .)
|
|
||||||
- if [ -z $NOVET ]; then
|
- if [ -z $NOVET ]; then
|
||||||
diff -u <(echo -n) <(go tool vet . 2>&1 | grep -vE 'ExampleCommand|bash_completions.*Fprint');
|
diff -u <(echo -n) <(go tool vet . 2>&1 | grep -vE 'ExampleCommand|bash_completions.*Fprint');
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -134,7 +134,7 @@ __%[1]s_handle_reply()
|
||||||
__%[1]s_custom_func
|
__%[1]s_custom_func
|
||||||
else
|
else
|
||||||
# otherwise fall back to unqualified for compatibility
|
# otherwise fall back to unqualified for compatibility
|
||||||
declare -F ___custom_func >/dev/null && __custom_func
|
declare -F __custom_func >/dev/null && __custom_func
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ Find more information at https://github.com/GoogleCloudPlatform/kubernetes.`,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `BashCompletionFunction` option is really only valid/useful on the root command. Doing the above will cause `___kubectl_custom_func()` (`__<command-use>_custom_func()`) to be called when the built in processor was unable to find a solution. In the case of kubernetes a valid command might look something like `kubectl get pod [mypod]`. If you type `kubectl get pod [tab][tab]` the `__kubectl_customc_func()` will run because the cobra.Command only understood "kubectl" and "get." `__kubectl_custom_func()` will see that the cobra.Command is "kubectl_get" and will thus call another helper `__kubectl_get_resource()`. `__kubectl_get_resource` will look at the 'nouns' collected. In our example the only noun will be `pod`. So it will call `__kubectl_parse_get pod`. `__kubectl_parse_get` will actually call out to kubernetes and get any pods. It will then set `COMPREPLY` to valid pods!
|
The `BashCompletionFunction` option is really only valid/useful on the root command. Doing the above will cause `__kubectl_custom_func()` (`__<command-use>_custom_func()`) to be called when the built in processor was unable to find a solution. In the case of kubernetes a valid command might look something like `kubectl get pod [mypod]`. If you type `kubectl get pod [tab][tab]` the `__kubectl_customc_func()` will run because the cobra.Command only understood "kubectl" and "get." `__kubectl_custom_func()` will see that the cobra.Command is "kubectl_get" and will thus call another helper `__kubectl_get_resource()`. `__kubectl_get_resource` will look at the 'nouns' collected. In our example the only noun will be `pod`. So it will call `__kubectl_parse_get pod`. `__kubectl_parse_get` will actually call out to kubernetes and get any pods. It will then set `COMPREPLY` to valid pods!
|
||||||
|
|
||||||
## Have the completions code complete your 'nouns'
|
## Have the completions code complete your 'nouns'
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ func TestBashCompletions(t *testing.T) {
|
||||||
ArgAliases: []string{"pods", "nodes", "services", "replicationcontrollers", "po", "no", "svc", "rc"},
|
ArgAliases: []string{"pods", "nodes", "services", "replicationcontrollers", "po", "no", "svc", "rc"},
|
||||||
ValidArgs: []string{"pod", "node", "service", "replicationcontroller"},
|
ValidArgs: []string{"pod", "node", "service", "replicationcontroller"},
|
||||||
BashCompletionFunction: bashCompletionFunc,
|
BashCompletionFunction: bashCompletionFunc,
|
||||||
Run: emptyRun,
|
Run: emptyRun,
|
||||||
}
|
}
|
||||||
rootCmd.Flags().IntP("introot", "i", -1, "help message for flag introot")
|
rootCmd.Flags().IntP("introot", "i", -1, "help message for flag introot")
|
||||||
rootCmd.MarkFlagRequired("introot")
|
rootCmd.MarkFlagRequired("introot")
|
||||||
|
|
Loading…
Add table
Reference in a new issue