|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/app.go docker-1/vendor/src/github.com/codegangsta/cli/app.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/app.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/app.go 2015-01-16 03:56:49.105152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,248 @@
|
|
|
b215bf |
+package cli
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "fmt"
|
|
|
b215bf |
+ "io/ioutil"
|
|
|
b215bf |
+ "os"
|
|
|
b215bf |
+ "time"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+// App is the main structure of a cli application. It is recomended that
|
|
|
b215bf |
+// and app be created with the cli.NewApp() function
|
|
|
b215bf |
+type App struct {
|
|
|
b215bf |
+ // The name of the program. Defaults to os.Args[0]
|
|
|
b215bf |
+ Name string
|
|
|
b215bf |
+ // Description of the program.
|
|
|
b215bf |
+ Usage string
|
|
|
b215bf |
+ // Version of the program
|
|
|
b215bf |
+ Version string
|
|
|
b215bf |
+ // List of commands to execute
|
|
|
b215bf |
+ Commands []Command
|
|
|
b215bf |
+ // List of flags to parse
|
|
|
b215bf |
+ Flags []Flag
|
|
|
b215bf |
+ // Boolean to enable bash completion commands
|
|
|
b215bf |
+ EnableBashCompletion bool
|
|
|
b215bf |
+ // Boolean to hide built-in help command
|
|
|
b215bf |
+ HideHelp bool
|
|
|
b215bf |
+ // An action to execute when the bash-completion flag is set
|
|
|
b215bf |
+ BashComplete func(context *Context)
|
|
|
b215bf |
+ // An action to execute before any subcommands are run, but after the context is ready
|
|
|
b215bf |
+ // If a non-nil error is returned, no subcommands are run
|
|
|
b215bf |
+ Before func(context *Context) error
|
|
|
b215bf |
+ // The action to execute when no subcommands are specified
|
|
|
b215bf |
+ Action func(context *Context)
|
|
|
b215bf |
+ // Execute this function if the proper command cannot be found
|
|
|
b215bf |
+ CommandNotFound func(context *Context, command string)
|
|
|
b215bf |
+ // Compilation date
|
|
|
b215bf |
+ Compiled time.Time
|
|
|
b215bf |
+ // Author
|
|
|
b215bf |
+ Author string
|
|
|
b215bf |
+ // Author e-mail
|
|
|
b215bf |
+ Email string
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Tries to find out when this binary was compiled.
|
|
|
b215bf |
+// Returns the current time if it fails to find it.
|
|
|
b215bf |
+func compileTime() time.Time {
|
|
|
b215bf |
+ info, err := os.Stat(os.Args[0])
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ return time.Now()
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return info.ModTime()
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Creates a new cli Application with some reasonable defaults for Name, Usage, Version and Action.
|
|
|
b215bf |
+func NewApp() *App {
|
|
|
b215bf |
+ return &App{
|
|
|
b215bf |
+ Name: os.Args[0],
|
|
|
b215bf |
+ Usage: "A new cli application",
|
|
|
b215bf |
+ Version: "0.0.0",
|
|
|
b215bf |
+ BashComplete: DefaultAppComplete,
|
|
|
b215bf |
+ Action: helpCommand.Action,
|
|
|
b215bf |
+ Compiled: compileTime(),
|
|
|
b215bf |
+ Author: "Author",
|
|
|
b215bf |
+ Email: "unknown@email",
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Entry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination
|
|
|
b215bf |
+func (a *App) Run(arguments []string) error {
|
|
|
b215bf |
+ // append help to commands
|
|
|
b215bf |
+ if a.Command(helpCommand.Name) == nil && !a.HideHelp {
|
|
|
b215bf |
+ a.Commands = append(a.Commands, helpCommand)
|
|
|
b215bf |
+ a.appendFlag(HelpFlag)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ //append version/help flags
|
|
|
b215bf |
+ if a.EnableBashCompletion {
|
|
|
b215bf |
+ a.appendFlag(BashCompletionFlag)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ a.appendFlag(VersionFlag)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // parse flags
|
|
|
b215bf |
+ set := flagSet(a.Name, a.Flags)
|
|
|
b215bf |
+ set.SetOutput(ioutil.Discard)
|
|
|
b215bf |
+ err := set.Parse(arguments[1:])
|
|
|
b215bf |
+ nerr := normalizeFlags(a.Flags, set)
|
|
|
b215bf |
+ if nerr != nil {
|
|
|
b215bf |
+ fmt.Println(nerr)
|
|
|
b215bf |
+ context := NewContext(a, set, set)
|
|
|
b215bf |
+ ShowAppHelp(context)
|
|
|
b215bf |
+ fmt.Println("")
|
|
|
b215bf |
+ return nerr
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ context := NewContext(a, set, set)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ fmt.Printf("Incorrect Usage.\n\n")
|
|
|
b215bf |
+ ShowAppHelp(context)
|
|
|
b215bf |
+ fmt.Println("")
|
|
|
b215bf |
+ return err
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if checkCompletions(context) {
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if checkHelp(context) {
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if checkVersion(context) {
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if a.Before != nil {
|
|
|
b215bf |
+ err := a.Before(context)
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ return err
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ args := context.Args()
|
|
|
b215bf |
+ if args.Present() {
|
|
|
b215bf |
+ name := args.First()
|
|
|
b215bf |
+ c := a.Command(name)
|
|
|
b215bf |
+ if c != nil {
|
|
|
b215bf |
+ return c.Run(context)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // Run default Action
|
|
|
b215bf |
+ a.Action(context)
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Another entry point to the cli app, takes care of passing arguments and error handling
|
|
|
b215bf |
+func (a *App) RunAndExitOnError() {
|
|
|
b215bf |
+ if err := a.Run(os.Args); err != nil {
|
|
|
b215bf |
+ os.Stderr.WriteString(fmt.Sprintln(err))
|
|
|
b215bf |
+ os.Exit(1)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Invokes the subcommand given the context, parses ctx.Args() to generate command-specific flags
|
|
|
b215bf |
+func (a *App) RunAsSubcommand(ctx *Context) error {
|
|
|
b215bf |
+ // append help to commands
|
|
|
b215bf |
+ if len(a.Commands) > 0 {
|
|
|
b215bf |
+ if a.Command(helpCommand.Name) == nil && !a.HideHelp {
|
|
|
b215bf |
+ a.Commands = append(a.Commands, helpCommand)
|
|
|
b215bf |
+ a.appendFlag(HelpFlag)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // append flags
|
|
|
b215bf |
+ if a.EnableBashCompletion {
|
|
|
b215bf |
+ a.appendFlag(BashCompletionFlag)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // parse flags
|
|
|
b215bf |
+ set := flagSet(a.Name, a.Flags)
|
|
|
b215bf |
+ set.SetOutput(ioutil.Discard)
|
|
|
b215bf |
+ err := set.Parse(ctx.Args().Tail())
|
|
|
b215bf |
+ nerr := normalizeFlags(a.Flags, set)
|
|
|
b215bf |
+ context := NewContext(a, set, ctx.globalSet)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if nerr != nil {
|
|
|
b215bf |
+ fmt.Println(nerr)
|
|
|
b215bf |
+ if len(a.Commands) > 0 {
|
|
|
b215bf |
+ ShowSubcommandHelp(context)
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ ShowCommandHelp(ctx, context.Args().First())
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ fmt.Println("")
|
|
|
b215bf |
+ return nerr
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ fmt.Printf("Incorrect Usage.\n\n")
|
|
|
b215bf |
+ ShowSubcommandHelp(context)
|
|
|
b215bf |
+ return err
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if checkCompletions(context) {
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if len(a.Commands) > 0 {
|
|
|
b215bf |
+ if checkSubcommandHelp(context) {
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ if checkCommandHelp(ctx, context.Args().First()) {
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if a.Before != nil {
|
|
|
b215bf |
+ err := a.Before(context)
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ return err
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ args := context.Args()
|
|
|
b215bf |
+ if args.Present() {
|
|
|
b215bf |
+ name := args.First()
|
|
|
b215bf |
+ c := a.Command(name)
|
|
|
b215bf |
+ if c != nil {
|
|
|
b215bf |
+ return c.Run(context)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // Run default Action
|
|
|
b215bf |
+ if len(a.Commands) > 0 {
|
|
|
b215bf |
+ a.Action(context)
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ a.Action(ctx)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Returns the named command on App. Returns nil if the command does not exist
|
|
|
b215bf |
+func (a *App) Command(name string) *Command {
|
|
|
b215bf |
+ for _, c := range a.Commands {
|
|
|
b215bf |
+ if c.HasName(name) {
|
|
|
b215bf |
+ return &c
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (a *App) hasFlag(flag Flag) bool {
|
|
|
b215bf |
+ for _, f := range a.Flags {
|
|
|
b215bf |
+ if flag == f {
|
|
|
b215bf |
+ return true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (a *App) appendFlag(flag Flag) {
|
|
|
b215bf |
+ if !a.hasFlag(flag) {
|
|
|
b215bf |
+ a.Flags = append(a.Flags, flag)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/app_test.go docker-1/vendor/src/github.com/codegangsta/cli/app_test.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/app_test.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/app_test.go 2015-01-16 03:56:49.104152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,399 @@
|
|
|
b215bf |
+package cli_test
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "fmt"
|
|
|
b215bf |
+ "os"
|
|
|
b215bf |
+ "testing"
|
|
|
b215bf |
+
|
|
|
b215bf |
+ "github.com/codegangsta/cli"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+func ExampleApp() {
|
|
|
b215bf |
+ // set args for examples sake
|
|
|
b215bf |
+ os.Args = []string{"greet", "--name", "Jeremy"}
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ app.Name = "greet"
|
|
|
b215bf |
+ app.Flags = []cli.Flag{
|
|
|
b215bf |
+ cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ app.Action = func(c *cli.Context) {
|
|
|
b215bf |
+ fmt.Printf("Hello %v\n", c.String("name"))
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ app.Run(os.Args)
|
|
|
b215bf |
+ // Output:
|
|
|
b215bf |
+ // Hello Jeremy
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func ExampleAppSubcommand() {
|
|
|
b215bf |
+ // set args for examples sake
|
|
|
b215bf |
+ os.Args = []string{"say", "hi", "english", "--name", "Jeremy"}
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ app.Name = "say"
|
|
|
b215bf |
+ app.Commands = []cli.Command{
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "hello",
|
|
|
b215bf |
+ ShortName: "hi",
|
|
|
b215bf |
+ Usage: "use it to see a description",
|
|
|
b215bf |
+ Description: "This is how we describe hello the function",
|
|
|
b215bf |
+ Subcommands: []cli.Command{
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "english",
|
|
|
b215bf |
+ ShortName: "en",
|
|
|
b215bf |
+ Usage: "sends a greeting in english",
|
|
|
b215bf |
+ Description: "greets someone in english",
|
|
|
b215bf |
+ Flags: []cli.Flag{
|
|
|
b215bf |
+ cli.StringFlag{Name: "name", Value: "Bob", Usage: "Name of the person to greet"},
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ fmt.Println("Hello,", c.String("name"))
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Run(os.Args)
|
|
|
b215bf |
+ // Output:
|
|
|
b215bf |
+ // Hello, Jeremy
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func ExampleAppHelp() {
|
|
|
b215bf |
+ // set args for examples sake
|
|
|
b215bf |
+ os.Args = []string{"greet", "h", "describeit"}
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ app.Name = "greet"
|
|
|
b215bf |
+ app.Flags = []cli.Flag{
|
|
|
b215bf |
+ cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ app.Commands = []cli.Command{
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "describeit",
|
|
|
b215bf |
+ ShortName: "d",
|
|
|
b215bf |
+ Usage: "use it to see a description",
|
|
|
b215bf |
+ Description: "This is how we describe describeit the function",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ fmt.Printf("i like to describe things")
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ app.Run(os.Args)
|
|
|
b215bf |
+ // Output:
|
|
|
b215bf |
+ // NAME:
|
|
|
b215bf |
+ // describeit - use it to see a description
|
|
|
b215bf |
+ //
|
|
|
b215bf |
+ // USAGE:
|
|
|
b215bf |
+ // command describeit [arguments...]
|
|
|
b215bf |
+ //
|
|
|
b215bf |
+ // DESCRIPTION:
|
|
|
b215bf |
+ // This is how we describe describeit the function
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func ExampleAppBashComplete() {
|
|
|
b215bf |
+ // set args for examples sake
|
|
|
b215bf |
+ os.Args = []string{"greet", "--generate-bash-completion"}
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ app.Name = "greet"
|
|
|
b215bf |
+ app.EnableBashCompletion = true
|
|
|
b215bf |
+ app.Commands = []cli.Command{
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "describeit",
|
|
|
b215bf |
+ ShortName: "d",
|
|
|
b215bf |
+ Usage: "use it to see a description",
|
|
|
b215bf |
+ Description: "This is how we describe describeit the function",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ fmt.Printf("i like to describe things")
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }, {
|
|
|
b215bf |
+ Name: "next",
|
|
|
b215bf |
+ Usage: "next example",
|
|
|
b215bf |
+ Description: "more stuff to see when generating bash completion",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ fmt.Printf("the next example")
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Run(os.Args)
|
|
|
b215bf |
+ // Output:
|
|
|
b215bf |
+ // describeit
|
|
|
b215bf |
+ // d
|
|
|
b215bf |
+ // next
|
|
|
b215bf |
+ // help
|
|
|
b215bf |
+ // h
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestApp_Run(t *testing.T) {
|
|
|
b215bf |
+ s := ""
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ app.Action = func(c *cli.Context) {
|
|
|
b215bf |
+ s = s + c.Args().First()
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ err := app.Run([]string{"command", "foo"})
|
|
|
b215bf |
+ expect(t, err, nil)
|
|
|
b215bf |
+ err = app.Run([]string{"command", "bar"})
|
|
|
b215bf |
+ expect(t, err, nil)
|
|
|
b215bf |
+ expect(t, s, "foobar")
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+var commandAppTests = []struct {
|
|
|
b215bf |
+ name string
|
|
|
b215bf |
+ expected bool
|
|
|
b215bf |
+}{
|
|
|
b215bf |
+ {"foobar", true},
|
|
|
b215bf |
+ {"batbaz", true},
|
|
|
b215bf |
+ {"b", true},
|
|
|
b215bf |
+ {"f", true},
|
|
|
b215bf |
+ {"bat", false},
|
|
|
b215bf |
+ {"nothing", false},
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestApp_Command(t *testing.T) {
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ fooCommand := cli.Command{Name: "foobar", ShortName: "f"}
|
|
|
b215bf |
+ batCommand := cli.Command{Name: "batbaz", ShortName: "b"}
|
|
|
b215bf |
+ app.Commands = []cli.Command{
|
|
|
b215bf |
+ fooCommand,
|
|
|
b215bf |
+ batCommand,
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ for _, test := range commandAppTests {
|
|
|
b215bf |
+ expect(t, app.Command(test.name) != nil, test.expected)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestApp_CommandWithArgBeforeFlags(t *testing.T) {
|
|
|
b215bf |
+ var parsedOption, firstArg string
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ command := cli.Command{
|
|
|
b215bf |
+ Name: "cmd",
|
|
|
b215bf |
+ Flags: []cli.Flag{
|
|
|
b215bf |
+ cli.StringFlag{Name: "option", Value: "", Usage: "some option"},
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ parsedOption = c.String("option")
|
|
|
b215bf |
+ firstArg = c.Args().First()
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ app.Commands = []cli.Command{command}
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Run([]string{"", "cmd", "my-arg", "--option", "my-option"})
|
|
|
b215bf |
+
|
|
|
b215bf |
+ expect(t, parsedOption, "my-option")
|
|
|
b215bf |
+ expect(t, firstArg, "my-arg")
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestApp_Float64Flag(t *testing.T) {
|
|
|
b215bf |
+ var meters float64
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ app.Flags = []cli.Flag{
|
|
|
b215bf |
+ cli.Float64Flag{Name: "height", Value: 1.5, Usage: "Set the height, in meters"},
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ app.Action = func(c *cli.Context) {
|
|
|
b215bf |
+ meters = c.Float64("height")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Run([]string{"", "--height", "1.93"})
|
|
|
b215bf |
+ expect(t, meters, 1.93)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestApp_ParseSliceFlags(t *testing.T) {
|
|
|
b215bf |
+ var parsedOption, firstArg string
|
|
|
b215bf |
+ var parsedIntSlice []int
|
|
|
b215bf |
+ var parsedStringSlice []string
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ command := cli.Command{
|
|
|
b215bf |
+ Name: "cmd",
|
|
|
b215bf |
+ Flags: []cli.Flag{
|
|
|
b215bf |
+ cli.IntSliceFlag{Name: "p", Value: &cli.IntSlice{}, Usage: "set one or more ip addr"},
|
|
|
b215bf |
+ cli.StringSliceFlag{Name: "ip", Value: &cli.StringSlice{}, Usage: "set one or more ports to open"},
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ parsedIntSlice = c.IntSlice("p")
|
|
|
b215bf |
+ parsedStringSlice = c.StringSlice("ip")
|
|
|
b215bf |
+ parsedOption = c.String("option")
|
|
|
b215bf |
+ firstArg = c.Args().First()
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ app.Commands = []cli.Command{command}
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Run([]string{"", "cmd", "my-arg", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"})
|
|
|
b215bf |
+
|
|
|
b215bf |
+ IntsEquals := func(a, b []int) bool {
|
|
|
b215bf |
+ if len(a) != len(b) {
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ for i, v := range a {
|
|
|
b215bf |
+ if v != b[i] {
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ StrsEquals := func(a, b []string) bool {
|
|
|
b215bf |
+ if len(a) != len(b) {
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ for i, v := range a {
|
|
|
b215bf |
+ if v != b[i] {
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ var expectedIntSlice = []int{22, 80}
|
|
|
b215bf |
+ var expectedStringSlice = []string{"8.8.8.8", "8.8.4.4"}
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if !IntsEquals(parsedIntSlice, expectedIntSlice) {
|
|
|
b215bf |
+ t.Errorf("%v does not match %v", parsedIntSlice, expectedIntSlice)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if !StrsEquals(parsedStringSlice, expectedStringSlice) {
|
|
|
b215bf |
+ t.Errorf("%v does not match %v", parsedStringSlice, expectedStringSlice)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestApp_BeforeFunc(t *testing.T) {
|
|
|
b215bf |
+ beforeRun, subcommandRun := false, false
|
|
|
b215bf |
+ beforeError := fmt.Errorf("fail")
|
|
|
b215bf |
+ var err error
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Before = func(c *cli.Context) error {
|
|
|
b215bf |
+ beforeRun = true
|
|
|
b215bf |
+ s := c.String("opt")
|
|
|
b215bf |
+ if s == "fail" {
|
|
|
b215bf |
+ return beforeError
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Commands = []cli.Command{
|
|
|
b215bf |
+ cli.Command{
|
|
|
b215bf |
+ Name: "sub",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ subcommandRun = true
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Flags = []cli.Flag{
|
|
|
b215bf |
+ cli.StringFlag{Name: "opt"},
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // run with the Before() func succeeding
|
|
|
b215bf |
+ err = app.Run([]string{"command", "--opt", "succeed", "sub"})
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ t.Fatalf("Run error: %s", err)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if beforeRun == false {
|
|
|
b215bf |
+ t.Errorf("Before() not executed when expected")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if subcommandRun == false {
|
|
|
b215bf |
+ t.Errorf("Subcommand not executed when expected")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // reset
|
|
|
b215bf |
+ beforeRun, subcommandRun = false, false
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // run with the Before() func failing
|
|
|
b215bf |
+ err = app.Run([]string{"command", "--opt", "fail", "sub"})
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // should be the same error produced by the Before func
|
|
|
b215bf |
+ if err != beforeError {
|
|
|
b215bf |
+ t.Errorf("Run error expected, but not received")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if beforeRun == false {
|
|
|
b215bf |
+ t.Errorf("Before() not executed when expected")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if subcommandRun == true {
|
|
|
b215bf |
+ t.Errorf("Subcommand executed when NOT expected")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestAppHelpPrinter(t *testing.T) {
|
|
|
b215bf |
+ oldPrinter := cli.HelpPrinter
|
|
|
b215bf |
+ defer func() {
|
|
|
b215bf |
+ cli.HelpPrinter = oldPrinter
|
|
|
b215bf |
+ }()
|
|
|
b215bf |
+
|
|
|
b215bf |
+ var wasCalled = false
|
|
|
b215bf |
+ cli.HelpPrinter = func(template string, data interface{}) {
|
|
|
b215bf |
+ wasCalled = true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ app.Run([]string{"-h"})
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if wasCalled == false {
|
|
|
b215bf |
+ t.Errorf("Help printer expected to be called, but was not")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestAppCommandNotFound(t *testing.T) {
|
|
|
b215bf |
+ beforeRun, subcommandRun := false, false
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.CommandNotFound = func(c *cli.Context, command string) {
|
|
|
b215bf |
+ beforeRun = true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Commands = []cli.Command{
|
|
|
b215bf |
+ cli.Command{
|
|
|
b215bf |
+ Name: "bar",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ subcommandRun = true
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Run([]string{"command", "foo"})
|
|
|
b215bf |
+
|
|
|
b215bf |
+ expect(t, beforeRun, true)
|
|
|
b215bf |
+ expect(t, subcommandRun, false)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestGlobalFlagsInSubcommands(t *testing.T) {
|
|
|
b215bf |
+ subcommandRun := false
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Flags = []cli.Flag{
|
|
|
b215bf |
+ cli.BoolFlag{Name: "debug, d", Usage: "Enable debugging"},
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Commands = []cli.Command{
|
|
|
b215bf |
+ cli.Command{
|
|
|
b215bf |
+ Name: "foo",
|
|
|
b215bf |
+ Subcommands: []cli.Command{
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "bar",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ if c.GlobalBool("debug") {
|
|
|
b215bf |
+ subcommandRun = true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Run([]string{"command", "-d", "foo", "bar"})
|
|
|
b215bf |
+
|
|
|
b215bf |
+ expect(t, subcommandRun, true)
|
|
|
b215bf |
+}
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/autocomplete/bash_autocomplete docker-1/vendor/src/github.com/codegangsta/cli/autocomplete/bash_autocomplete
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/autocomplete/bash_autocomplete 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/autocomplete/bash_autocomplete 2015-01-16 03:56:49.103152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,13 @@
|
|
|
b215bf |
+#! /bin/bash
|
|
|
b215bf |
+
|
|
|
b215bf |
+_cli_bash_autocomplete() {
|
|
|
b215bf |
+ local cur prev opts base
|
|
|
b215bf |
+ COMPREPLY=()
|
|
|
b215bf |
+ cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
b215bf |
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
b215bf |
+ opts=$( ${COMP_WORDS[@]:0:COMP_CWORD} --generate-bash-completion )
|
|
|
b215bf |
+ COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
|
|
b215bf |
+ return 0
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ complete -F _cli_bash_autocomplete $PROG
|
|
|
b215bf |
\ No newline at end of file
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/cli.go docker-1/vendor/src/github.com/codegangsta/cli/cli.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/cli.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/cli.go 2015-01-16 03:56:49.104152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,19 @@
|
|
|
b215bf |
+// Package cli provides a minimal framework for creating and organizing command line
|
|
|
b215bf |
+// Go applications. cli is designed to be easy to understand and write, the most simple
|
|
|
b215bf |
+// cli application can be written as follows:
|
|
|
b215bf |
+// func main() {
|
|
|
b215bf |
+// cli.NewApp().Run(os.Args)
|
|
|
b215bf |
+// }
|
|
|
b215bf |
+//
|
|
|
b215bf |
+// Of course this application does not do much, so let's make this an actual application:
|
|
|
b215bf |
+// func main() {
|
|
|
b215bf |
+// app := cli.NewApp()
|
|
|
b215bf |
+// app.Name = "greet"
|
|
|
b215bf |
+// app.Usage = "say a greeting"
|
|
|
b215bf |
+// app.Action = func(c *cli.Context) {
|
|
|
b215bf |
+// println("Greetings")
|
|
|
b215bf |
+// }
|
|
|
b215bf |
+//
|
|
|
b215bf |
+// app.Run(os.Args)
|
|
|
b215bf |
+// }
|
|
|
b215bf |
+package cli
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/cli_test.go docker-1/vendor/src/github.com/codegangsta/cli/cli_test.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/cli_test.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/cli_test.go 2015-01-16 03:56:49.105152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,88 @@
|
|
|
b215bf |
+package cli_test
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "os"
|
|
|
b215bf |
+
|
|
|
b215bf |
+ "github.com/codegangsta/cli"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+func Example() {
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ app.Name = "todo"
|
|
|
b215bf |
+ app.Usage = "task list on the command line"
|
|
|
b215bf |
+ app.Commands = []cli.Command{
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "add",
|
|
|
b215bf |
+ ShortName: "a",
|
|
|
b215bf |
+ Usage: "add a task to the list",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ println("added task: ", c.Args().First())
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "complete",
|
|
|
b215bf |
+ ShortName: "c",
|
|
|
b215bf |
+ Usage: "complete a task on the list",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ println("completed task: ", c.Args().First())
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Run(os.Args)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func ExampleSubcommand() {
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ app.Name = "say"
|
|
|
b215bf |
+ app.Commands = []cli.Command{
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "hello",
|
|
|
b215bf |
+ ShortName: "hi",
|
|
|
b215bf |
+ Usage: "use it to see a description",
|
|
|
b215bf |
+ Description: "This is how we describe hello the function",
|
|
|
b215bf |
+ Subcommands: []cli.Command{
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "english",
|
|
|
b215bf |
+ ShortName: "en",
|
|
|
b215bf |
+ Usage: "sends a greeting in english",
|
|
|
b215bf |
+ Description: "greets someone in english",
|
|
|
b215bf |
+ Flags: []cli.Flag{
|
|
|
b215bf |
+ cli.StringFlag{Name: "name", Value: "Bob", Usage: "Name of the person to greet"},
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ println("Hello, ", c.String("name"))
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }, {
|
|
|
b215bf |
+ Name: "spanish",
|
|
|
b215bf |
+ ShortName: "sp",
|
|
|
b215bf |
+ Usage: "sends a greeting in spanish",
|
|
|
b215bf |
+ Flags: []cli.Flag{
|
|
|
b215bf |
+ cli.StringFlag{Name: "surname", Value: "Jones", Usage: "Surname of the person to greet"},
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ println("Hola, ", c.String("surname"))
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }, {
|
|
|
b215bf |
+ Name: "french",
|
|
|
b215bf |
+ ShortName: "fr",
|
|
|
b215bf |
+ Usage: "sends a greeting in french",
|
|
|
b215bf |
+ Flags: []cli.Flag{
|
|
|
b215bf |
+ cli.StringFlag{Name: "nickname", Value: "Stevie", Usage: "Nickname of the person to greet"},
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ println("Bonjour, ", c.String("nickname"))
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }, {
|
|
|
b215bf |
+ Name: "bye",
|
|
|
b215bf |
+ Usage: "says goodbye",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ println("bye")
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Run(os.Args)
|
|
|
b215bf |
+}
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/command.go docker-1/vendor/src/github.com/codegangsta/cli/command.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/command.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/command.go 2015-01-16 03:56:49.105152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,141 @@
|
|
|
b215bf |
+package cli
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "fmt"
|
|
|
b215bf |
+ "io/ioutil"
|
|
|
b215bf |
+ "strings"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Command is a subcommand for a cli.App.
|
|
|
b215bf |
+type Command struct {
|
|
|
b215bf |
+ // The name of the command
|
|
|
b215bf |
+ Name string
|
|
|
b215bf |
+ // short name of the command. Typically one character
|
|
|
b215bf |
+ ShortName string
|
|
|
b215bf |
+ // A short description of the usage of this command
|
|
|
b215bf |
+ Usage string
|
|
|
b215bf |
+ // A longer explanation of how the command works
|
|
|
b215bf |
+ Description string
|
|
|
b215bf |
+ // The function to call when checking for bash command completions
|
|
|
b215bf |
+ BashComplete func(context *Context)
|
|
|
b215bf |
+ // An action to execute before any sub-subcommands are run, but after the context is ready
|
|
|
b215bf |
+ // If a non-nil error is returned, no sub-subcommands are run
|
|
|
b215bf |
+ Before func(context *Context) error
|
|
|
b215bf |
+ // The function to call when this command is invoked
|
|
|
b215bf |
+ Action func(context *Context)
|
|
|
b215bf |
+ // List of child commands
|
|
|
b215bf |
+ Subcommands []Command
|
|
|
b215bf |
+ // List of flags to parse
|
|
|
b215bf |
+ Flags []Flag
|
|
|
b215bf |
+ // Treat all flags as normal arguments if true
|
|
|
b215bf |
+ SkipFlagParsing bool
|
|
|
b215bf |
+ // Boolean to hide built-in help command
|
|
|
b215bf |
+ HideHelp bool
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Invokes the command given the context, parses ctx.Args() to generate command-specific flags
|
|
|
b215bf |
+func (c Command) Run(ctx *Context) error {
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if len(c.Subcommands) > 0 || c.Before != nil {
|
|
|
b215bf |
+ return c.startApp(ctx)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if !c.HideHelp {
|
|
|
b215bf |
+ // append help to flags
|
|
|
b215bf |
+ c.Flags = append(
|
|
|
b215bf |
+ c.Flags,
|
|
|
b215bf |
+ HelpFlag,
|
|
|
b215bf |
+ )
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if ctx.App.EnableBashCompletion {
|
|
|
b215bf |
+ c.Flags = append(c.Flags, BashCompletionFlag)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ set := flagSet(c.Name, c.Flags)
|
|
|
b215bf |
+ set.SetOutput(ioutil.Discard)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ firstFlagIndex := -1
|
|
|
b215bf |
+ for index, arg := range ctx.Args() {
|
|
|
b215bf |
+ if strings.HasPrefix(arg, "-") {
|
|
|
b215bf |
+ firstFlagIndex = index
|
|
|
b215bf |
+ break
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ var err error
|
|
|
b215bf |
+ if firstFlagIndex > -1 && !c.SkipFlagParsing {
|
|
|
b215bf |
+ args := ctx.Args()
|
|
|
b215bf |
+ regularArgs := args[1:firstFlagIndex]
|
|
|
b215bf |
+ flagArgs := args[firstFlagIndex:]
|
|
|
b215bf |
+ err = set.Parse(append(flagArgs, regularArgs...))
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ err = set.Parse(ctx.Args().Tail())
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ fmt.Printf("Incorrect Usage.\n\n")
|
|
|
b215bf |
+ ShowCommandHelp(ctx, c.Name)
|
|
|
b215bf |
+ fmt.Println("")
|
|
|
b215bf |
+ return err
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ nerr := normalizeFlags(c.Flags, set)
|
|
|
b215bf |
+ if nerr != nil {
|
|
|
b215bf |
+ fmt.Println(nerr)
|
|
|
b215bf |
+ fmt.Println("")
|
|
|
b215bf |
+ ShowCommandHelp(ctx, c.Name)
|
|
|
b215bf |
+ fmt.Println("")
|
|
|
b215bf |
+ return nerr
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ context := NewContext(ctx.App, set, ctx.globalSet)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if checkCommandCompletions(context, c.Name) {
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if checkCommandHelp(context, c.Name) {
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ context.Command = c
|
|
|
b215bf |
+ c.Action(context)
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Returns true if Command.Name or Command.ShortName matches given name
|
|
|
b215bf |
+func (c Command) HasName(name string) bool {
|
|
|
b215bf |
+ return c.Name == name || c.ShortName == name
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (c Command) startApp(ctx *Context) error {
|
|
|
b215bf |
+ app := NewApp()
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // set the name and usage
|
|
|
b215bf |
+ app.Name = fmt.Sprintf("%s %s", ctx.App.Name, c.Name)
|
|
|
b215bf |
+ if c.Description != "" {
|
|
|
b215bf |
+ app.Usage = c.Description
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ app.Usage = c.Usage
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // set the flags and commands
|
|
|
b215bf |
+ app.Commands = c.Subcommands
|
|
|
b215bf |
+ app.Flags = c.Flags
|
|
|
b215bf |
+ app.HideHelp = c.HideHelp
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // bash completion
|
|
|
b215bf |
+ app.EnableBashCompletion = ctx.App.EnableBashCompletion
|
|
|
b215bf |
+ if c.BashComplete != nil {
|
|
|
b215bf |
+ app.BashComplete = c.BashComplete
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ // set the actions
|
|
|
b215bf |
+ app.Before = c.Before
|
|
|
b215bf |
+ if c.Action != nil {
|
|
|
b215bf |
+ app.Action = c.Action
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ app.Action = helpSubcommand.Action
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return app.RunAsSubcommand(ctx)
|
|
|
b215bf |
+}
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/command_test.go docker-1/vendor/src/github.com/codegangsta/cli/command_test.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/command_test.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/command_test.go 2015-01-16 03:56:49.104152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,48 @@
|
|
|
b215bf |
+package cli_test
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "flag"
|
|
|
b215bf |
+ "github.com/codegangsta/cli"
|
|
|
b215bf |
+ "testing"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestCommandDoNotIgnoreFlags(t *testing.T) {
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ set := flag.NewFlagSet("test", 0)
|
|
|
b215bf |
+ test := []string{"blah", "blah", "-break"}
|
|
|
b215bf |
+ set.Parse(test)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ c := cli.NewContext(app, set, set)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ command := cli.Command {
|
|
|
b215bf |
+ Name: "test-cmd",
|
|
|
b215bf |
+ ShortName: "tc",
|
|
|
b215bf |
+ Usage: "this is for testing",
|
|
|
b215bf |
+ Description: "testing",
|
|
|
b215bf |
+ Action: func(_ *cli.Context) { },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ err := command.Run(c)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ expect(t, err.Error(), "flag provided but not defined: -break")
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestCommandIgnoreFlags(t *testing.T) {
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ set := flag.NewFlagSet("test", 0)
|
|
|
b215bf |
+ test := []string{"blah", "blah"}
|
|
|
b215bf |
+ set.Parse(test)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ c := cli.NewContext(app, set, set)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ command := cli.Command {
|
|
|
b215bf |
+ Name: "test-cmd",
|
|
|
b215bf |
+ ShortName: "tc",
|
|
|
b215bf |
+ Usage: "this is for testing",
|
|
|
b215bf |
+ Description: "testing",
|
|
|
b215bf |
+ Action: func(_ *cli.Context) { },
|
|
|
b215bf |
+ SkipFlagParsing: true,
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ err := command.Run(c)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ expect(t, err, nil)
|
|
|
b215bf |
+}
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/context.go docker-1/vendor/src/github.com/codegangsta/cli/context.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/context.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/context.go 2015-01-16 03:56:49.104152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,280 @@
|
|
|
b215bf |
+package cli
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "errors"
|
|
|
b215bf |
+ "flag"
|
|
|
b215bf |
+ "strconv"
|
|
|
b215bf |
+ "strings"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Context is a type that is passed through to
|
|
|
b215bf |
+// each Handler action in a cli application. Context
|
|
|
b215bf |
+// can be used to retrieve context-specific Args and
|
|
|
b215bf |
+// parsed command-line options.
|
|
|
b215bf |
+type Context struct {
|
|
|
b215bf |
+ App *App
|
|
|
b215bf |
+ Command Command
|
|
|
b215bf |
+ flagSet *flag.FlagSet
|
|
|
b215bf |
+ globalSet *flag.FlagSet
|
|
|
b215bf |
+ setFlags map[string]bool
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Creates a new context. For use in when invoking an App or Command action.
|
|
|
b215bf |
+func NewContext(app *App, set *flag.FlagSet, globalSet *flag.FlagSet) *Context {
|
|
|
b215bf |
+ return &Context{App: app, flagSet: set, globalSet: globalSet}
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a local int flag, returns 0 if no int flag exists
|
|
|
b215bf |
+func (c *Context) Int(name string) int {
|
|
|
b215bf |
+ return lookupInt(name, c.flagSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a local float64 flag, returns 0 if no float64 flag exists
|
|
|
b215bf |
+func (c *Context) Float64(name string) float64 {
|
|
|
b215bf |
+ return lookupFloat64(name, c.flagSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a local bool flag, returns false if no bool flag exists
|
|
|
b215bf |
+func (c *Context) Bool(name string) bool {
|
|
|
b215bf |
+ return lookupBool(name, c.flagSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a local boolT flag, returns false if no bool flag exists
|
|
|
b215bf |
+func (c *Context) BoolT(name string) bool {
|
|
|
b215bf |
+ return lookupBoolT(name, c.flagSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a local string flag, returns "" if no string flag exists
|
|
|
b215bf |
+func (c *Context) String(name string) string {
|
|
|
b215bf |
+ return lookupString(name, c.flagSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a local string slice flag, returns nil if no string slice flag exists
|
|
|
b215bf |
+func (c *Context) StringSlice(name string) []string {
|
|
|
b215bf |
+ return lookupStringSlice(name, c.flagSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a local int slice flag, returns nil if no int slice flag exists
|
|
|
b215bf |
+func (c *Context) IntSlice(name string) []int {
|
|
|
b215bf |
+ return lookupIntSlice(name, c.flagSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a local generic flag, returns nil if no generic flag exists
|
|
|
b215bf |
+func (c *Context) Generic(name string) interface{} {
|
|
|
b215bf |
+ return lookupGeneric(name, c.flagSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a global int flag, returns 0 if no int flag exists
|
|
|
b215bf |
+func (c *Context) GlobalInt(name string) int {
|
|
|
b215bf |
+ return lookupInt(name, c.globalSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a global bool flag, returns false if no bool flag exists
|
|
|
b215bf |
+func (c *Context) GlobalBool(name string) bool {
|
|
|
b215bf |
+ return lookupBool(name, c.globalSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a global string flag, returns "" if no string flag exists
|
|
|
b215bf |
+func (c *Context) GlobalString(name string) string {
|
|
|
b215bf |
+ return lookupString(name, c.globalSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a global string slice flag, returns nil if no string slice flag exists
|
|
|
b215bf |
+func (c *Context) GlobalStringSlice(name string) []string {
|
|
|
b215bf |
+ return lookupStringSlice(name, c.globalSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a global int slice flag, returns nil if no int slice flag exists
|
|
|
b215bf |
+func (c *Context) GlobalIntSlice(name string) []int {
|
|
|
b215bf |
+ return lookupIntSlice(name, c.globalSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Looks up the value of a global generic flag, returns nil if no generic flag exists
|
|
|
b215bf |
+func (c *Context) GlobalGeneric(name string) interface{} {
|
|
|
b215bf |
+ return lookupGeneric(name, c.globalSet)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Determines if the flag was actually set exists
|
|
|
b215bf |
+func (c *Context) IsSet(name string) bool {
|
|
|
b215bf |
+ if c.setFlags == nil {
|
|
|
b215bf |
+ c.setFlags = make(map[string]bool)
|
|
|
b215bf |
+ c.flagSet.Visit(func(f *flag.Flag) {
|
|
|
b215bf |
+ c.setFlags[f.Name] = true
|
|
|
b215bf |
+ })
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return c.setFlags[name] == true
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+type Args []string
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Returns the command line arguments associated with the context.
|
|
|
b215bf |
+func (c *Context) Args() Args {
|
|
|
b215bf |
+ args := Args(c.flagSet.Args())
|
|
|
b215bf |
+ return args
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Returns the nth argument, or else a blank string
|
|
|
b215bf |
+func (a Args) Get(n int) string {
|
|
|
b215bf |
+ if len(a) > n {
|
|
|
b215bf |
+ return a[n]
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return ""
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Returns the first argument, or else a blank string
|
|
|
b215bf |
+func (a Args) First() string {
|
|
|
b215bf |
+ return a.Get(0)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Return the rest of the arguments (not the first one)
|
|
|
b215bf |
+// or else an empty string slice
|
|
|
b215bf |
+func (a Args) Tail() []string {
|
|
|
b215bf |
+ if len(a) >= 2 {
|
|
|
b215bf |
+ return []string(a)[1:]
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return []string{}
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Checks if there are any arguments present
|
|
|
b215bf |
+func (a Args) Present() bool {
|
|
|
b215bf |
+ return len(a) != 0
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Swaps arguments at the given indexes
|
|
|
b215bf |
+func (a Args) Swap(from, to int) error {
|
|
|
b215bf |
+ if from >= len(a) || to >= len(a) {
|
|
|
b215bf |
+ return errors.New("index out of range")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ a[from], a[to] = a[to], a[from]
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func lookupInt(name string, set *flag.FlagSet) int {
|
|
|
b215bf |
+ f := set.Lookup(name)
|
|
|
b215bf |
+ if f != nil {
|
|
|
b215bf |
+ val, err := strconv.Atoi(f.Value.String())
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ return 0
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return val
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return 0
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func lookupFloat64(name string, set *flag.FlagSet) float64 {
|
|
|
b215bf |
+ f := set.Lookup(name)
|
|
|
b215bf |
+ if f != nil {
|
|
|
b215bf |
+ val, err := strconv.ParseFloat(f.Value.String(), 64)
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ return 0
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return val
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return 0
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func lookupString(name string, set *flag.FlagSet) string {
|
|
|
b215bf |
+ f := set.Lookup(name)
|
|
|
b215bf |
+ if f != nil {
|
|
|
b215bf |
+ return f.Value.String()
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return ""
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func lookupStringSlice(name string, set *flag.FlagSet) []string {
|
|
|
b215bf |
+ f := set.Lookup(name)
|
|
|
b215bf |
+ if f != nil {
|
|
|
b215bf |
+ return (f.Value.(*StringSlice)).Value()
|
|
|
b215bf |
+
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func lookupIntSlice(name string, set *flag.FlagSet) []int {
|
|
|
b215bf |
+ f := set.Lookup(name)
|
|
|
b215bf |
+ if f != nil {
|
|
|
b215bf |
+ return (f.Value.(*IntSlice)).Value()
|
|
|
b215bf |
+
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func lookupGeneric(name string, set *flag.FlagSet) interface{} {
|
|
|
b215bf |
+ f := set.Lookup(name)
|
|
|
b215bf |
+ if f != nil {
|
|
|
b215bf |
+ return f.Value
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func lookupBool(name string, set *flag.FlagSet) bool {
|
|
|
b215bf |
+ f := set.Lookup(name)
|
|
|
b215bf |
+ if f != nil {
|
|
|
b215bf |
+ val, err := strconv.ParseBool(f.Value.String())
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return val
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func lookupBoolT(name string, set *flag.FlagSet) bool {
|
|
|
b215bf |
+ f := set.Lookup(name)
|
|
|
b215bf |
+ if f != nil {
|
|
|
b215bf |
+ val, err := strconv.ParseBool(f.Value.String())
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ return true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return val
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) {
|
|
|
b215bf |
+ switch ff.Value.(type) {
|
|
|
b215bf |
+ case *StringSlice:
|
|
|
b215bf |
+ default:
|
|
|
b215bf |
+ set.Set(name, ff.Value.String())
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func normalizeFlags(flags []Flag, set *flag.FlagSet) error {
|
|
|
b215bf |
+ visited := make(map[string]bool)
|
|
|
b215bf |
+ set.Visit(func(f *flag.Flag) {
|
|
|
b215bf |
+ visited[f.Name] = true
|
|
|
b215bf |
+ })
|
|
|
b215bf |
+ for _, f := range flags {
|
|
|
b215bf |
+ parts := strings.Split(f.getName(), ",")
|
|
|
b215bf |
+ if len(parts) == 1 {
|
|
|
b215bf |
+ continue
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ var ff *flag.Flag
|
|
|
b215bf |
+ for _, name := range parts {
|
|
|
b215bf |
+ name = strings.Trim(name, " ")
|
|
|
b215bf |
+ if visited[name] {
|
|
|
b215bf |
+ if ff != nil {
|
|
|
b215bf |
+ return errors.New("Cannot use two forms of the same flag: " + name + " " + ff.Name)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ ff = set.Lookup(name)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ if ff == nil {
|
|
|
b215bf |
+ continue
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ for _, name := range parts {
|
|
|
b215bf |
+ name = strings.Trim(name, " ")
|
|
|
b215bf |
+ if !visited[name] {
|
|
|
b215bf |
+ copyFlag(name, ff, set)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/context_test.go docker-1/vendor/src/github.com/codegangsta/cli/context_test.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/context_test.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/context_test.go 2015-01-16 03:56:49.104152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,68 @@
|
|
|
b215bf |
+package cli_test
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "flag"
|
|
|
b215bf |
+ "github.com/codegangsta/cli"
|
|
|
b215bf |
+ "testing"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestNewContext(t *testing.T) {
|
|
|
b215bf |
+ set := flag.NewFlagSet("test", 0)
|
|
|
b215bf |
+ set.Int("myflag", 12, "doc")
|
|
|
b215bf |
+ globalSet := flag.NewFlagSet("test", 0)
|
|
|
b215bf |
+ globalSet.Int("myflag", 42, "doc")
|
|
|
b215bf |
+ command := cli.Command{Name: "mycommand"}
|
|
|
b215bf |
+ c := cli.NewContext(nil, set, globalSet)
|
|
|
b215bf |
+ c.Command = command
|
|
|
b215bf |
+ expect(t, c.Int("myflag"), 12)
|
|
|
b215bf |
+ expect(t, c.GlobalInt("myflag"), 42)
|
|
|
b215bf |
+ expect(t, c.Command.Name, "mycommand")
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestContext_Int(t *testing.T) {
|
|
|
b215bf |
+ set := flag.NewFlagSet("test", 0)
|
|
|
b215bf |
+ set.Int("myflag", 12, "doc")
|
|
|
b215bf |
+ c := cli.NewContext(nil, set, set)
|
|
|
b215bf |
+ expect(t, c.Int("myflag"), 12)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestContext_String(t *testing.T) {
|
|
|
b215bf |
+ set := flag.NewFlagSet("test", 0)
|
|
|
b215bf |
+ set.String("myflag", "hello world", "doc")
|
|
|
b215bf |
+ c := cli.NewContext(nil, set, set)
|
|
|
b215bf |
+ expect(t, c.String("myflag"), "hello world")
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestContext_Bool(t *testing.T) {
|
|
|
b215bf |
+ set := flag.NewFlagSet("test", 0)
|
|
|
b215bf |
+ set.Bool("myflag", false, "doc")
|
|
|
b215bf |
+ c := cli.NewContext(nil, set, set)
|
|
|
b215bf |
+ expect(t, c.Bool("myflag"), false)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestContext_BoolT(t *testing.T) {
|
|
|
b215bf |
+ set := flag.NewFlagSet("test", 0)
|
|
|
b215bf |
+ set.Bool("myflag", true, "doc")
|
|
|
b215bf |
+ c := cli.NewContext(nil, set, set)
|
|
|
b215bf |
+ expect(t, c.BoolT("myflag"), true)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestContext_Args(t *testing.T) {
|
|
|
b215bf |
+ set := flag.NewFlagSet("test", 0)
|
|
|
b215bf |
+ set.Bool("myflag", false, "doc")
|
|
|
b215bf |
+ c := cli.NewContext(nil, set, set)
|
|
|
b215bf |
+ set.Parse([]string{"--myflag", "bat", "baz"})
|
|
|
b215bf |
+ expect(t, len(c.Args()), 2)
|
|
|
b215bf |
+ expect(t, c.Bool("myflag"), true)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestContext_IsSet(t *testing.T) {
|
|
|
b215bf |
+ set := flag.NewFlagSet("test", 0)
|
|
|
b215bf |
+ set.Bool("myflag", false, "doc")
|
|
|
b215bf |
+ set.String("otherflag", "hello world", "doc")
|
|
|
b215bf |
+ c := cli.NewContext(nil, set, set)
|
|
|
b215bf |
+ set.Parse([]string{"--myflag", "bat", "baz"})
|
|
|
b215bf |
+ expect(t, c.IsSet("myflag"), true)
|
|
|
b215bf |
+ expect(t, c.IsSet("otherflag"), false)
|
|
|
b215bf |
+ expect(t, c.IsSet("bogusflag"), false)
|
|
|
b215bf |
+}
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/flag.go docker-1/vendor/src/github.com/codegangsta/cli/flag.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/flag.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/flag.go 2015-01-16 03:56:49.103152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,280 @@
|
|
|
b215bf |
+package cli
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "flag"
|
|
|
b215bf |
+ "fmt"
|
|
|
b215bf |
+ "strconv"
|
|
|
b215bf |
+ "strings"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+// This flag enables bash-completion for all commands and subcommands
|
|
|
b215bf |
+var BashCompletionFlag = BoolFlag{"generate-bash-completion", ""}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// This flag prints the version for the application
|
|
|
b215bf |
+var VersionFlag = BoolFlag{"version, v", "print the version"}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// This flag prints the help for all commands and subcommands
|
|
|
b215bf |
+var HelpFlag = BoolFlag{"help, h", "show help"}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Flag is a common interface related to parsing flags in cli.
|
|
|
b215bf |
+// For more advanced flag parsing techniques, it is recomended that
|
|
|
b215bf |
+// this interface be implemented.
|
|
|
b215bf |
+type Flag interface {
|
|
|
b215bf |
+ fmt.Stringer
|
|
|
b215bf |
+ // Apply Flag settings to the given flag set
|
|
|
b215bf |
+ Apply(*flag.FlagSet)
|
|
|
b215bf |
+ getName() string
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func flagSet(name string, flags []Flag) *flag.FlagSet {
|
|
|
b215bf |
+ set := flag.NewFlagSet(name, flag.ContinueOnError)
|
|
|
b215bf |
+
|
|
|
b215bf |
+ for _, f := range flags {
|
|
|
b215bf |
+ f.Apply(set)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return set
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func eachName(longName string, fn func(string)) {
|
|
|
b215bf |
+ parts := strings.Split(longName, ",")
|
|
|
b215bf |
+ for _, name := range parts {
|
|
|
b215bf |
+ name = strings.Trim(name, " ")
|
|
|
b215bf |
+ fn(name)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Generic is a generic parseable type identified by a specific flag
|
|
|
b215bf |
+type Generic interface {
|
|
|
b215bf |
+ Set(value string) error
|
|
|
b215bf |
+ String() string
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// GenericFlag is the flag type for types implementing Generic
|
|
|
b215bf |
+type GenericFlag struct {
|
|
|
b215bf |
+ Name string
|
|
|
b215bf |
+ Value Generic
|
|
|
b215bf |
+ Usage string
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f GenericFlag) String() string {
|
|
|
b215bf |
+ return fmt.Sprintf("%s%s %v\t`%v` %s", prefixFor(f.Name), f.Name, f.Value, "-"+f.Name+" option -"+f.Name+" option", f.Usage)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f GenericFlag) Apply(set *flag.FlagSet) {
|
|
|
b215bf |
+ eachName(f.Name, func(name string) {
|
|
|
b215bf |
+ set.Var(f.Value, name, f.Usage)
|
|
|
b215bf |
+ })
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f GenericFlag) getName() string {
|
|
|
b215bf |
+ return f.Name
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+type StringSlice []string
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f *StringSlice) Set(value string) error {
|
|
|
b215bf |
+ *f = append(*f, value)
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f *StringSlice) String() string {
|
|
|
b215bf |
+ return fmt.Sprintf("%s", *f)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f *StringSlice) Value() []string {
|
|
|
b215bf |
+ return *f
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+type StringSliceFlag struct {
|
|
|
b215bf |
+ Name string
|
|
|
b215bf |
+ Value *StringSlice
|
|
|
b215bf |
+ Usage string
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f StringSliceFlag) String() string {
|
|
|
b215bf |
+ firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
|
|
|
b215bf |
+ pref := prefixFor(firstName)
|
|
|
b215bf |
+ return fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f StringSliceFlag) Apply(set *flag.FlagSet) {
|
|
|
b215bf |
+ eachName(f.Name, func(name string) {
|
|
|
b215bf |
+ set.Var(f.Value, name, f.Usage)
|
|
|
b215bf |
+ })
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f StringSliceFlag) getName() string {
|
|
|
b215bf |
+ return f.Name
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+type IntSlice []int
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f *IntSlice) Set(value string) error {
|
|
|
b215bf |
+
|
|
|
b215bf |
+ tmp, err := strconv.Atoi(value)
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ return err
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ *f = append(*f, tmp)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f *IntSlice) String() string {
|
|
|
b215bf |
+ return fmt.Sprintf("%d", *f)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f *IntSlice) Value() []int {
|
|
|
b215bf |
+ return *f
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+type IntSliceFlag struct {
|
|
|
b215bf |
+ Name string
|
|
|
b215bf |
+ Value *IntSlice
|
|
|
b215bf |
+ Usage string
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f IntSliceFlag) String() string {
|
|
|
b215bf |
+ firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
|
|
|
b215bf |
+ pref := prefixFor(firstName)
|
|
|
b215bf |
+ return fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f IntSliceFlag) Apply(set *flag.FlagSet) {
|
|
|
b215bf |
+ eachName(f.Name, func(name string) {
|
|
|
b215bf |
+ set.Var(f.Value, name, f.Usage)
|
|
|
b215bf |
+ })
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f IntSliceFlag) getName() string {
|
|
|
b215bf |
+ return f.Name
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+type BoolFlag struct {
|
|
|
b215bf |
+ Name string
|
|
|
b215bf |
+ Usage string
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f BoolFlag) String() string {
|
|
|
b215bf |
+ return fmt.Sprintf("%s\t%v", prefixedNames(f.Name), f.Usage)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f BoolFlag) Apply(set *flag.FlagSet) {
|
|
|
b215bf |
+ eachName(f.Name, func(name string) {
|
|
|
b215bf |
+ set.Bool(name, false, f.Usage)
|
|
|
b215bf |
+ })
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f BoolFlag) getName() string {
|
|
|
b215bf |
+ return f.Name
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+type BoolTFlag struct {
|
|
|
b215bf |
+ Name string
|
|
|
b215bf |
+ Usage string
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f BoolTFlag) String() string {
|
|
|
b215bf |
+ return fmt.Sprintf("%s\t%v", prefixedNames(f.Name), f.Usage)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f BoolTFlag) Apply(set *flag.FlagSet) {
|
|
|
b215bf |
+ eachName(f.Name, func(name string) {
|
|
|
b215bf |
+ set.Bool(name, true, f.Usage)
|
|
|
b215bf |
+ })
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f BoolTFlag) getName() string {
|
|
|
b215bf |
+ return f.Name
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+type StringFlag struct {
|
|
|
b215bf |
+ Name string
|
|
|
b215bf |
+ Value string
|
|
|
b215bf |
+ Usage string
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f StringFlag) String() string {
|
|
|
b215bf |
+ var fmtString string
|
|
|
b215bf |
+ fmtString = "%s %v\t%v"
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if len(f.Value) > 0 {
|
|
|
b215bf |
+ fmtString = "%s '%v'\t%v"
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ fmtString = "%s %v\t%v"
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return fmt.Sprintf(fmtString, prefixedNames(f.Name), f.Value, f.Usage)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f StringFlag) Apply(set *flag.FlagSet) {
|
|
|
b215bf |
+ eachName(f.Name, func(name string) {
|
|
|
b215bf |
+ set.String(name, f.Value, f.Usage)
|
|
|
b215bf |
+ })
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f StringFlag) getName() string {
|
|
|
b215bf |
+ return f.Name
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+type IntFlag struct {
|
|
|
b215bf |
+ Name string
|
|
|
b215bf |
+ Value int
|
|
|
b215bf |
+ Usage string
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f IntFlag) String() string {
|
|
|
b215bf |
+ return fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), f.Value, f.Usage)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f IntFlag) Apply(set *flag.FlagSet) {
|
|
|
b215bf |
+ eachName(f.Name, func(name string) {
|
|
|
b215bf |
+ set.Int(name, f.Value, f.Usage)
|
|
|
b215bf |
+ })
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f IntFlag) getName() string {
|
|
|
b215bf |
+ return f.Name
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+type Float64Flag struct {
|
|
|
b215bf |
+ Name string
|
|
|
b215bf |
+ Value float64
|
|
|
b215bf |
+ Usage string
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f Float64Flag) String() string {
|
|
|
b215bf |
+ return fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), f.Value, f.Usage)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f Float64Flag) Apply(set *flag.FlagSet) {
|
|
|
b215bf |
+ eachName(f.Name, func(name string) {
|
|
|
b215bf |
+ set.Float64(name, f.Value, f.Usage)
|
|
|
b215bf |
+ })
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (f Float64Flag) getName() string {
|
|
|
b215bf |
+ return f.Name
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func prefixFor(name string) (prefix string) {
|
|
|
b215bf |
+ if len(name) == 1 {
|
|
|
b215bf |
+ prefix = "-"
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ prefix = "--"
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func prefixedNames(fullName string) (prefixed string) {
|
|
|
b215bf |
+ parts := strings.Split(fullName, ",")
|
|
|
b215bf |
+ for i, name := range parts {
|
|
|
b215bf |
+ name = strings.Trim(name, " ")
|
|
|
b215bf |
+ prefixed += prefixFor(name) + name
|
|
|
b215bf |
+ if i < len(parts)-1 {
|
|
|
b215bf |
+ prefixed += ", "
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ return
|
|
|
b215bf |
+}
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/flag_test.go docker-1/vendor/src/github.com/codegangsta/cli/flag_test.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/flag_test.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/flag_test.go 2015-01-16 03:56:49.103152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,194 @@
|
|
|
b215bf |
+package cli_test
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "github.com/codegangsta/cli"
|
|
|
b215bf |
+
|
|
|
b215bf |
+ "fmt"
|
|
|
b215bf |
+ "reflect"
|
|
|
b215bf |
+ "strings"
|
|
|
b215bf |
+ "testing"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+var boolFlagTests = []struct {
|
|
|
b215bf |
+ name string
|
|
|
b215bf |
+ expected string
|
|
|
b215bf |
+}{
|
|
|
b215bf |
+ {"help", "--help\t"},
|
|
|
b215bf |
+ {"h", "-h\t"},
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestBoolFlagHelpOutput(t *testing.T) {
|
|
|
b215bf |
+
|
|
|
b215bf |
+ for _, test := range boolFlagTests {
|
|
|
b215bf |
+ flag := cli.BoolFlag{Name: test.name}
|
|
|
b215bf |
+ output := flag.String()
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if output != test.expected {
|
|
|
b215bf |
+ t.Errorf("%s does not match %s", output, test.expected)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+var stringFlagTests = []struct {
|
|
|
b215bf |
+ name string
|
|
|
b215bf |
+ value string
|
|
|
b215bf |
+ expected string
|
|
|
b215bf |
+}{
|
|
|
b215bf |
+ {"help", "", "--help \t"},
|
|
|
b215bf |
+ {"h", "", "-h \t"},
|
|
|
b215bf |
+ {"h", "", "-h \t"},
|
|
|
b215bf |
+ {"test", "Something", "--test 'Something'\t"},
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestStringFlagHelpOutput(t *testing.T) {
|
|
|
b215bf |
+
|
|
|
b215bf |
+ for _, test := range stringFlagTests {
|
|
|
b215bf |
+ flag := cli.StringFlag{Name: test.name, Value: test.value}
|
|
|
b215bf |
+ output := flag.String()
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if output != test.expected {
|
|
|
b215bf |
+ t.Errorf("%s does not match %s", output, test.expected)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+var intFlagTests = []struct {
|
|
|
b215bf |
+ name string
|
|
|
b215bf |
+ expected string
|
|
|
b215bf |
+}{
|
|
|
b215bf |
+ {"help", "--help '0'\t"},
|
|
|
b215bf |
+ {"h", "-h '0'\t"},
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestIntFlagHelpOutput(t *testing.T) {
|
|
|
b215bf |
+
|
|
|
b215bf |
+ for _, test := range intFlagTests {
|
|
|
b215bf |
+ flag := cli.IntFlag{Name: test.name}
|
|
|
b215bf |
+ output := flag.String()
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if output != test.expected {
|
|
|
b215bf |
+ t.Errorf("%s does not match %s", output, test.expected)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+var float64FlagTests = []struct {
|
|
|
b215bf |
+ name string
|
|
|
b215bf |
+ expected string
|
|
|
b215bf |
+}{
|
|
|
b215bf |
+ {"help", "--help '0'\t"},
|
|
|
b215bf |
+ {"h", "-h '0'\t"},
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestFloat64FlagHelpOutput(t *testing.T) {
|
|
|
b215bf |
+
|
|
|
b215bf |
+ for _, test := range float64FlagTests {
|
|
|
b215bf |
+ flag := cli.Float64Flag{Name: test.name}
|
|
|
b215bf |
+ output := flag.String()
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if output != test.expected {
|
|
|
b215bf |
+ t.Errorf("%s does not match %s", output, test.expected)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestParseMultiString(t *testing.T) {
|
|
|
b215bf |
+ (&cli.App{
|
|
|
b215bf |
+ Flags: []cli.Flag{
|
|
|
b215bf |
+ cli.StringFlag{Name: "serve, s"},
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ Action: func(ctx *cli.Context) {
|
|
|
b215bf |
+ if ctx.String("serve") != "10" {
|
|
|
b215bf |
+ t.Errorf("main name not set")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ if ctx.String("s") != "10" {
|
|
|
b215bf |
+ t.Errorf("short name not set")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }).Run([]string{"run", "-s", "10"})
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestParseMultiStringSlice(t *testing.T) {
|
|
|
b215bf |
+ (&cli.App{
|
|
|
b215bf |
+ Flags: []cli.Flag{
|
|
|
b215bf |
+ cli.StringSliceFlag{Name: "serve, s", Value: &cli.StringSlice{}},
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ Action: func(ctx *cli.Context) {
|
|
|
b215bf |
+ if !reflect.DeepEqual(ctx.StringSlice("serve"), []string{"10", "20"}) {
|
|
|
b215bf |
+ t.Errorf("main name not set")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ if !reflect.DeepEqual(ctx.StringSlice("s"), []string{"10", "20"}) {
|
|
|
b215bf |
+ t.Errorf("short name not set")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }).Run([]string{"run", "-s", "10", "-s", "20"})
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestParseMultiInt(t *testing.T) {
|
|
|
b215bf |
+ a := cli.App{
|
|
|
b215bf |
+ Flags: []cli.Flag{
|
|
|
b215bf |
+ cli.IntFlag{Name: "serve, s"},
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ Action: func(ctx *cli.Context) {
|
|
|
b215bf |
+ if ctx.Int("serve") != 10 {
|
|
|
b215bf |
+ t.Errorf("main name not set")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ if ctx.Int("s") != 10 {
|
|
|
b215bf |
+ t.Errorf("short name not set")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ a.Run([]string{"run", "-s", "10"})
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestParseMultiBool(t *testing.T) {
|
|
|
b215bf |
+ a := cli.App{
|
|
|
b215bf |
+ Flags: []cli.Flag{
|
|
|
b215bf |
+ cli.BoolFlag{Name: "serve, s"},
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ Action: func(ctx *cli.Context) {
|
|
|
b215bf |
+ if ctx.Bool("serve") != true {
|
|
|
b215bf |
+ t.Errorf("main name not set")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ if ctx.Bool("s") != true {
|
|
|
b215bf |
+ t.Errorf("short name not set")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ a.Run([]string{"run", "--serve"})
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+type Parser [2]string
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (p *Parser) Set(value string) error {
|
|
|
b215bf |
+ parts := strings.Split(value, ",")
|
|
|
b215bf |
+ if len(parts) != 2 {
|
|
|
b215bf |
+ return fmt.Errorf("invalid format")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ (*p)[0] = parts[0]
|
|
|
b215bf |
+ (*p)[1] = parts[1]
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return nil
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func (p *Parser) String() string {
|
|
|
b215bf |
+ return fmt.Sprintf("%s,%s", p[0], p[1])
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func TestParseGeneric(t *testing.T) {
|
|
|
b215bf |
+ a := cli.App{
|
|
|
b215bf |
+ Flags: []cli.Flag{
|
|
|
b215bf |
+ cli.GenericFlag{Name: "serve, s", Value: &Parser{}},
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ Action: func(ctx *cli.Context) {
|
|
|
b215bf |
+ if !reflect.DeepEqual(ctx.Generic("serve"), &Parser{"10", "20"}) {
|
|
|
b215bf |
+ t.Errorf("main name not set")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ if !reflect.DeepEqual(ctx.Generic("s"), &Parser{"10", "20"}) {
|
|
|
b215bf |
+ t.Errorf("short name not set")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ a.Run([]string{"run", "-s", "10,20"})
|
|
|
b215bf |
+}
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/helpers_test.go docker-1/vendor/src/github.com/codegangsta/cli/helpers_test.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/helpers_test.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/helpers_test.go 2015-01-16 03:56:49.104152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,19 @@
|
|
|
b215bf |
+package cli_test
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "reflect"
|
|
|
b215bf |
+ "testing"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+/* Test Helpers */
|
|
|
b215bf |
+func expect(t *testing.T, a interface{}, b interface{}) {
|
|
|
b215bf |
+ if a != b {
|
|
|
b215bf |
+ t.Errorf("Expected %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a))
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func refute(t *testing.T, a interface{}, b interface{}) {
|
|
|
b215bf |
+ if a == b {
|
|
|
b215bf |
+ t.Errorf("Did not expect %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a))
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/help.go docker-1/vendor/src/github.com/codegangsta/cli/help.go
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/help.go 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/help.go 2015-01-16 03:56:49.104152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,213 @@
|
|
|
b215bf |
+package cli
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "fmt"
|
|
|
b215bf |
+ "os"
|
|
|
b215bf |
+ "text/tabwriter"
|
|
|
b215bf |
+ "text/template"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+// The text template for the Default help topic.
|
|
|
b215bf |
+// cli.go uses text/template to render templates. You can
|
|
|
b215bf |
+// render custom help text by setting this variable.
|
|
|
b215bf |
+var AppHelpTemplate = `NAME:
|
|
|
b215bf |
+ {{.Name}} - {{.Usage}}
|
|
|
b215bf |
+
|
|
|
b215bf |
+USAGE:
|
|
|
b215bf |
+ {{.Name}} {{ if .Flags }}[global options] {{ end }}command{{ if .Flags }} [command options]{{ end }} [arguments...]
|
|
|
b215bf |
+
|
|
|
b215bf |
+VERSION:
|
|
|
b215bf |
+ {{.Version}}
|
|
|
b215bf |
+
|
|
|
b215bf |
+COMMANDS:
|
|
|
b215bf |
+ {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
|
|
b215bf |
+ {{end}}{{ if .Flags }}
|
|
|
b215bf |
+GLOBAL OPTIONS:
|
|
|
b215bf |
+ {{range .Flags}}{{.}}
|
|
|
b215bf |
+ {{end}}{{ end }}
|
|
|
b215bf |
+`
|
|
|
b215bf |
+
|
|
|
b215bf |
+// The text template for the command help topic.
|
|
|
b215bf |
+// cli.go uses text/template to render templates. You can
|
|
|
b215bf |
+// render custom help text by setting this variable.
|
|
|
b215bf |
+var CommandHelpTemplate = `NAME:
|
|
|
b215bf |
+ {{.Name}} - {{.Usage}}
|
|
|
b215bf |
+
|
|
|
b215bf |
+USAGE:
|
|
|
b215bf |
+ command {{.Name}}{{ if .Flags }} [command options]{{ end }} [arguments...]
|
|
|
b215bf |
+
|
|
|
b215bf |
+DESCRIPTION:
|
|
|
b215bf |
+ {{.Description}}{{ if .Flags }}
|
|
|
b215bf |
+
|
|
|
b215bf |
+OPTIONS:
|
|
|
b215bf |
+ {{range .Flags}}{{.}}
|
|
|
b215bf |
+ {{end}}{{ end }}
|
|
|
b215bf |
+`
|
|
|
b215bf |
+
|
|
|
b215bf |
+// The text template for the subcommand help topic.
|
|
|
b215bf |
+// cli.go uses text/template to render templates. You can
|
|
|
b215bf |
+// render custom help text by setting this variable.
|
|
|
b215bf |
+var SubcommandHelpTemplate = `NAME:
|
|
|
b215bf |
+ {{.Name}} - {{.Usage}}
|
|
|
b215bf |
+
|
|
|
b215bf |
+USAGE:
|
|
|
b215bf |
+ {{.Name}} command{{ if .Flags }} [command options]{{ end }} [arguments...]
|
|
|
b215bf |
+
|
|
|
b215bf |
+COMMANDS:
|
|
|
b215bf |
+ {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
|
|
b215bf |
+ {{end}}{{ if .Flags }}
|
|
|
b215bf |
+OPTIONS:
|
|
|
b215bf |
+ {{range .Flags}}{{.}}
|
|
|
b215bf |
+ {{end}}{{ end }}
|
|
|
b215bf |
+`
|
|
|
b215bf |
+
|
|
|
b215bf |
+var helpCommand = Command{
|
|
|
b215bf |
+ Name: "help",
|
|
|
b215bf |
+ ShortName: "h",
|
|
|
b215bf |
+ Usage: "Shows a list of commands or help for one command",
|
|
|
b215bf |
+ Action: func(c *Context) {
|
|
|
b215bf |
+ args := c.Args()
|
|
|
b215bf |
+ if args.Present() {
|
|
|
b215bf |
+ ShowCommandHelp(c, args.First())
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ ShowAppHelp(c)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+var helpSubcommand = Command{
|
|
|
b215bf |
+ Name: "help",
|
|
|
b215bf |
+ ShortName: "h",
|
|
|
b215bf |
+ Usage: "Shows a list of commands or help for one command",
|
|
|
b215bf |
+ Action: func(c *Context) {
|
|
|
b215bf |
+ args := c.Args()
|
|
|
b215bf |
+ if args.Present() {
|
|
|
b215bf |
+ ShowCommandHelp(c, args.First())
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ ShowSubcommandHelp(c)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Prints help for the App
|
|
|
b215bf |
+var HelpPrinter = printHelp
|
|
|
b215bf |
+
|
|
|
b215bf |
+func ShowAppHelp(c *Context) {
|
|
|
b215bf |
+ HelpPrinter(AppHelpTemplate, c.App)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Prints the list of subcommands as the default app completion method
|
|
|
b215bf |
+func DefaultAppComplete(c *Context) {
|
|
|
b215bf |
+ for _, command := range c.App.Commands {
|
|
|
b215bf |
+ fmt.Println(command.Name)
|
|
|
b215bf |
+ if command.ShortName != "" {
|
|
|
b215bf |
+ fmt.Println(command.ShortName)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Prints help for the given command
|
|
|
b215bf |
+func ShowCommandHelp(c *Context, command string) {
|
|
|
b215bf |
+ for _, c := range c.App.Commands {
|
|
|
b215bf |
+ if c.HasName(command) {
|
|
|
b215bf |
+ HelpPrinter(CommandHelpTemplate, c)
|
|
|
b215bf |
+ return
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ if c.App.CommandNotFound != nil {
|
|
|
b215bf |
+ c.App.CommandNotFound(c, command)
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ fmt.Printf("No help topic for '%v'\n", command)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Prints help for the given subcommand
|
|
|
b215bf |
+func ShowSubcommandHelp(c *Context) {
|
|
|
b215bf |
+ HelpPrinter(SubcommandHelpTemplate, c.App)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Prints the version number of the App
|
|
|
b215bf |
+func ShowVersion(c *Context) {
|
|
|
b215bf |
+ fmt.Printf("%v version %v\n", c.App.Name, c.App.Version)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Prints the lists of commands within a given context
|
|
|
b215bf |
+func ShowCompletions(c *Context) {
|
|
|
b215bf |
+ a := c.App
|
|
|
b215bf |
+ if a != nil && a.BashComplete != nil {
|
|
|
b215bf |
+ a.BashComplete(c)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+// Prints the custom completions for a given command
|
|
|
b215bf |
+func ShowCommandCompletions(ctx *Context, command string) {
|
|
|
b215bf |
+ c := ctx.App.Command(command)
|
|
|
b215bf |
+ if c != nil && c.BashComplete != nil {
|
|
|
b215bf |
+ c.BashComplete(ctx)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func printHelp(templ string, data interface{}) {
|
|
|
b215bf |
+ w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
|
|
b215bf |
+ t := template.Must(template.New("help").Parse(templ))
|
|
|
b215bf |
+ err := t.Execute(w, data)
|
|
|
b215bf |
+ if err != nil {
|
|
|
b215bf |
+ panic(err)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ w.Flush()
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func checkVersion(c *Context) bool {
|
|
|
b215bf |
+ if c.GlobalBool("version") {
|
|
|
b215bf |
+ ShowVersion(c)
|
|
|
b215bf |
+ return true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func checkHelp(c *Context) bool {
|
|
|
b215bf |
+ if c.GlobalBool("h") || c.GlobalBool("help") {
|
|
|
b215bf |
+ ShowAppHelp(c)
|
|
|
b215bf |
+ return true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func checkCommandHelp(c *Context, name string) bool {
|
|
|
b215bf |
+ if c.Bool("h") || c.Bool("help") {
|
|
|
b215bf |
+ ShowCommandHelp(c, name)
|
|
|
b215bf |
+ return true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func checkSubcommandHelp(c *Context) bool {
|
|
|
b215bf |
+ if c.GlobalBool("h") || c.GlobalBool("help") {
|
|
|
b215bf |
+ ShowSubcommandHelp(c)
|
|
|
b215bf |
+ return true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func checkCompletions(c *Context) bool {
|
|
|
b215bf |
+ if c.GlobalBool(BashCompletionFlag.Name) && c.App.EnableBashCompletion {
|
|
|
b215bf |
+ ShowCompletions(c)
|
|
|
b215bf |
+ return true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+}
|
|
|
b215bf |
+
|
|
|
b215bf |
+func checkCommandCompletions(c *Context, name string) bool {
|
|
|
b215bf |
+ if c.Bool(BashCompletionFlag.Name) && c.App.EnableBashCompletion {
|
|
|
b215bf |
+ ShowCommandCompletions(c, name)
|
|
|
b215bf |
+ return true
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ return false
|
|
|
b215bf |
+}
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/LICENSE docker-1/vendor/src/github.com/codegangsta/cli/LICENSE
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/LICENSE 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/LICENSE 2015-01-16 03:56:49.105152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,21 @@
|
|
|
b215bf |
+Copyright (C) 2013 Jeremy Saenz
|
|
|
b215bf |
+All Rights Reserved.
|
|
|
b215bf |
+
|
|
|
b215bf |
+MIT LICENSE
|
|
|
b215bf |
+
|
|
|
b215bf |
+Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
b215bf |
+this software and associated documentation files (the "Software"), to deal in
|
|
|
b215bf |
+the Software without restriction, including without limitation the rights to
|
|
|
b215bf |
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
b215bf |
+the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
b215bf |
+subject to the following conditions:
|
|
|
b215bf |
+
|
|
|
b215bf |
+The above copyright notice and this permission notice shall be included in all
|
|
|
b215bf |
+copies or substantial portions of the Software.
|
|
|
b215bf |
+
|
|
|
b215bf |
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
b215bf |
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
b215bf |
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
b215bf |
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
b215bf |
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
b215bf |
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/README.md docker-1/vendor/src/github.com/codegangsta/cli/README.md
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/README.md 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/README.md 2015-01-16 03:56:49.105152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,257 @@
|
|
|
b215bf |
+[![Build Status](https://travis-ci.org/codegangsta/cli.png?branch=master)](https://travis-ci.org/codegangsta/cli)
|
|
|
b215bf |
+
|
|
|
b215bf |
+# cli.go
|
|
|
b215bf |
+cli.go is simple, fast, and fun package for building command line apps in Go. The goal is to enable developers to write fast and distributable command line applications in an expressive way.
|
|
|
b215bf |
+
|
|
|
b215bf |
+You can view the API docs here:
|
|
|
b215bf |
+http://godoc.org/github.com/codegangsta/cli
|
|
|
b215bf |
+
|
|
|
b215bf |
+## Overview
|
|
|
b215bf |
+Command line apps are usually so tiny that there is absolutely no reason why your code should *not* be self-documenting. Things like generating help text and parsing command flags/options should not hinder productivity when writing a command line app.
|
|
|
b215bf |
+
|
|
|
b215bf |
+This is where cli.go comes into play. cli.go makes command line programming fun, organized, and expressive!
|
|
|
b215bf |
+
|
|
|
b215bf |
+## Installation
|
|
|
b215bf |
+Make sure you have a working Go environment (go 1.1 is *required*). [See the install instructions](http://golang.org/doc/install.html).
|
|
|
b215bf |
+
|
|
|
b215bf |
+To install cli.go, simply run:
|
|
|
b215bf |
+```
|
|
|
b215bf |
+$ go get github.com/codegangsta/cli
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+Make sure your PATH includes to the `$GOPATH/bin` directory so your commands can be easily used:
|
|
|
b215bf |
+```
|
|
|
b215bf |
+export PATH=$PATH:$GOPATH/bin
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+## Getting Started
|
|
|
b215bf |
+One of the philosophies behind cli.go is that an API should be playful and full of discovery. So a cli.go app can be as little as one line of code in `main()`.
|
|
|
b215bf |
+
|
|
|
b215bf |
+``` go
|
|
|
b215bf |
+package main
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "os"
|
|
|
b215bf |
+ "github.com/codegangsta/cli"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+func main() {
|
|
|
b215bf |
+ cli.NewApp().Run(os.Args)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+This app will run and show help text, but is not very useful. Let's give an action to execute and some help documentation:
|
|
|
b215bf |
+
|
|
|
b215bf |
+``` go
|
|
|
b215bf |
+package main
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "os"
|
|
|
b215bf |
+ "github.com/codegangsta/cli"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+func main() {
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ app.Name = "boom"
|
|
|
b215bf |
+ app.Usage = "make an explosive entrance"
|
|
|
b215bf |
+ app.Action = func(c *cli.Context) {
|
|
|
b215bf |
+ println("boom! I say!")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Run(os.Args)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+Running this already gives you a ton of functionality, plus support for things like subcommands and flags, which are covered below.
|
|
|
b215bf |
+
|
|
|
b215bf |
+## Example
|
|
|
b215bf |
+
|
|
|
b215bf |
+Being a programmer can be a lonely job. Thankfully by the power of automation that is not the case! Let's create a greeter app to fend off our demons of loneliness!
|
|
|
b215bf |
+
|
|
|
b215bf |
+``` go
|
|
|
b215bf |
+/* greet.go */
|
|
|
b215bf |
+package main
|
|
|
b215bf |
+
|
|
|
b215bf |
+import (
|
|
|
b215bf |
+ "os"
|
|
|
b215bf |
+ "github.com/codegangsta/cli"
|
|
|
b215bf |
+)
|
|
|
b215bf |
+
|
|
|
b215bf |
+func main() {
|
|
|
b215bf |
+ app := cli.NewApp()
|
|
|
b215bf |
+ app.Name = "greet"
|
|
|
b215bf |
+ app.Usage = "fight the loneliness!"
|
|
|
b215bf |
+ app.Action = func(c *cli.Context) {
|
|
|
b215bf |
+ println("Hello friend!")
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+
|
|
|
b215bf |
+ app.Run(os.Args)
|
|
|
b215bf |
+}
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+Install our command to the `$GOPATH/bin` directory:
|
|
|
b215bf |
+
|
|
|
b215bf |
+```
|
|
|
b215bf |
+$ go install
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+Finally run our new command:
|
|
|
b215bf |
+
|
|
|
b215bf |
+```
|
|
|
b215bf |
+$ greet
|
|
|
b215bf |
+Hello friend!
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+cli.go also generates some bitchass help text:
|
|
|
b215bf |
+```
|
|
|
b215bf |
+$ greet help
|
|
|
b215bf |
+NAME:
|
|
|
b215bf |
+ greet - fight the loneliness!
|
|
|
b215bf |
+
|
|
|
b215bf |
+USAGE:
|
|
|
b215bf |
+ greet [global options] command [command options] [arguments...]
|
|
|
b215bf |
+
|
|
|
b215bf |
+VERSION:
|
|
|
b215bf |
+ 0.0.0
|
|
|
b215bf |
+
|
|
|
b215bf |
+COMMANDS:
|
|
|
b215bf |
+ help, h Shows a list of commands or help for one command
|
|
|
b215bf |
+
|
|
|
b215bf |
+GLOBAL OPTIONS
|
|
|
b215bf |
+ --version Shows version information
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+### Arguments
|
|
|
b215bf |
+You can lookup arguments by calling the `Args` function on cli.Context.
|
|
|
b215bf |
+
|
|
|
b215bf |
+``` go
|
|
|
b215bf |
+...
|
|
|
b215bf |
+app.Action = func(c *cli.Context) {
|
|
|
b215bf |
+ println("Hello", c.Args()[0])
|
|
|
b215bf |
+}
|
|
|
b215bf |
+...
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+### Flags
|
|
|
b215bf |
+Setting and querying flags is simple.
|
|
|
b215bf |
+``` go
|
|
|
b215bf |
+...
|
|
|
b215bf |
+app.Flags = []cli.Flag {
|
|
|
b215bf |
+ cli.StringFlag{Name: "lang", Value: "english", Usage: "language for the greeting"},
|
|
|
b215bf |
+}
|
|
|
b215bf |
+app.Action = func(c *cli.Context) {
|
|
|
b215bf |
+ name := "someone"
|
|
|
b215bf |
+ if len(c.Args()) > 0 {
|
|
|
b215bf |
+ name = c.Args()[0]
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ if c.String("lang") == "spanish" {
|
|
|
b215bf |
+ println("Hola", name)
|
|
|
b215bf |
+ } else {
|
|
|
b215bf |
+ println("Hello", name)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+...
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+#### Alternate Names
|
|
|
b215bf |
+
|
|
|
b215bf |
+You can set alternate (or short) names for flags by providing a comma-delimited list for the Name. e.g.
|
|
|
b215bf |
+
|
|
|
b215bf |
+``` go
|
|
|
b215bf |
+app.Flags = []cli.Flag {
|
|
|
b215bf |
+ cli.StringFlag{Name: "lang, l", Value: "english", Usage: "language for the greeting"},
|
|
|
b215bf |
+}
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+That flag can then be set with `--lang spanish` or `-l spanish`. Note that giving two different forms of the same flag in the same command invocation is an error.
|
|
|
b215bf |
+
|
|
|
b215bf |
+### Subcommands
|
|
|
b215bf |
+
|
|
|
b215bf |
+Subcommands can be defined for a more git-like command line app.
|
|
|
b215bf |
+```go
|
|
|
b215bf |
+...
|
|
|
b215bf |
+app.Commands = []cli.Command{
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "add",
|
|
|
b215bf |
+ ShortName: "a",
|
|
|
b215bf |
+ Usage: "add a task to the list",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ println("added task: ", c.Args().First())
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "complete",
|
|
|
b215bf |
+ ShortName: "c",
|
|
|
b215bf |
+ Usage: "complete a task on the list",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ println("completed task: ", c.Args().First())
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "template",
|
|
|
b215bf |
+ ShortName: "r",
|
|
|
b215bf |
+ Usage: "options for task templates",
|
|
|
b215bf |
+ Subcommands: []cli.Command{
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "add",
|
|
|
b215bf |
+ Usage: "add a new template",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ println("new task template: ", c.Args().First())
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "remove",
|
|
|
b215bf |
+ Usage: "remove an existing template",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ println("removed task template: ", c.Args().First())
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+}
|
|
|
b215bf |
+...
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+### Bash Completion
|
|
|
b215bf |
+
|
|
|
b215bf |
+You can enable completion commands by setting the EnableBashCompletion
|
|
|
b215bf |
+flag on the App object. By default, this setting will only auto-complete to
|
|
|
b215bf |
+show an app's subcommands, but you can write your own completion methods for
|
|
|
b215bf |
+the App or its subcommands.
|
|
|
b215bf |
+```go
|
|
|
b215bf |
+...
|
|
|
b215bf |
+var tasks = []string{"cook", "clean", "laundry", "eat", "sleep", "code"}
|
|
|
b215bf |
+app := cli.NewApp()
|
|
|
b215bf |
+app.EnableBashCompletion = true
|
|
|
b215bf |
+app.Commands = []cli.Command{
|
|
|
b215bf |
+ {
|
|
|
b215bf |
+ Name: "complete",
|
|
|
b215bf |
+ ShortName: "c",
|
|
|
b215bf |
+ Usage: "complete a task on the list",
|
|
|
b215bf |
+ Action: func(c *cli.Context) {
|
|
|
b215bf |
+ println("completed task: ", c.Args().First())
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ BashComplete: func(c *cli.Context) {
|
|
|
b215bf |
+ // This will complete if no args are passed
|
|
|
b215bf |
+ if len(c.Args()) > 0 {
|
|
|
b215bf |
+ return
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ for _, t := range tasks {
|
|
|
b215bf |
+ println(t)
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+ },
|
|
|
b215bf |
+ }
|
|
|
b215bf |
+}
|
|
|
b215bf |
+...
|
|
|
b215bf |
+```
|
|
|
b215bf |
+
|
|
|
b215bf |
+#### To Enable
|
|
|
b215bf |
+
|
|
|
b215bf |
+Source the autocomplete/bash_autocomplete file in your .bashrc file while
|
|
|
b215bf |
+setting the PROG variable to the name of your program:
|
|
|
b215bf |
+
|
|
|
b215bf |
+`PROG=myprogram source /.../cli/autocomplete/bash_autocomplete`
|
|
|
b215bf |
+
|
|
|
b215bf |
+
|
|
|
b215bf |
+## About
|
|
|
b215bf |
+cli.go is written by none other than the [Code Gangsta](http://codegangsta.io)
|
|
|
b215bf |
diff -uNr docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/.travis.yml docker-1/vendor/src/github.com/codegangsta/cli/.travis.yml
|
|
|
b215bf |
--- docker-6ee24211b4111e0b1e1bd7a46c5a3c4ced1b2ffa/vendor/src/github.com/codegangsta/cli/.travis.yml 1969-12-31 19:00:00.000000000 -0500
|
|
|
b215bf |
+++ docker-1/vendor/src/github.com/codegangsta/cli/.travis.yml 2015-01-16 03:56:49.104152140 -0500
|
|
|
b215bf |
@@ -0,0 +1,6 @@
|
|
|
b215bf |
+language: go
|
|
|
b215bf |
+go: 1.1
|
|
|
b215bf |
+
|
|
|
b215bf |
+script:
|
|
|
b215bf |
+- go vet ./...
|
|
|
b215bf |
+- go test -v ./...
|