From 48e7531f7954a789c44948a42a78bfa237ad638c Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 18 Jun 2015 15:56:42 -0700 Subject: [PATCH] command/path-help: rename command, better error if sealed. Fixes #234 --- cli/commands.go | 4 ++-- command/{help.go => path_help.go} | 26 ++++++++++++++------- command/{help_test.go => path_help_test.go} | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) rename command/{help.go => path_help.go} (69%) rename command/{help_test.go => path_help_test.go} (95%) diff --git a/cli/commands.go b/cli/commands.go index 074b80dd11..d9cc3a8624 100644 --- a/cli/commands.go +++ b/cli/commands.go @@ -74,8 +74,8 @@ func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory { }, nil }, - "help": func() (cli.Command, error) { - return &command.HelpCommand{ + "path-help": func() (cli.Command, error) { + return &command.PathHelpCommand{ Meta: meta, }, nil }, diff --git a/command/help.go b/command/path_help.go similarity index 69% rename from command/help.go rename to command/path_help.go index f832f07bc6..792ea9e3a4 100644 --- a/command/help.go +++ b/command/path_help.go @@ -5,12 +5,12 @@ import ( "strings" ) -// HelpCommand is a Command that lists the mounts. -type HelpCommand struct { +// PathHelpCommand is a Command that lists the mounts. +type PathHelpCommand struct { Meta } -func (c *HelpCommand) Run(args []string) int { +func (c *PathHelpCommand) Run(args []string) int { flags := c.Meta.FlagSet("help", FlagSetDefault) flags.Usage = func() { c.Ui.Error(c.Help()) } if err := flags.Parse(args); err != nil { @@ -35,8 +35,15 @@ func (c *HelpCommand) Run(args []string) int { help, err := client.Help(path) if err != nil { - c.Ui.Error(fmt.Sprintf( - "Error reading help: %s", err)) + if strings.Contains(err.Error(), "Vault is sealed") { + c.Ui.Error(`Error: Vault is sealed. + +The path-help command requires the Vault to be unsealed so that +mount points of secret backends are known.`) + } else { + c.Ui.Error(fmt.Sprintf( + "Error reading help: %s", err)) + } return 1 } @@ -44,13 +51,13 @@ func (c *HelpCommand) Run(args []string) int { return 0 } -func (c *HelpCommand) Synopsis() string { +func (c *PathHelpCommand) Synopsis() string { return "Look up the help for a path" } -func (c *HelpCommand) Help() string { +func (c *PathHelpCommand) Help() string { helpText := ` -Usage: vault help [options] path +Usage: vault path-help [options] path Look up the help for a path. @@ -58,6 +65,9 @@ Usage: vault help [options] path providers provide built-in help. This command looks up and outputs that help. + The command requires that the Vault be unsealed, because otherwise + the mount points of the backends are unknown. + General Options: -address=addr The address of the Vault server. diff --git a/command/help_test.go b/command/path_help_test.go similarity index 95% rename from command/help_test.go rename to command/path_help_test.go index c4facc0ca8..faec9723d9 100644 --- a/command/help_test.go +++ b/command/path_help_test.go @@ -14,7 +14,7 @@ func TestHelp(t *testing.T) { defer ln.Close() ui := new(cli.MockUi) - c := &HelpCommand{ + c := &PathHelpCommand{ Meta: Meta{ ClientToken: token, Ui: ui,