mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
fix autocomplete to list all matches
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user