From 75266af3d3e95ec8517fb25af2d1f9e5720c890a Mon Sep 17 00:00:00 2001 From: Giacomo Tirabassi <21693524+gitirabassi@users.noreply.github.com> Date: Mon, 11 Feb 2019 20:19:08 +0100 Subject: [PATCH] remove panicking and added usage (#6208) --- command/commands.go | 5 +++++ command/print.go | 43 ++++++++++++++++++++++++++++++++++++++++++ command/print_token.go | 9 ++------- 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 command/print.go diff --git a/command/commands.go b/command/commands.go index 395b47a07e..c5bf984b40 100644 --- a/command/commands.go +++ b/command/commands.go @@ -425,6 +425,11 @@ func initCommands(ui, serverCmdUi cli.Ui, runOpts *RunOptions) { BaseCommand: getBaseCommand(), }, nil }, + "print": func() (cli.Command, error) { + return &PrintCommand{ + BaseCommand: getBaseCommand(), + }, nil + }, "print token": func() (cli.Command, error) { return &PrintTokenCommand{ BaseCommand: getBaseCommand(), diff --git a/command/print.go b/command/print.go new file mode 100644 index 0000000000..0ec6061a5a --- /dev/null +++ b/command/print.go @@ -0,0 +1,43 @@ +package command + +import ( + "strings" + + "github.com/mitchellh/cli" + "github.com/posener/complete" +) + +var _ cli.Command = (*PrintCommand)(nil) +var _ cli.CommandAutocomplete = (*PrintCommand)(nil) + +type PrintCommand struct { + *BaseCommand +} + +func (c *PrintCommand) Synopsis() string { + return "Prints runtime configurations" +} + +func (c *PrintCommand) Help() string { + helpText := ` +Usage: vault print + + This command groups subcommands for interacting with Vault's runtime values. + +Subcommands: + token Token currently in use +` + return strings.TrimSpace(helpText) +} + +func (c *PrintCommand) AutocompleteArgs() complete.Predictor { + return nil +} + +func (c *PrintCommand) AutocompleteFlags() complete.Flags { + return nil +} + +func (c *PrintCommand) Run(args []string) int { + return cli.RunResultHelp +} diff --git a/command/print_token.go b/command/print_token.go index a86d8bfa2a..d260fe8952 100644 --- a/command/print_token.go +++ b/command/print_token.go @@ -15,7 +15,7 @@ type PrintTokenCommand struct { } func (c *PrintTokenCommand) Synopsis() string { - return "Prints the contents of a policy" + return "Prints the vault token currenty in use" } func (c *PrintTokenCommand) Help() string { @@ -27,15 +27,10 @@ Usage: vault print token $ vault print token -` + c.Flags().Help() - +` return strings.TrimSpace(helpText) } -func (c *PrintTokenCommand) Flags() *FlagSets { - return nil -} - func (c *PrintTokenCommand) AutocompleteArgs() complete.Predictor { return nil }