diff --git a/api/help.go b/api/help.go index 472ca0395ead..321bd597c1a2 100644 --- a/api/help.go +++ b/api/help.go @@ -24,6 +24,7 @@ func (c *Client) Help(path string) (*Help, error) { } type Help struct { - Help string `json:"help"` - SeeAlso []string `json:"see_also"` + Help string `json:"help"` + SeeAlso []string `json:"see_also"` + OpenAPI map[string]interface{} `json:"openapi"` } diff --git a/command/path_help.go b/command/path_help.go index 2ce4a38bfd42..d50fe8eab427 100644 --- a/command/path_help.go +++ b/command/path_help.go @@ -1,6 +1,7 @@ package command import ( + "encoding/json" "fmt" "strings" @@ -44,13 +45,15 @@ Usage: vault path-help [options] PATH Each secret engine produces different help output. + If -format is specified as JSON, the output will be in OpenAPI format. + ` + c.Flags().Help() return strings.TrimSpace(helpText) } func (c *PathHelpCommand) Flags() *FlagSets { - return c.flagSet(FlagSetHTTP) + return c.flagSet(FlagSetHTTP | FlagSetOutputFormat) } func (c *PathHelpCommand) AutocompleteArgs() complete.Predictor { @@ -97,6 +100,17 @@ func (c *PathHelpCommand) Run(args []string) int { return 2 } - c.UI.Output(help.Help) + switch c.flagFormat { + case "json": + b, err := json.Marshal(help.OpenAPI) + if err != nil { + c.UI.Error(fmt.Sprintf("Error marshaling OpenAPI: %s", err)) + return 2 + } + c.UI.Output(string(b)) + default: + c.UI.Output(help.Help) + } + return 0 }