flesh out the rest of the job subcommands
This commit is contained in:
parent
b41be1f85b
commit
f79c14ac4c
|
@ -3,6 +3,9 @@ package command
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/nomad/api/contexts"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
type JobDeploymentsCommand struct {
|
||||
|
@ -40,6 +43,25 @@ func (c *JobDeploymentsCommand) Synopsis() string {
|
|||
return "List deployments for a job"
|
||||
}
|
||||
|
||||
func (c *JobDeploymentsCommand) AutocompleteFlags() complete.Flags {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *JobDeploymentsCommand) 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 *JobDeploymentsCommand) Run(args []string) int {
|
||||
var json, latest, verbose bool
|
||||
var tmpl 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 TestJobDeploymentsCommand_Implements(t *testing.T) {
|
||||
|
@ -34,3 +37,34 @@ func TestJobDeploymentsCommand_Fails(t *testing.T) {
|
|||
}
|
||||
ui.ErrorWriter.Reset()
|
||||
}
|
||||
|
||||
func TestJobDeploymentsCommand_AutocompleteArgs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
t.Parallel()
|
||||
|
||||
srv, _, url := testServer(t, true, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &JobDeploymentsCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||
|
||||
// Create a fake job
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/nomad/api/contexts"
|
||||
flaghelper "github.com/hashicorp/nomad/helper/flag-helpers"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
type JobDispatchCommand struct {
|
||||
|
@ -54,6 +56,25 @@ func (c *JobDispatchCommand) Synopsis() string {
|
|||
return "Dispatch an instance of a parameterized job"
|
||||
}
|
||||
|
||||
func (c *JobDispatchCommand) AutocompleteFlags() complete.Flags {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *JobDispatchCommand) 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 *JobDispatchCommand) Run(args []string) int {
|
||||
var detach, verbose bool
|
||||
var meta []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 TestJobDispatchCommand_Implements(t *testing.T) {
|
||||
|
@ -43,3 +46,34 @@ func TestJobDispatchCommand_Fails(t *testing.T) {
|
|||
}
|
||||
ui.ErrorWriter.Reset()
|
||||
}
|
||||
|
||||
func TestJobDispatchCommand_AutocompleteArgs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
t.Parallel()
|
||||
|
||||
srv, _, url := testServer(t, true, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &JobDispatchCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||
|
||||
// Create a fake job
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/api/contexts"
|
||||
"github.com/posener/complete"
|
||||
"github.com/ryanuber/columnize"
|
||||
)
|
||||
|
||||
|
@ -52,6 +54,25 @@ func (c *JobHistoryCommand) Synopsis() string {
|
|||
return "Display all tracked versions of a job"
|
||||
}
|
||||
|
||||
func (c *JobHistoryCommand) AutocompleteFlags() complete.Flags {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *JobHistoryCommand) 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 *JobHistoryCommand) Run(args []string) int {
|
||||
var json, diff, full 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 TestJobHistoryCommand_Implements(t *testing.T) {
|
||||
|
@ -34,3 +37,34 @@ func TestJobHistoryCommand_Fails(t *testing.T) {
|
|||
}
|
||||
ui.ErrorWriter.Reset()
|
||||
}
|
||||
|
||||
func TestJobHistoryCommand_AutocompleteArgs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
t.Parallel()
|
||||
|
||||
srv, _, url := testServer(t, true, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &JobHistoryCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||
|
||||
// Create a fake job
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/api/contexts"
|
||||
flaghelper "github.com/hashicorp/nomad/helper/flag-helpers"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
type JobPromoteCommand struct {
|
||||
|
@ -50,6 +52,25 @@ func (c *JobPromoteCommand) Synopsis() string {
|
|||
return "Promote a job's canaries"
|
||||
}
|
||||
|
||||
func (c *JobPromoteCommand) AutocompleteFlags() complete.Flags {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *JobPromoteCommand) 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 *JobPromoteCommand) Run(args []string) int {
|
||||
var detach, verbose bool
|
||||
var groups []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 TestJobPromoteCommand_Implements(t *testing.T) {
|
||||
|
@ -34,3 +37,34 @@ func TestJobPromoteCommand_Fails(t *testing.T) {
|
|||
}
|
||||
ui.ErrorWriter.Reset()
|
||||
}
|
||||
|
||||
func TestJobPromoteCommand_AutocompleteArgs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
t.Parallel()
|
||||
|
||||
srv, _, url := testServer(t, true, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &JobPromoteCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||
|
||||
// Create a fake job
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@ package command
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/nomad/api/contexts"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
type JobRevertCommand struct {
|
||||
|
@ -37,6 +40,25 @@ func (c *JobRevertCommand) Synopsis() string {
|
|||
return "Revert to a prior version of the job"
|
||||
}
|
||||
|
||||
func (c *JobRevertCommand) AutocompleteFlags() complete.Flags {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *JobRevertCommand) 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 *JobRevertCommand) Run(args []string) int {
|
||||
var detach, verbose bool
|
||||
|
||||
|
|
|
@ -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 TestJobRevertCommand_Implements(t *testing.T) {
|
||||
|
@ -34,3 +37,34 @@ func TestJobRevertCommand_Fails(t *testing.T) {
|
|||
}
|
||||
ui.ErrorWriter.Reset()
|
||||
}
|
||||
|
||||
func TestJobRevertCommand_AutocompleteArgs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
t.Parallel()
|
||||
|
||||
srv, _, url := testServer(t, true, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &JobRevertCommand{Meta: Meta{Ui: ui, flagAddress: url}}
|
||||
|
||||
// Create a fake job
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue