From 3127ce320c6456c31e171b0d39828b360b5660f1 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 19 Jul 2017 11:28:16 -0700 Subject: [PATCH 1/2] Agent command autocompletes to hcl/json files --- command/agent/command.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/command/agent/command.go b/command/agent/command.go index df47de38c..c6108df4d 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -27,6 +27,7 @@ import ( "github.com/hashicorp/nomad/nomad/structs/config" "github.com/hashicorp/scada-client/scada" "github.com/mitchellh/cli" + "github.com/posener/complete" ) // gracefulTimeout controls how long we wait before forcefully terminating @@ -408,6 +409,14 @@ func (c *Command) checkpointResults(results *checkpoint.CheckResponse, err error } } +func (c *Command) AutocompleteFlags() complete.Flags { + return nil +} + +func (c *Command) AutocompleteArgs() complete.Predictor { + return complete.PredictOr(complete.PredictFiles("*.json"), complete.PredictFiles("*.hcl")) +} + func (c *Command) Run(args []string) int { c.Ui = &cli.PrefixedUi{ OutputPrefix: "==> ", From 8a371e0bd4ce13774e9e5c483c37870cc2bf641b Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 19 Jul 2017 11:51:01 -0700 Subject: [PATCH 2/2] Fix predictor --- command/agent/command.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/command/agent/command.go b/command/agent/command.go index c6108df4d..4e1c9e760 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -410,11 +410,17 @@ func (c *Command) checkpointResults(results *checkpoint.CheckResponse, err error } func (c *Command) AutocompleteFlags() complete.Flags { - return nil + configFilePredictor := complete.PredictOr( + complete.PredictFiles("*.json"), + complete.PredictFiles("*.hcl")) + + return map[string]complete.Predictor{ + "-config": configFilePredictor, + } } func (c *Command) AutocompleteArgs() complete.Predictor { - return complete.PredictOr(complete.PredictFiles("*.json"), complete.PredictFiles("*.hcl")) + return nil } func (c *Command) Run(args []string) int {