Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: add json and template flag opts to acl bootstrap command. #11411

Merged
merged 3 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11411.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
cli: added json and template flag opts to the acl bootstrap command
```
32 changes: 31 additions & 1 deletion command/acl_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,24 @@ General Options:

` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `

Bootstrap Options:

-json
Output the bootstrap response in JSON format.

-t
Format and display the bootstrap response using a Go template.

`
return strings.TrimSpace(helpText)
}

func (c *ACLBootstrapCommand) AutocompleteFlags() complete.Flags {
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
complete.Flags{})
complete.Flags{
"-json": complete.PredictNothing,
"-t": complete.PredictAnything,
})
}

func (c *ACLBootstrapCommand) AutocompleteArgs() complete.Predictor {
Expand All @@ -42,8 +53,16 @@ func (c *ACLBootstrapCommand) Synopsis() string {
func (c *ACLBootstrapCommand) Name() string { return "acl bootstrap" }

func (c *ACLBootstrapCommand) Run(args []string) int {

var (
json bool
tmpl string
)

flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&json, "json", false, "")
flags.StringVar(&tmpl, "t", "", "")
if err := flags.Parse(args); err != nil {
return 1
}
Expand All @@ -70,6 +89,17 @@ func (c *ACLBootstrapCommand) Run(args []string) int {
return 1
}

if json || len(tmpl) > 0 {
out, err := Format(json, tmpl, token)
if err != nil {
c.Ui.Error(err.Error())
return 1
}

c.Ui.Output(out)
return 0
}

// Format the output
c.Ui.Output(formatKVACLToken(token))
return 0
Expand Down
5 changes: 5 additions & 0 deletions website/content/docs/commands/acl/bootstrap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ The `acl bootstrap` command requires no arguments.

@include 'general_options_no_namespace.mdx'

## Bootstrap Options

- `-json` : Output the bootstrap response in JSON format.
- `-t` : Format and display the deployments using a Go template.

## Examples

Bootstrap the initial token:
Expand Down