summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13')
-rw-r--r--vendor/github.com/spf13/cobra/README.md25
-rw-r--r--vendor/github.com/spf13/cobra/cobra.go9
-rw-r--r--vendor/github.com/spf13/cobra/cobra/cmd/helpers.go32
-rw-r--r--vendor/github.com/spf13/cobra/cobra/cmd/init.go2
-rw-r--r--vendor/github.com/spf13/cobra/cobra/cmd/testdata/root.go.golden2
-rw-r--r--vendor/github.com/spf13/cobra/command.go36
-rw-r--r--vendor/github.com/spf13/cobra/command_test.go39
-rw-r--r--vendor/github.com/spf13/cobra/command_win.go8
8 files changed, 98 insertions, 55 deletions
diff --git a/vendor/github.com/spf13/cobra/README.md b/vendor/github.com/spf13/cobra/README.md
index ff844d2c0..e249c1bcb 100644
--- a/vendor/github.com/spf13/cobra/README.md
+++ b/vendor/github.com/spf13/cobra/README.md
@@ -140,8 +140,8 @@ import "github.com/spf13/cobra"
# Getting Started
-While you are welcome to provide your own organization, typically a Cobra based
-application will follow the following organizational structure.
+While you are welcome to provide your own organization, typically a Cobra-based
+application will follow the following organizational structure:
```
▾ appName/
@@ -153,7 +153,7 @@ application will follow the following organizational structure.
main.go
```
-In a Cobra app, typically the main.go file is very bare. It serves, one purpose, to initialize Cobra.
+In a Cobra app, typically the main.go file is very bare. It serves one purpose: initializing Cobra.
```go
package main
@@ -216,10 +216,11 @@ cobra add create -p 'configCmd'
```
*Note: Use camelCase (not snake_case/snake-case) for command names.
-Otherwise, you will become unexpected errors.
+Otherwise, you will encounter errors.
For example, `cobra add add-user` is incorrect, but `cobra add addUser` is valid.*
-Once you have run these three commands you would have an app structure that would look like:
+Once you have run these three commands you would have an app structure similar to
+the following:
```
▾ app/
@@ -232,14 +233,14 @@ Once you have run these three commands you would have an app structure that woul
At this point you can run `go run main.go` and it would run your app. `go run
main.go serve`, `go run main.go config`, `go run main.go config create` along
-with `go run main.go help serve`, etc would all work.
+with `go run main.go help serve`, etc. would all work.
-Obviously you haven't added your own code to these yet, the commands are ready
+Obviously you haven't added your own code to these yet. The commands are ready
for you to give them their tasks. Have fun!
### Configuring the cobra generator
-The cobra generator will be easier to use if you provide a simple configuration
+The Cobra generator will be easier to use if you provide a simple configuration
file which will help you eliminate providing a bunch of repeated information in
flags over and over.
@@ -269,7 +270,7 @@ You can also use built-in licenses. For example, **GPLv2**, **GPLv3**, **LGPL**,
## Manually implementing Cobra
-To manually implement cobra you need to create a bare main.go file and a RootCmd file.
+To manually implement Cobra you need to create a bare main.go file and a RootCmd file.
You will optionally provide additional commands as you see fit.
### Create the root command
@@ -324,10 +325,10 @@ func init() {
}
func Execute() {
- rootCmd.Execute()
+ RootCmd.Execute()
}
-func main() {
+func initConfig() {
// Don't forget to read config either from cfgFile or from home directory!
if cfgFile != "" {
// Use config file from the flag.
@@ -336,7 +337,7 @@ func main() {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
- fmt.Println(home)
+ fmt.Println(err)
os.Exit(1)
}
diff --git a/vendor/github.com/spf13/cobra/cobra.go b/vendor/github.com/spf13/cobra/cobra.go
index 2726d19e4..8928cefc2 100644
--- a/vendor/github.com/spf13/cobra/cobra.go
+++ b/vendor/github.com/spf13/cobra/cobra.go
@@ -47,6 +47,15 @@ var EnablePrefixMatching = false
// To disable sorting, set it to false.
var EnableCommandSorting = true
+// MousetrapHelpText enables an information splash screen on Windows
+// if the CLI is started from explorer.exe.
+// To disable the mousetrap, just set this variable to blank string ("").
+// Works only on Microsoft Windows.
+var MousetrapHelpText string = `This is a command line tool.
+
+You need to open cmd.exe and run it from there.
+`
+
// AddTemplateFunc adds a template function that's available to Usage and Help
// template generation.
func AddTemplateFunc(name string, tmplFunc interface{}) {
diff --git a/vendor/github.com/spf13/cobra/cobra/cmd/helpers.go b/vendor/github.com/spf13/cobra/cobra/cmd/helpers.go
index 6114227db..c5e261ce3 100644
--- a/vendor/github.com/spf13/cobra/cobra/cmd/helpers.go
+++ b/vendor/github.com/spf13/cobra/cobra/cmd/helpers.go
@@ -45,24 +45,34 @@ func er(msg interface{}) {
}
// isEmpty checks if a given path is empty.
+// Hidden files in path are ignored.
func isEmpty(path string) bool {
fi, err := os.Stat(path)
if err != nil {
er(err)
}
- if fi.IsDir() {
- f, err := os.Open(path)
- if err != nil {
- er(err)
- }
- defer f.Close()
- dirs, err := f.Readdirnames(1)
- if err != nil && err != io.EOF {
- er(err)
+
+ if !fi.IsDir() {
+ return fi.Size() == 0
+ }
+
+ f, err := os.Open(path)
+ if err != nil {
+ er(err)
+ }
+ defer f.Close()
+
+ names, err := f.Readdirnames(-1)
+ if err != nil && err != io.EOF {
+ er(err)
+ }
+
+ for _, name := range names {
+ if len(name) > 0 && name[0] != '.' {
+ return false
}
- return len(dirs) == 0
}
- return fi.Size() == 0
+ return true
}
// exists checks if a file or directory exists.
diff --git a/vendor/github.com/spf13/cobra/cobra/cmd/init.go b/vendor/github.com/spf13/cobra/cobra/cmd/init.go
index 4e7ebdb34..149aabe1f 100644
--- a/vendor/github.com/spf13/cobra/cobra/cmd/init.go
+++ b/vendor/github.com/spf13/cobra/cobra/cmd/init.go
@@ -165,7 +165,7 @@ to quickly create a Cobra application.` + "`" + `,
// Run: func(cmd *cobra.Command, args []string) { },
}
-// Execute adds all child commands to the root command sets flags appropriately.
+// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := RootCmd.Execute(); err != nil {
diff --git a/vendor/github.com/spf13/cobra/cobra/cmd/testdata/root.go.golden b/vendor/github.com/spf13/cobra/cobra/cmd/testdata/root.go.golden
index 0085d5ace..ecc876012 100644
--- a/vendor/github.com/spf13/cobra/cobra/cmd/testdata/root.go.golden
+++ b/vendor/github.com/spf13/cobra/cobra/cmd/testdata/root.go.golden
@@ -39,7 +39,7 @@ to quickly create a Cobra application.`,
// Run: func(cmd *cobra.Command, args []string) { },
}
-// Execute adds all child commands to the root command sets flags appropriately.
+// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := RootCmd.Execute(); err != nil {
diff --git a/vendor/github.com/spf13/cobra/command.go b/vendor/github.com/spf13/cobra/command.go
index 2cd6ee807..c3e16b1d1 100644
--- a/vendor/github.com/spf13/cobra/command.go
+++ b/vendor/github.com/spf13/cobra/command.go
@@ -767,28 +767,28 @@ func (c *Command) InitDefaultHelpFlag() {
// It is called automatically by executing the c or by calling help and usage.
// If c already has help command or c has no subcommands, it will do nothing.
func (c *Command) InitDefaultHelpCmd() {
- if c.helpCommand != nil || !c.HasSubCommands() {
+ if !c.HasSubCommands() {
return
}
- c.helpCommand = &Command{
- Use: "help [command]",
- Short: "Help about any command",
- Long: `Help provides help for any command in the application.
- Simply type ` + c.Name() + ` help [path to command] for full details.`,
- PersistentPreRun: func(cmd *Command, args []string) {},
- PersistentPostRun: func(cmd *Command, args []string) {},
+ if c.helpCommand == nil {
+ c.helpCommand = &Command{
+ Use: "help [command]",
+ Short: "Help about any command",
+ Long: `Help provides help for any command in the application.
+Simply type ` + c.Name() + ` help [path to command] for full details.`,
- Run: func(c *Command, args []string) {
- cmd, _, e := c.Root().Find(args)
- if cmd == nil || e != nil {
- c.Printf("Unknown help topic %#q\n", args)
- c.Root().Usage()
- } else {
- cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown
- cmd.Help()
- }
- },
+ Run: func(c *Command, args []string) {
+ cmd, _, e := c.Root().Find(args)
+ if cmd == nil || e != nil {
+ c.Printf("Unknown help topic %#q\n", args)
+ c.Root().Usage()
+ } else {
+ cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown
+ cmd.Help()
+ }
+ },
+ }
}
c.RemoveCommand(c.helpCommand)
c.AddCommand(c.helpCommand)
diff --git a/vendor/github.com/spf13/cobra/command_test.go b/vendor/github.com/spf13/cobra/command_test.go
index f4fe14646..aa6658f85 100644
--- a/vendor/github.com/spf13/cobra/command_test.go
+++ b/vendor/github.com/spf13/cobra/command_test.go
@@ -120,7 +120,6 @@ func TestStripFlags(t *testing.T) {
}
func TestDisableFlagParsing(t *testing.T) {
- as := []string{"-v", "-race", "-file", "foo.go"}
targs := []string{}
cmdPrint := &Command{
DisableFlagParsing: true,
@@ -128,14 +127,14 @@ func TestDisableFlagParsing(t *testing.T) {
targs = args
},
}
- osargs := []string{"cmd"}
- os.Args = append(osargs, as...)
+ args := []string{"cmd", "-v", "-race", "-file", "foo.go"}
+ cmdPrint.SetArgs(args)
err := cmdPrint.Execute()
if err != nil {
t.Error(err)
}
- if !reflect.DeepEqual(as, targs) {
- t.Errorf("expected: %v, got: %v", as, targs)
+ if !reflect.DeepEqual(args, targs) {
+ t.Errorf("expected: %v, got: %v", args, targs)
}
}
@@ -316,5 +315,35 @@ func TestUseDeprecatedFlags(t *testing.T) {
if !strings.Contains(output.String(), "This flag is deprecated") {
t.Errorf("Expected to contain deprecated message, but got %q", output.String())
}
+}
+
+// TestSetHelpCommand checks, if SetHelpCommand works correctly.
+func TestSetHelpCommand(t *testing.T) {
+ c := &Command{Use: "c", Run: func(*Command, []string) {}}
+ output := new(bytes.Buffer)
+ c.SetOutput(output)
+ c.SetArgs([]string{"help"})
+
+ // Help will not be shown, if c has no subcommands.
+ c.AddCommand(&Command{
+ Use: "empty",
+ Run: func(cmd *Command, args []string) {},
+ })
+ correctMessage := "WORKS"
+ c.SetHelpCommand(&Command{
+ Use: "help [command]",
+ Short: "Help about any command",
+ Long: `Help provides help for any command in the application.
+ Simply type ` + c.Name() + ` help [path to command] for full details.`,
+ Run: func(c *Command, args []string) { c.Print(correctMessage) },
+ })
+
+ if err := c.Execute(); err != nil {
+ t.Error("Unexpected error:", err)
+ }
+
+ if output.String() != correctMessage {
+ t.Errorf("Expected to contain %q message, but got %q", correctMessage, output.String())
+ }
}
diff --git a/vendor/github.com/spf13/cobra/command_win.go b/vendor/github.com/spf13/cobra/command_win.go
index 4b0eaa1b6..edec728e4 100644
--- a/vendor/github.com/spf13/cobra/command_win.go
+++ b/vendor/github.com/spf13/cobra/command_win.go
@@ -11,14 +11,8 @@ import (
var preExecHookFn = preExecHook
-// enables an information splash screen on Windows if the CLI is started from explorer.exe.
-var MousetrapHelpText string = `This is a command line tool
-
-You need to open cmd.exe and run it from there.
-`
-
func preExecHook(c *Command) {
- if mousetrap.StartedByExplorer() {
+ if MousetrapHelpText != "" && mousetrap.StartedByExplorer() {
c.Print(MousetrapHelpText)
time.Sleep(5 * time.Second)
os.Exit(1)