mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 09:55:44 +03:00
inspect
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/api/contexts"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
type InspectCommand struct {
|
||||
@@ -39,6 +41,25 @@ func (c *InspectCommand) Synopsis() string {
|
||||
return "Inspect a submitted job"
|
||||
}
|
||||
|
||||
func (c *InspectCommand) AutocompleteFlags() complete.Flags {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *InspectCommand) AutocompleteArgs() complete.Predictor {
|
||||
client, _ := c.Meta.Client()
|
||||
return complete.PredictFunc(func(a complete.Args) []string {
|
||||
if len(a.Completed) > 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
resp, err := client.Search().PrefixSearch(a.Last, contexts.Jobs)
|
||||
if err != nil {
|
||||
return []string{}
|
||||
}
|
||||
return resp.Matches[contexts.Jobs]
|
||||
})
|
||||
}
|
||||
|
||||
func (c *InspectCommand) Run(args []string) int {
|
||||
var json bool
|
||||
var tmpl, versionStr string
|
||||
|
||||
@@ -4,7 +4,10 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/nomad/mock"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/posener/complete"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestInspectCommand_Implements(t *testing.T) {
|
||||
@@ -55,3 +58,33 @@ func TestInspectCommand_Fails(t *testing.T) {
|
||||
t.Fatalf("expected getting formatter error, got: %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInspectCommand_AutocompleteArgs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
t.Parallel()
|
||||
|
||||
srv, _, url := testServer(t, true, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &JobStatusCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||
|
||||
state := srv.Agent.Server().State()
|
||||
j := mock.Job()
|
||||
assert.Nil(state.UpsertJob(1000, j))
|
||||
|
||||
prefix := j.ID[:len(j.ID)-5]
|
||||
args := complete.Args{Last: prefix}
|
||||
predictor := cmd.AutocompleteArgs()
|
||||
|
||||
res := predictor.Predict(args)
|
||||
assert.Equal(1, len(res))
|
||||
assert.Equal(j.ID, res[0])
|
||||
|
||||
// Autocomplete should only complete once
|
||||
args = complete.Args{Last: prefix, Completed: []string{prefix, "a", "b"}}
|
||||
predictor = cmd.AutocompleteArgs()
|
||||
|
||||
res = predictor.Predict(args)
|
||||
assert.Nil(res)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user