command/path-help: rename command, better error if sealed. Fixes #234

This commit is contained in:
Armon Dadgar
2015-06-18 15:56:42 -07:00
parent 2d0cde4ccc
commit 48e7531f79
3 changed files with 21 additions and 11 deletions

View File

@@ -74,8 +74,8 @@ func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {
}, nil }, nil
}, },
"help": func() (cli.Command, error) { "path-help": func() (cli.Command, error) {
return &command.HelpCommand{ return &command.PathHelpCommand{
Meta: meta, Meta: meta,
}, nil }, nil
}, },

View File

@@ -5,12 +5,12 @@ import (
"strings" "strings"
) )
// HelpCommand is a Command that lists the mounts. // PathHelpCommand is a Command that lists the mounts.
type HelpCommand struct { type PathHelpCommand struct {
Meta Meta
} }
func (c *HelpCommand) Run(args []string) int { func (c *PathHelpCommand) Run(args []string) int {
flags := c.Meta.FlagSet("help", FlagSetDefault) flags := c.Meta.FlagSet("help", FlagSetDefault)
flags.Usage = func() { c.Ui.Error(c.Help()) } flags.Usage = func() { c.Ui.Error(c.Help()) }
if err := flags.Parse(args); err != nil { if err := flags.Parse(args); err != nil {
@@ -35,8 +35,15 @@ func (c *HelpCommand) Run(args []string) int {
help, err := client.Help(path) help, err := client.Help(path)
if err != nil { if err != nil {
c.Ui.Error(fmt.Sprintf( if strings.Contains(err.Error(), "Vault is sealed") {
"Error reading help: %s", err)) 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 return 1
} }
@@ -44,13 +51,13 @@ func (c *HelpCommand) Run(args []string) int {
return 0 return 0
} }
func (c *HelpCommand) Synopsis() string { func (c *PathHelpCommand) Synopsis() string {
return "Look up the help for a path" return "Look up the help for a path"
} }
func (c *HelpCommand) Help() string { func (c *PathHelpCommand) Help() string {
helpText := ` helpText := `
Usage: vault help [options] path Usage: vault path-help [options] path
Look up the help for a 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 providers provide built-in help. This command looks up and outputs that
help. help.
The command requires that the Vault be unsealed, because otherwise
the mount points of the backends are unknown.
General Options: General Options:
-address=addr The address of the Vault server. -address=addr The address of the Vault server.

View File

@@ -14,7 +14,7 @@ func TestHelp(t *testing.T) {
defer ln.Close() defer ln.Close()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &HelpCommand{ c := &PathHelpCommand{
Meta: Meta{ Meta: Meta{
ClientToken: token, ClientToken: token,
Ui: ui, Ui: ui,