diff --git a/command/meta.go b/command/meta.go index e269ce346..cf32eeeb4 100644 --- a/command/meta.go +++ b/command/meta.go @@ -56,18 +56,6 @@ type Meta struct { insecure bool } -func (m *Meta) Copy(dest *Meta) { - dest.Ui = m.Ui - dest.flagAddress = m.flagAddress - dest.noColor = m.noColor - dest.region = m.region - dest.caCert = m.caCert - dest.caPath = m.caPath - dest.clientCert = m.clientCert - dest.clientKey = m.clientKey - dest.insecure = m.insecure -} - // FlagSet returns a FlagSet with the common flags that every // command implements. The exact behavior of FlagSet can be configured // using the flags as the second parameter, for example to disable diff --git a/command/status.go b/command/status.go index 6d7ef90bd..c44b8e973 100644 --- a/command/status.go +++ b/command/status.go @@ -109,7 +109,20 @@ func (s *StatusCommand) AutocompleteArgs() complete.Predictor { if err != nil { return []string{} } - return resp.Matches[contexts.All] + + final := make([]string, 0) + + for _, matches := range resp.Matches { + if len(matches) == 0 { + continue + } + + for _, id := range matches { + final = append(final, id) + } + } + + return final }) } diff --git a/command/status_test.go b/command/status_test.go index 48f3eea6d..17bae48e3 100644 --- a/command/status_test.go +++ b/command/status_test.go @@ -9,6 +9,8 @@ import ( "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" "github.com/mitchellh/cli" + "github.com/posener/complete" + "github.com/stretchr/testify/assert" ) func TestStatusCommand_Run_JobStatus(t *testing.T) { @@ -212,3 +214,31 @@ func TestStatusCommand_Run_NoPrefix(t *testing.T) { ui.OutputWriter.Reset() } + +func TestStatusCommand_AutocompleteArgs(t *testing.T) { + assert := assert.New(t) + t.Parallel() + + srv, client, url := testServer(t, true, nil) + defer srv.Shutdown() + + ui := new(cli.MockUi) + cmd := &StatusCommand{Meta: Meta{Ui: ui, flagAddress: url}} + + jobID := "job1_sfx" + job1 := testJob(jobID) + resp, _, err := client.Jobs().Register(job1, nil) + if err != nil { + t.Fatalf("err: %s", err) + } + if code := waitForSuccess(ui, client, fullId, t, resp.EvalID); code != 0 { + t.Fatalf("status code non zero saw %d", code) + } + + prefix := jobID[:len(jobID)-5] + args := complete.Args{Last: prefix} + predictor := cmd.AutocompleteArgs() + + res := predictor.Predict(args) + assert.Contains(res, jobID) +}