Skip to content

Commit

Permalink
Add a deprecated helper to tokenutil and JSON output to path-help (#7006
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jefferai authored Jun 27, 2019
1 parent 0a58f30 commit fe636fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions api/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
18 changes: 16 additions & 2 deletions command/path_help.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
"encoding/json"
"fmt"
"strings"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit fe636fb

Please sign in to comment.