mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 08:23:47 +01:00
vendor: update github.com/spf13/cobra to master
This commit is contained in:
parent
73f0a67d98
commit
5991315990
2
go.mod
2
go.mod
@ -38,7 +38,7 @@ require (
|
||||
github.com/skratchdot/open-golang v0.0.0-20190104022628-a2dfa6d0dab6
|
||||
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
|
||||
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect
|
||||
github.com/spf13/cobra v0.0.3
|
||||
github.com/spf13/cobra v0.0.4-0.20190109003409-7547e83b2d85
|
||||
github.com/spf13/pflag v1.0.3
|
||||
github.com/stretchr/testify v1.3.0
|
||||
github.com/t3rm1n4l/go-mega v0.0.0-20190205172012-55a226cf41da
|
||||
|
2
go.sum
2
go.sum
@ -164,6 +164,8 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh
|
||||
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
|
||||
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/cobra v0.0.4-0.20190109003409-7547e83b2d85 h1:RghwryY75x76zKqO9v7NF+9lcmfW1/RNZBfqK4LSCKE=
|
||||
github.com/spf13/cobra v0.0.4-0.20190109003409-7547e83b2d85/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
7
vendor/github.com/spf13/cobra/.travis.yml
generated
vendored
7
vendor/github.com/spf13/cobra/.travis.yml
generated
vendored
@ -2,9 +2,11 @@ language: go
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- go: 1.9.4
|
||||
- go: 1.10.0
|
||||
- go: 1.10.x
|
||||
- go: 1.11.x
|
||||
- go: tip
|
||||
- go: 1.11.x
|
||||
script: diff -u <(echo -n) <(gofmt -d -s .)
|
||||
allow_failures:
|
||||
- go: tip
|
||||
|
||||
@ -15,7 +17,6 @@ before_install:
|
||||
script:
|
||||
- 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
|
||||
|
9
vendor/github.com/spf13/cobra/README.md
generated
vendored
9
vendor/github.com/spf13/cobra/README.md
generated
vendored
@ -16,7 +16,7 @@ Many of the most widely used Go projects are built using Cobra including:
|
||||
* [CockroachDB](http://www.cockroachlabs.com/)
|
||||
* [Bleve](http://www.blevesearch.com/)
|
||||
* [ProjectAtomic (enterprise)](http://www.projectatomic.io/)
|
||||
* [GiantSwarm's swarm](https://github.com/giantswarm/cli)
|
||||
* [Giant Swarm's gsctl](https://github.com/giantswarm/gsctl)
|
||||
* [Nanobox](https://github.com/nanobox-io/nanobox)/[Nanopack](https://github.com/nanopack)
|
||||
* [rclone](http://rclone.org/)
|
||||
* [nehm](https://github.com/bogem/nehm)
|
||||
@ -152,9 +152,6 @@ In a Cobra app, typically the main.go file is very bare. It serves one purpose:
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"{pathToYourApp}/cmd"
|
||||
)
|
||||
|
||||
@ -265,9 +262,6 @@ In a Cobra app, typically the main.go file is very bare. It serves, one purpose,
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"{pathToYourApp}/cmd"
|
||||
)
|
||||
|
||||
@ -395,6 +389,7 @@ The following validators are built in:
|
||||
- `MinimumNArgs(int)` - the command will report an error if there are not at least N positional args.
|
||||
- `MaximumNArgs(int)` - the command will report an error if there are more than N positional args.
|
||||
- `ExactArgs(int)` - the command will report an error if there are not exactly N positional args.
|
||||
- `ExactValidArgs(int)` = the command will report and error if there are not exactly N positional args OR if there are any positional args that are not in the `ValidArgs` field of `Command`
|
||||
- `RangeArgs(min, max)` - the command will report an error if the number of args is not between the minimum and maximum number of expected args.
|
||||
|
||||
An example of setting the custom validator:
|
||||
|
12
vendor/github.com/spf13/cobra/args.go
generated
vendored
12
vendor/github.com/spf13/cobra/args.go
generated
vendored
@ -78,6 +78,18 @@ func ExactArgs(n int) PositionalArgs {
|
||||
}
|
||||
}
|
||||
|
||||
// ExactValidArgs returns an error if
|
||||
// there are not exactly N positional args OR
|
||||
// there are any positional args that are not in the `ValidArgs` field of `Command`
|
||||
func ExactValidArgs(n int) PositionalArgs {
|
||||
return func(cmd *Command, args []string) error {
|
||||
if err := ExactArgs(n)(cmd, args); err != nil {
|
||||
return err
|
||||
}
|
||||
return OnlyValidArgs(cmd, args)
|
||||
}
|
||||
}
|
||||
|
||||
// RangeArgs returns an error if the number of args is not within the expected range.
|
||||
func RangeArgs(min int, max int) PositionalArgs {
|
||||
return func(cmd *Command, args []string) error {
|
||||
|
8
vendor/github.com/spf13/cobra/bash_completions.go
generated
vendored
8
vendor/github.com/spf13/cobra/bash_completions.go
generated
vendored
@ -129,7 +129,13 @@ __%[1]s_handle_reply()
|
||||
fi
|
||||
|
||||
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
|
||||
declare -F __custom_func >/dev/null && __custom_func
|
||||
if declare -F __%[1]s_custom_func >/dev/null; then
|
||||
# try command name qualified custom func
|
||||
__%[1]s_custom_func
|
||||
else
|
||||
# otherwise fall back to unqualified for compatibility
|
||||
declare -F __custom_func >/dev/null && __custom_func
|
||||
fi
|
||||
fi
|
||||
|
||||
# available in bash-completion >= 2, not always present on macOS
|
||||
|
39
vendor/github.com/spf13/cobra/bash_completions.md
generated
vendored
39
vendor/github.com/spf13/cobra/bash_completions.md
generated
vendored
@ -1,5 +1,40 @@
|
||||
# Generating Bash Completions For Your Own cobra.Command
|
||||
|
||||
If you are using the generator you can create a completion command by running
|
||||
|
||||
```bash
|
||||
cobra add completion
|
||||
```
|
||||
|
||||
Update the help text show how to install the bash_completion Linux show here [Kubectl docs show mac options](https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion)
|
||||
|
||||
Writing the shell script to stdout allows the most flexible use.
|
||||
|
||||
```go
|
||||
// completionCmd represents the completion command
|
||||
var completionCmd = &cobra.Command{
|
||||
Use: "completion",
|
||||
Short: "Generates bash completion scripts",
|
||||
Long: `To load completion run
|
||||
|
||||
. <(bitbucket completion)
|
||||
|
||||
To configure your bash shell to load completions for each session add to your bashrc
|
||||
|
||||
# ~/.bashrc or ~/.profile
|
||||
. <(bitbucket completion)
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
rootCmd.GenBashCompletion(os.Stdout);
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
**Note:** The cobra generator may include messages printed to stdout for example if the config file is loaded, this will break the auto complete script
|
||||
|
||||
|
||||
## Example from kubectl
|
||||
|
||||
Generating bash completions from a cobra command is incredibly easy. An actual program which does so for the kubernetes kubectl binary is as follows:
|
||||
|
||||
```go
|
||||
@ -47,7 +82,7 @@ __kubectl_get_resource()
|
||||
fi
|
||||
}
|
||||
|
||||
__custom_func() {
|
||||
__kubectl_custom_func() {
|
||||
case ${last_command} in
|
||||
kubectl_get | kubectl_describe | kubectl_delete | kubectl_stop)
|
||||
__kubectl_get_resource
|
||||
@ -74,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 `__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 `__customc_func()` will run because the cobra.Command only understood "kubectl" and "get." `__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'
|
||||
|
||||
|
17
vendor/github.com/spf13/cobra/doc/man_docs.go
generated
vendored
17
vendor/github.com/spf13/cobra/doc/man_docs.go
generated
vendored
@ -20,6 +20,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -87,7 +88,7 @@ type GenManTreeOptions struct {
|
||||
|
||||
// GenManHeader is a lot like the .TH header at the start of man pages. These
|
||||
// include the title, section, date, source, and manual. We will use the
|
||||
// current time if Date if unset and will use "Auto generated by spf13/cobra"
|
||||
// current time if Date is unset and will use "Auto generated by spf13/cobra"
|
||||
// if the Source is unset.
|
||||
type GenManHeader struct {
|
||||
Title string
|
||||
@ -104,14 +105,16 @@ func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {
|
||||
if header == nil {
|
||||
header = &GenManHeader{}
|
||||
}
|
||||
fillHeader(header, cmd.CommandPath())
|
||||
if err := fillHeader(header, cmd.CommandPath()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b := genMan(cmd, header)
|
||||
_, err := w.Write(md2man.Render(b))
|
||||
return err
|
||||
}
|
||||
|
||||
func fillHeader(header *GenManHeader, name string) {
|
||||
func fillHeader(header *GenManHeader, name string) error {
|
||||
if header.Title == "" {
|
||||
header.Title = strings.ToUpper(strings.Replace(name, " ", "\\-", -1))
|
||||
}
|
||||
@ -120,12 +123,20 @@ func fillHeader(header *GenManHeader, name string) {
|
||||
}
|
||||
if header.Date == nil {
|
||||
now := time.Now()
|
||||
if epoch := os.Getenv("SOURCE_DATE_EPOCH"); epoch != "" {
|
||||
unixEpoch, err := strconv.ParseInt(epoch, 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid SOURCE_DATE_EPOCH: %v", err)
|
||||
}
|
||||
now = time.Unix(unixEpoch, 0)
|
||||
}
|
||||
header.Date = &now
|
||||
}
|
||||
header.date = (*header.Date).Format("Jan 2006")
|
||||
if header.Source == "" {
|
||||
header.Source = "Auto generated by spf13/cobra"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func manPreamble(buf *bytes.Buffer, header *GenManHeader, cmd *cobra.Command, dashedName string) {
|
||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -132,7 +132,7 @@ github.com/russross/blackfriday
|
||||
github.com/sevlyar/go-daemon
|
||||
# github.com/skratchdot/open-golang v0.0.0-20190104022628-a2dfa6d0dab6
|
||||
github.com/skratchdot/open-golang/open
|
||||
# github.com/spf13/cobra v0.0.3
|
||||
# github.com/spf13/cobra v0.0.4-0.20190109003409-7547e83b2d85
|
||||
github.com/spf13/cobra
|
||||
github.com/spf13/cobra/doc
|
||||
# github.com/spf13/pflag v1.0.3
|
||||
|
Loading…
Reference in New Issue
Block a user