Этот коммит содержится в:
Christopher Speller
2017-07-20 15:22:49 -07:00
коммит произвёл GitHub
родитель e2f4492ead
Коммит 58839cefb5
624 изменённых файлов: 103449 добавлений и 14954 удалений

25
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)
}

9
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{}) {

34
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)
}
return len(dirs) == 0
if !fi.IsDir() {
return fi.Size() == 0
}
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 true
}
// exists checks if a file or directory exists.

2
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 {

2
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 {

36
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)

41
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())
}
}

8
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)