From c0e03dd118927e2776d9a26e61af434353b8e162 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 17 Jul 2017 14:30:51 -0700 Subject: [PATCH] address feedback, remove TODO --- autocomplete.go | 2 +- cli.go | 8 ++++++-- cli_test.go | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/autocomplete.go b/autocomplete.go index 9dcdc00..3bec625 100644 --- a/autocomplete.go +++ b/autocomplete.go @@ -4,7 +4,7 @@ import ( "github.com/posener/complete/cmd/install" ) -// autocompleteInstaller is an interface to be implemented to peform the +// autocompleteInstaller is an interface to be implemented to perform the // autocomplete installation and uninstallation with a CLI. // // This interface is not exported because it only exists for unit tests diff --git a/cli.go b/cli.go index b90360b..9663c61 100644 --- a/cli.go +++ b/cli.go @@ -176,8 +176,9 @@ func (c *CLI) Run() (int, error) { // If both install and uninstall flags are specified, then error if c.isAutocompleteInstall && c.isAutocompleteUninstall { - // TODO: Write error message - return 1, nil + return 1, fmt.Errorf( + "Either the autocomplete install or uninstall flag may " + + "be specified, but not both.") } // If the install flag is specified, perform the install or uninstall @@ -383,6 +384,9 @@ func (c *CLI) initAutocomplete() { c.autocomplete = complete.New(c.Name, cmd) } +// initAutocompleteSub creates the complete.Command for a subcommand with +// the given prefix. This will continue recursively for all subcommands. +// The prefix "" (empty string) can be used for the root command. func (c *CLI) initAutocompleteSub(prefix string) complete.Command { var cmd complete.Command walkFn := func(k string, raw interface{}) bool { diff --git a/cli_test.go b/cli_test.go index f4abc23..23f0305 100644 --- a/cli_test.go +++ b/cli_test.go @@ -636,8 +636,8 @@ func TestCLIRun_autocompleteBoth(t *testing.T) { } exitCode, err := cli.Run() - if err != nil { - t.Fatalf("err: %s", err) + if err == nil { + t.Fatal("should error") } if exitCode != 1 {