Skip to content

Commit d1a9302

Browse files
authored
Merge pull request #10822 from hashicorp/b-gh-10820
cli: fixed system commands so they correctly use passed flags.
2 parents 7edf0cc + 2e5f30b commit d1a9302

4 files changed

+24
-2
lines changed

command/system_gc.go

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ func (c *SystemGCCommand) AutocompleteArgs() complete.Predictor {
4040
func (c *SystemGCCommand) Name() string { return "system gc" }
4141

4242
func (c *SystemGCCommand) Run(args []string) int {
43+
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
44+
flags.Usage = func() { c.Ui.Output(c.Help()) }
45+
46+
if err := flags.Parse(args); err != nil {
47+
return 1
48+
}
49+
50+
if args = flags.Args(); len(args) > 0 {
51+
c.Ui.Error("This command takes no arguments")
52+
c.Ui.Error(commandErrorText(c))
53+
}
4354

4455
// Get the HTTP client
4556
client, err := c.Meta.Client()

command/system_gc_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestSystemGCCommand_Good(t *testing.T) {
1919
defer srv.Shutdown()
2020

2121
ui := cli.NewMockUi()
22-
cmd := &SystemGCCommand{Meta: Meta{Ui: ui, flagAddress: url}}
22+
cmd := &SystemGCCommand{Meta: Meta{Ui: ui}}
2323

2424
if code := cmd.Run([]string{"-address=" + url}); code != 0 {
2525
t.Fatalf("expected exit 0, got: %d; %v", code, ui.ErrorWriter.String())

command/system_reconcile_summaries.go

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ func (c *SystemReconcileSummariesCommand) AutocompleteArgs() complete.Predictor
4040
func (c *SystemReconcileSummariesCommand) Name() string { return "system reconcile summaries" }
4141

4242
func (c *SystemReconcileSummariesCommand) Run(args []string) int {
43+
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
44+
flags.Usage = func() { c.Ui.Output(c.Help()) }
45+
46+
if err := flags.Parse(args); err != nil {
47+
return 1
48+
}
49+
50+
if args = flags.Args(); len(args) > 0 {
51+
c.Ui.Error("This command takes no arguments")
52+
c.Ui.Error(commandErrorText(c))
53+
}
4354

4455
// Get the HTTP client
4556
client, err := c.Meta.Client()

command/system_reconcile_summaries_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestSystemReconcileSummariesCommand_Good(t *testing.T) {
1919
defer srv.Shutdown()
2020

2121
ui := cli.NewMockUi()
22-
cmd := &SystemReconcileSummariesCommand{Meta: Meta{Ui: ui, flagAddress: url}}
22+
cmd := &SystemReconcileSummariesCommand{Meta: Meta{Ui: ui}}
2323

2424
if code := cmd.Run([]string{"-address=" + url}); code != 0 {
2525
t.Fatalf("expected exit 0, got: %d; %v", code, ui.ErrorWriter.String())

0 commit comments

Comments
 (0)