Skip to content

Commit

Permalink
Merge pull request #10822 from hashicorp/b-gh-10820
Browse files Browse the repository at this point in the history
cli: fixed system commands so they correctly use passed flags.
  • Loading branch information
jrasell authored Jun 29, 2021
2 parents 7edf0cc + 2e5f30b commit d1a9302
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
11 changes: 11 additions & 0 deletions command/system_gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ func (c *SystemGCCommand) AutocompleteArgs() complete.Predictor {
func (c *SystemGCCommand) Name() string { return "system gc" }

func (c *SystemGCCommand) Run(args []string) int {
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
return 1
}

if args = flags.Args(); len(args) > 0 {
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
}

// Get the HTTP client
client, err := c.Meta.Client()
Expand Down
2 changes: 1 addition & 1 deletion command/system_gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestSystemGCCommand_Good(t *testing.T) {
defer srv.Shutdown()

ui := cli.NewMockUi()
cmd := &SystemGCCommand{Meta: Meta{Ui: ui, flagAddress: url}}
cmd := &SystemGCCommand{Meta: Meta{Ui: ui}}

if code := cmd.Run([]string{"-address=" + url}); code != 0 {
t.Fatalf("expected exit 0, got: %d; %v", code, ui.ErrorWriter.String())
Expand Down
11 changes: 11 additions & 0 deletions command/system_reconcile_summaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ func (c *SystemReconcileSummariesCommand) AutocompleteArgs() complete.Predictor
func (c *SystemReconcileSummariesCommand) Name() string { return "system reconcile summaries" }

func (c *SystemReconcileSummariesCommand) Run(args []string) int {
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
return 1
}

if args = flags.Args(); len(args) > 0 {
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
}

// Get the HTTP client
client, err := c.Meta.Client()
Expand Down
2 changes: 1 addition & 1 deletion command/system_reconcile_summaries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestSystemReconcileSummariesCommand_Good(t *testing.T) {
defer srv.Shutdown()

ui := cli.NewMockUi()
cmd := &SystemReconcileSummariesCommand{Meta: Meta{Ui: ui, flagAddress: url}}
cmd := &SystemReconcileSummariesCommand{Meta: Meta{Ui: ui}}

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

0 comments on commit d1a9302

Please sign in to comment.