Add a deprecated helper to tokenutil and JSON output to path-help (#7006)

This commit is contained in:
Jeff Mitchell 2019-06-27 12:56:31 -04:00 committed by GitHub
parent ce9f8a72b6
commit 346a31fddf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -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"`
}

View File

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