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 e2b0f5dae8
commit c54868120a
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
},
"help": func() (cli.Command, error) {
return &command.HelpCommand{
"path-help": func() (cli.Command, error) {
return &command.PathHelpCommand{
Meta: meta,
}, nil
},

View File

@ -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.

View File

@ -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,