cli: support `json` and `t` on `acl binding-rule info` command. (#16357)

This commit is contained in:
James Rasell 2023-03-07 18:27:02 +01:00 committed by GitHub
parent 966c4b1a2d
commit 7507c92139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

3
.changelog/16357.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
cli: Fixed a bug where the `-json` and `-t` flags were not respected on the `acl binding-rule info` command
```

View File

@ -95,6 +95,17 @@ func (a *ACLBindingRuleInfoCommand) Run(args []string) int {
return 1 return 1
} }
if a.json || len(a.tmpl) > 0 {
out, err := Format(a.json, a.tmpl, aclBindingRule)
if err != nil {
a.Ui.Error(err.Error())
return 1
}
a.Ui.Output(out)
return 0
}
// Format the output. // Format the output.
a.Ui.Output(formatACLBindingRule(aclBindingRule)) a.Ui.Output(formatACLBindingRule(aclBindingRule))
return 0 return 0

View File

@ -1,6 +1,7 @@
package command package command
import ( import (
"fmt"
"testing" "testing"
"github.com/hashicorp/nomad/ci" "github.com/hashicorp/nomad/ci"
@ -68,4 +69,22 @@ func TestACLBindingRuleInfoCommand_Run(t *testing.T) {
ui.OutputWriter.Reset() ui.OutputWriter.Reset()
ui.ErrorWriter.Reset() ui.ErrorWriter.Reset()
// Test that the JSON flag works in return a string that has JSON markers.
must.Eq(t, 0, cmd.Run([]string{"-address=" + url, "-token=" + rootACLToken.SecretID, "-json", aclBindingRule.ID}))
s = ui.OutputWriter.String()
must.StrContains(t, s, "{")
must.StrContains(t, s, "}")
ui.OutputWriter.Reset()
ui.ErrorWriter.Reset()
// Test that we can pass in a custom go template to format the output.
must.Eq(t, 0, cmd.Run([]string{
"-address=" + url, "-token=" + rootACLToken.SecretID, "-t", "Custom: {{ .ID }}", aclBindingRule.ID}))
s = ui.OutputWriter.String()
must.StrContains(t, s, fmt.Sprintf("Custom: %s", aclBindingRule.ID))
ui.OutputWriter.Reset()
ui.ErrorWriter.Reset()
} }