From 33ea18fb215dee7d9d940f56ff6d91460d615ef3 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Tue, 9 Aug 2016 17:26:11 -0700 Subject: [PATCH] Updates mattn/go-isatty and mitchellh/cli. --- .../github.com/mattn/go-isatty/isatty_bsd.go | 2 +- vendor/github.com/mitchellh/cli/.travis.yml | 14 --- vendor/github.com/mitchellh/cli/Makefile | 20 +++ vendor/github.com/mitchellh/cli/cli.go | 117 +++++++++++++----- vendor/vendor.json | 8 +- 5 files changed, 113 insertions(+), 48 deletions(-) delete mode 100644 vendor/github.com/mitchellh/cli/.travis.yml create mode 100644 vendor/github.com/mitchellh/cli/Makefile diff --git a/vendor/github.com/mattn/go-isatty/isatty_bsd.go b/vendor/github.com/mattn/go-isatty/isatty_bsd.go index 98ffe86a4..42f2514d1 100644 --- a/vendor/github.com/mattn/go-isatty/isatty_bsd.go +++ b/vendor/github.com/mattn/go-isatty/isatty_bsd.go @@ -1,4 +1,4 @@ -// +build darwin freebsd openbsd netbsd +// +build darwin freebsd openbsd netbsd dragonfly // +build !appengine package isatty diff --git a/vendor/github.com/mitchellh/cli/.travis.yml b/vendor/github.com/mitchellh/cli/.travis.yml deleted file mode 100644 index c2f4ab263..000000000 --- a/vendor/github.com/mitchellh/cli/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -sudo: false - -language: go - -go: - - 1.2 - - 1.3 - - 1.4 - - 1.5 - - tip - -matrix: - allow_failures: - - go: tip diff --git a/vendor/github.com/mitchellh/cli/Makefile b/vendor/github.com/mitchellh/cli/Makefile new file mode 100644 index 000000000..4874b0082 --- /dev/null +++ b/vendor/github.com/mitchellh/cli/Makefile @@ -0,0 +1,20 @@ +TEST?=./... + +default: test + +# test runs the test suite and vets the code +test: + go list $(TEST) | xargs -n1 go test -timeout=60s -parallel=10 $(TESTARGS) + +# testrace runs the race checker +testrace: + go list $(TEST) | xargs -n1 go test -race $(TESTARGS) + +# updatedeps installs all the dependencies to run and build +updatedeps: + go list ./... \ + | xargs go list -f '{{ join .Deps "\n" }}{{ printf "\n" }}{{ join .TestImports "\n" }}' \ + | grep -v github.com/mitchellh/cli \ + | xargs go get -f -u -v + +.PHONY: test testrace updatedeps diff --git a/vendor/github.com/mitchellh/cli/cli.go b/vendor/github.com/mitchellh/cli/cli.go index e871e6136..bd663671d 100644 --- a/vendor/github.com/mitchellh/cli/cli.go +++ b/vendor/github.com/mitchellh/cli/cli.go @@ -122,20 +122,11 @@ func (c *CLI) Run() (int, error) { return 1, nil } - // If there is an invalid flag, then error - if len(c.topFlags) > 0 { - c.HelpWriter.Write([]byte( - "Invalid flags before the subcommand. If these flags are for\n" + - "the subcommand, please put them after the subcommand.\n\n")) - c.HelpWriter.Write([]byte(c.HelpFunc(c.Commands) + "\n")) - return 1, nil - } - // Attempt to get the factory function for creating the command // implementation. If the command is invalid or blank, it is an error. raw, ok := c.commandTree.Get(c.Subcommand()) if !ok { - c.HelpWriter.Write([]byte(c.HelpFunc(c.Commands) + "\n")) + c.HelpWriter.Write([]byte(c.HelpFunc(c.helpCommands(c.subcommandParent())) + "\n")) return 1, nil } @@ -150,6 +141,15 @@ func (c *CLI) Run() (int, error) { return 1, nil } + // If there is an invalid flag, then error + if len(c.topFlags) > 0 { + c.HelpWriter.Write([]byte( + "Invalid flags before the subcommand. If these flags are for\n" + + "the subcommand, please put them after the subcommand.\n\n")) + c.commandHelp(command) + return 1, nil + } + code := command.Run(c.SubcommandArgs()) if code == RunResultHelp { // Requesting help @@ -175,6 +175,27 @@ func (c *CLI) SubcommandArgs() []string { return c.subcommandArgs } +// subcommandParent returns the parent of this subcommand, if there is one. +// If there isn't on, "" is returned. +func (c *CLI) subcommandParent() string { + // Get the subcommand, if it is "" alread just return + sub := c.Subcommand() + if sub == "" { + return sub + } + + // Clear any trailing spaces and find the last space + sub = strings.TrimRight(sub, " ") + idx := strings.LastIndex(sub, " ") + + if idx == -1 { + // No space means our parent is root + return "" + } + + return sub[:idx] +} + func (c *CLI) init() { if c.HelpFunc == nil { c.HelpFunc = BasicHelpFunc("app") @@ -268,15 +289,14 @@ func (c *CLI) commandHelp(command Command) { } // Build subcommand list if we have it - var subcommands []map[string]interface{} + var subcommandsTpl []map[string]interface{} if c.commandNested { // Get the matching keys - var keys []string - prefix := c.Subcommand() + " " - c.commandTree.WalkPrefix(prefix, func(k string, raw interface{}) bool { + subcommands := c.helpCommands(c.Subcommand()) + keys := make([]string, 0, len(subcommands)) + for k := range subcommands { keys = append(keys, k) - return false - }) + } // Sort the keys sort.Strings(keys) @@ -290,34 +310,35 @@ func (c *CLI) commandHelp(command Command) { } // Go through and create their structures - subcommands = make([]map[string]interface{}, len(keys)) - for i, k := range keys { - raw, ok := c.commandTree.Get(k) - if !ok { - // We just checked that it should be here above. If it is - // isn't, there are serious problems. - panic("value is missing") - } - + subcommandsTpl = make([]map[string]interface{}, 0, len(subcommands)) + for _, k := range keys { // Get the command - sub, err := raw.(CommandFactory)() + raw, ok := subcommands[k] + if !ok { + c.HelpWriter.Write([]byte(fmt.Sprintf( + "Error getting subcommand %q", k))) + } + sub, err := raw() if err != nil { c.HelpWriter.Write([]byte(fmt.Sprintf( "Error instantiating %q: %s", k, err))) } - // Determine some info - name := strings.TrimPrefix(k, prefix) + // Find the last space and make sure we only include that last part + name := k + if idx := strings.LastIndex(k, " "); idx > -1 { + name = name[idx+1:] + } - subcommands[i] = map[string]interface{}{ + subcommandsTpl = append(subcommandsTpl, map[string]interface{}{ "Name": name, "NameAligned": name + strings.Repeat(" ", longest-len(k)), "Help": sub.Help(), "Synopsis": sub.Synopsis(), - } + }) } } - data["Subcommands"] = subcommands + data["Subcommands"] = subcommandsTpl // Write err = t.Execute(c.HelpWriter, data) @@ -330,6 +351,40 @@ func (c *CLI) commandHelp(command Command) { "Internal error rendering help: %s", err))) } +// helpCommands returns the subcommands for the HelpFunc argument. +// This will only contain immediate subcommands. +func (c *CLI) helpCommands(prefix string) map[string]CommandFactory { + // If our prefix isn't empty, make sure it ends in ' ' + if prefix != "" && prefix[len(prefix)-1] != ' ' { + prefix += " " + } + + // Get all the subkeys of this command + var keys []string + c.commandTree.WalkPrefix(prefix, func(k string, raw interface{}) bool { + // Ignore any sub-sub keys, i.e. "foo bar baz" when we want "foo bar" + if !strings.Contains(k[len(prefix):], " ") { + keys = append(keys, k) + } + + return false + }) + + // For each of the keys return that in the map + result := make(map[string]CommandFactory, len(keys)) + for _, k := range keys { + raw, ok := c.commandTree.Get(k) + if !ok { + // We just got it via WalkPrefix above, so we just panic + panic("not found: " + k) + } + + result[k] = raw.(CommandFactory) + } + + return result +} + func (c *CLI) processArgs() { for i, arg := range c.Args { if c.subcommand == "" { diff --git a/vendor/vendor.json b/vendor/vendor.json index f56201357..b00ec223e 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -420,8 +420,10 @@ "revision": "f693c7e88ba316d1a0ae3e205e22a01aa3ec2848" }, { + "checksumSHA1": "xZuhljnmBysJPta/lMyYmJdujCg=", "path": "github.com/mattn/go-isatty", - "revision": "56b76bdf51f7708750eac80fa38b952bb9f32639" + "revision": "66b8e73f3f5cda9f96b69efd03dd3d7fc4a5cdb8", + "revisionTime": "2016-08-06T12:27:52Z" }, { "checksumSHA1": "OUZ1FFXyKs+Cfg9M9rmXqqweQck=", @@ -430,8 +432,10 @@ "revisionTime": "2016-07-26T03:20:27Z" }, { + "checksumSHA1": "yF39M9MGatDbq2d2oqlLy44jsRc=", "path": "github.com/mitchellh/cli", - "revision": "cb6853d606ea4a12a15ac83cc43503df99fd28fb" + "revision": "168daae10d6ff81b8b1201b0a4c9607d7e9b82e3", + "revisionTime": "2016-03-23T17:07:00Z" }, { "path": "github.com/mitchellh/copystructure",