Autocomplete deployment commands

This commit is contained in:
Alex Dadgar
2017-08-22 13:05:24 -07:00
parent 5addfc97b4
commit 3ae8ecb32f
11 changed files with 284 additions and 5 deletions

View File

@@ -3,6 +3,9 @@ package command
import (
"fmt"
"strings"
"github.com/hashicorp/nomad/api/contexts"
"github.com/posener/complete"
)
type DeploymentPauseCommand struct {
@@ -32,6 +35,25 @@ func (c *DeploymentPauseCommand) Synopsis() string {
return "Pause a deployment"
}
func (c *DeploymentPauseCommand) AutocompleteFlags() complete.Flags {
return nil
}
func (c *DeploymentPauseCommand) 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.Deployments)
if err != nil {
return []string{}
}
return resp.Matches[contexts.Deployments]
})
}
func (c *DeploymentPauseCommand) Run(args []string) int {
var verbose bool