grim/convey

Overhaul sub commands. Fixes #153

2018-01-07, Gary Kramlich
5fcab33ba2d8
Parents 1c49440fd1b7
Children 0d70a7778862
Overhaul sub commands. Fixes #153
--- a/ChangeLog Sun Jan 07 04:25:00 2018 -0600
+++ b/ChangeLog Sun Jan 07 22:06:42 2018 -0600
@@ -1,5 +1,13 @@
0.12.1dev:
- * Nothing yet! Be the first!!
+ * Changed the way subcommands are run. Fixed #153
+ * Added `run` sub-command.
+ * Deprecated `--graphviz`, use `graphviz` instead.
+ * Deprecated `--list-environment`, use `list environment` instead.
+ * Deprecated `--list-plans`, use `list plans` instead.
+ * Deprecated `--list-meta-plans`, use `list metaplans` instead.
+ * Deprecated `--list-tasks`, use `list tasks` instead.
+ * Deprecated `--show-config`, use `config` instead.
+ * Renamed `--allow-deprecated` to `--disable-deprecated`.
0.12.0: 20180107
* Deprecated engine attribute, and changed type attribute to be {engine}/{type}. Warnings will be output if legacy formats are detected. Fixed # 143
--- a/config/loader.go Sun Jan 07 04:25:00 2018 -0600
+++ b/config/loader.go Sun Jan 07 22:06:42 2018 -0600
@@ -28,8 +28,8 @@
)
type Loader interface {
- Load(path, base string, data []byte, allowDeprecated bool) (*Config, error)
- LoadOverride(path, base string, data []byte, config *Config, allowDeprecated bool)
+ Load(path, base string, data []byte, disableDeprecated bool) (*Config, error)
+ LoadOverride(path, base string, data []byte, config *Config, disableDeprecated bool)
Filenames() []string
OverrideSuffix() string
DefaultPlan() string
@@ -43,7 +43,7 @@
return base + loader.OverrideSuffix() + ext
}
-func loadOverride(path, base string, loader Loader, cfg *Config, allowDeprecated bool) {
+func loadOverride(path, base string, loader Loader, cfg *Config, disableDeprecated bool) {
overrideFilename := determineFilename(base, loader)
absName := filepath.Join(path, overrideFilename)
@@ -58,10 +58,10 @@
return
}
- loader.LoadOverride(path, base, data, cfg, allowDeprecated)
+ loader.LoadOverride(path, base, data, cfg, disableDeprecated)
}
-func LoadFile(file string, loader Loader, allowDeprecated bool) (*Config, error) {
+func LoadFile(file string, loader Loader, disableDeprecated bool) (*Config, error) {
// split the filename into our parts
path, base := filepath.Split(file)
@@ -70,12 +70,12 @@
return nil, fmt.Errorf("failed to read config file '%s'", file)
}
- cfg, err := loader.Load(path, base, data, allowDeprecated)
+ cfg, err := loader.Load(path, base, data, disableDeprecated)
if err != nil {
return cfg, err
}
- loadOverride(path, base, loader, cfg, allowDeprecated)
+ loadOverride(path, base, loader, cfg, disableDeprecated)
return cfg, nil
}
--- a/config/override_test.go Sun Jan 07 04:25:00 2018 -0600
+++ b/config/override_test.go Sun Jan 07 22:06:42 2018 -0600
@@ -26,11 +26,11 @@
type testLoader struct{}
-func (l *testLoader) Load(path, base string, data []byte, allowDeprecated bool) (*Config, error) {
+func (l *testLoader) Load(path, base string, data []byte, disableDeprecated bool) (*Config, error) {
return nil, nil
}
-func (l *testLoader) LoadOverride(path, base string, data []byte, cfg *Config, allowDeprecated bool) {
+func (l *testLoader) LoadOverride(path, base string, data []byte, cfg *Config, disableDeprecated bool) {
}
func (l *testLoader) OverrideSuffix() string {
--- a/loaders/bitbucket/loader.go Sun Jan 07 04:25:00 2018 -0600
+++ b/loaders/bitbucket/loader.go Sun Jan 07 22:06:42 2018 -0600
@@ -172,7 +172,7 @@
return nil
}
-func (l *Loader) Load(base, path string, data []byte, allowDeprecated bool) (*config.Config, error) {
+func (l *Loader) Load(base, path string, data []byte, disableDeprecated bool) (*config.Config, error) {
var pipeline bitbucketPipelines
err := yaml.Unmarshal(data, &pipeline)
if err != nil {
@@ -236,7 +236,7 @@
return cfg, nil
}
-func (l *Loader) LoadOverride(base, path string, data []byte, cfg *config.Config, allowDeprecated bool) {
+func (l *Loader) LoadOverride(base, path string, data []byte, cfg *config.Config, disableDeprecated bool) {
return
}
--- a/loaders/convey/convey.go Sun Jan 07 04:25:00 2018 -0600
+++ b/loaders/convey/convey.go Sun Jan 07 22:06:42 2018 -0600
@@ -62,7 +62,7 @@
fileLoader func(string, *Loader) (*cConfig.Config, error)
}
-func (c *Loader) Load(path, base string, data []byte, allowDeprecated bool) (*cConfig.Config, error) {
+func (c *Loader) Load(path, base string, data []byte, disableDeprecated bool) (*cConfig.Config, error) {
if c.logger == nil {
c.logger = logging.NewAdapter("config loader")
}
@@ -88,7 +88,7 @@
extendsAbsName := filepath.Join(path, cfg.Extends)
c.depth++
- baseConfig, err = c.loadFile(extendsAbsName, allowDeprecated)
+ baseConfig, err = c.loadFile(extendsAbsName, disableDeprecated)
c.depth--
// We can safely ignore no plans and no tasks errors here
@@ -108,7 +108,7 @@
}
// turn the raw tasks into real tasks
- realTasks, err := loadTasks(path, cfg.Tasks, c.logger)
+ realTasks, err := loadTasks(path, cfg.Tasks, c.logger, disableDeprecated)
if err != nil {
return nil, err
}
@@ -271,15 +271,15 @@
return nil
}
-func (c *Loader) loadFile(path string, allowDeprecated bool) (*cConfig.Config, error) {
+func (c *Loader) loadFile(path string, disableDeprecated bool) (*cConfig.Config, error) {
if c.fileLoader == nil {
- return cConfig.LoadFile(path, c, allowDeprecated)
+ return cConfig.LoadFile(path, c, disableDeprecated)
}
return c.fileLoader(path, c)
}
-func (c *Loader) LoadOverride(path, base string, data []byte, config *cConfig.Config, allowDeprecated bool) {
+func (c *Loader) LoadOverride(path, base string, data []byte, config *cConfig.Config, disableDeprecated bool) {
var overrideData override
err := yaml.Unmarshal(data, &overrideData)
--- a/loaders/convey/tasks.go Sun Jan 07 04:25:00 2018 -0600
+++ b/loaders/convey/tasks.go Sun Jan 07 22:06:42 2018 -0600
@@ -58,7 +58,7 @@
return task, nil
}
-func loadTask(name string, yamlTask yaml.MapSlice, logger *gomol.LogAdapter) (tasks.Task, error) {
+func loadTask(name string, yamlTask yaml.MapSlice, logger *gomol.LogAdapter, disableDeprecated bool) (tasks.Task, error) {
// figure out the engine and type for the task
var (
rawEngine string
@@ -78,8 +78,14 @@
}
task, ok := cConfig.TasksMap[rawType]
- // if the task is in the new format, we're done
+ // if the task isn't in the new format try to lookup the old format
if !ok {
+ // TODO remove when the old format for task types is removed.
+ // if deprecated tasks are disabled, just bomb out
+ if disableDeprecated {
+ return nil, fmt.Errorf("task '%s' not found", rawType)
+ }
+
rawTask, err := loadLegacyTask(rawEngine, rawType, logger)
if err != nil {
return nil, err
@@ -101,11 +107,11 @@
return realTask, nil
}
-func loadTasks(path string, raw map[string]yaml.MapSlice, logger *gomol.LogAdapter) (map[string]tasks.Task, error) {
+func loadTasks(path string, raw map[string]yaml.MapSlice, logger *gomol.LogAdapter, disableDeprecated bool) (map[string]tasks.Task, error) {
realTasks := map[string]tasks.Task{}
for name, task := range raw {
- realTask, err := loadTask(name, task, logger)
+ realTask, err := loadTask(name, task, logger, disableDeprecated)
if err != nil {
return nil, err
}
--- a/main.go Sun Jan 07 04:25:00 2018 -0600
+++ b/main.go Sun Jan 07 22:06:42 2018 -0600
@@ -45,34 +45,45 @@
var (
app = kingpin.New("convey", "container runner").Version(version)
- color = app.Flag("color", "Enable colorized output").Default("true").Bool()
- configLoader = app.Flag("config-loader", "Select the configuration loader").Short('l').Default("convey").Enum("convey", "bitbucket")
- configFile = app.Flag("config", "The config file name to use").Short('f').String()
- cpuShares = app.Flag("cpu-shares", "The amount of cpu shares to give to a run task").Short('c').String()
- dockerConfig = app.Flag("docker-config", "Location of docker client config files").String()
- env = app.Flag("env", "Set environment variables").Short('e').Strings()
- forceSequential = app.Flag("force-sequential", "Don't run anything concurrently").Short('S').Default("False").Bool()
- graphviz = app.Flag("graphviz", "Output a graphviz diagram of the config file").Short('g').Default("False").Bool()
- keep = app.Flag("keep", "Keep the workspace volume").Short('k').Hidden().Default("False").Bool()
- listEnvironment = app.Flag("list-environment", "List the environment variables that are available").Short('E').Default("false").Bool()
- listMetaPlans = app.Flag("list-meta-plans", "List the meta plans that are available").Short('M').Default("false").Bool()
- listPlans = app.Flag("list-plans", "List the plans that are available").Short('P').Default("false").Bool()
- listTasks = app.Flag("list-tasks", "List the supported tasks").Short('L').Default("false").Bool()
- memory = app.Flag("memory", "The amount of memory to give the run task").Short('m').String()
- showConfig = app.Flag("show-config", "Show a dump of the config file").Short('C').Hidden().Default("false").Bool()
- sshAgent = app.Flag("ssh-agent", "A shortcut for --ssh-identity=*").Default("false").Bool()
- sshIdentities = app.Flag("ssh-identity", "Enable ssh-agent for the given identities").Strings()
- planTimeout = app.Flag("timeout", "The maximum amount of time a plan can run. 0 to disable. Units must be specified.").Default("15m").Duration()
- verbose = app.Flag("verbose", "Be more verbose").Short('v').Default("False").Bool()
- allowDeprecated = app.Flag("allow-deprecated", "Allow the user of deprecated features").Default("False").Bool()
+ color = app.Flag("color", "Enable colorized output").Default("true").Bool()
+ configLoader = app.Flag("config-loader", "Select the configuration loader").Short('l').Default("convey").Enum("convey", "bitbucket")
+ configFile = app.Flag("config", "The config file name to use").Short('f').String()
+ cpuShares = app.Flag("cpu-shares", "The amount of cpu shares to give to a run task").Short('c').String()
+ dockerConfig = app.Flag("docker-config", "Location of docker client config files").String()
+ env = app.Flag("env", "Set environment variables").Short('e').Strings()
+ forceSequential = app.Flag("force-sequential", "Don't run anything concurrently").Short('S').Default("False").Bool()
+ graphviz = app.Flag("graphviz", "Output a graphviz diagram of the config file").Short('g').Hidden().Default("False").Bool()
+ keep = app.Flag("keep", "Keep the workspace volume").Short('k').Hidden().Default("False").Bool()
+ listEnvironment = app.Flag("list-environment", "List the environment variables that are available").Short('E').Hidden().Default("false").Bool()
+ listMetaPlans = app.Flag("list-meta-plans", "List the meta plans that are available").Short('M').Hidden().Default("false").Bool()
+ listPlans = app.Flag("list-plans", "List the plans that are available").Short('P').Hidden().Default("false").Bool()
+ listTasks = app.Flag("list-tasks", "List the supported tasks").Short('L').Hidden().Default("false").Bool()
+ memory = app.Flag("memory", "The amount of memory to give the run task").Short('m').String()
+ showConfig = app.Flag("show-config", "Show a dump of the config file").Short('C').Hidden().Default("false").Bool()
+ sshAgent = app.Flag("ssh-agent", "A shortcut for --ssh-identity=*").Default("false").Bool()
+ sshIdentities = app.Flag("ssh-identity", "Enable ssh-agent for the given identities").Strings()
+ planTimeout = app.Flag("timeout", "The maximum amount of time a plan can run. 0 to disable. Units must be specified.").Default("15m").Duration()
+ verbose = app.Flag("verbose", "Be more verbose").Short('v').Default("False").Bool()
+ disableDeprecated = app.Flag("disable-deprecated", "Allow the user of deprecated features").Default("False").Bool()
- planNames = app.Arg("plan", "The plan or list of plans to run in specified order").Default("default").Strings()
+ _ = app.Command("config", "Show a dump of the config file")
+ _ = app.Command("environment", "List the environment variables that are available")
+ _ = app.Command("graphviz", "Output a graphviz diagram of the config file")
+
+ run = app.Command("run", "Run a plan or metaplan").Default()
+ planNames = run.Arg("plan", "The plan or list of plans to run in specified order").Default("default").Strings()
+
+ ls = app.Command("list", "List information").Alias("ls")
+ _ = ls.Command("environment", "List environment").Alias("env")
+ _ = ls.Command("metaplans", "List metaplans")
+ _ = ls.Command("plans", "List plans")
+ _ = ls.Command("tasks", "List tasks")
)
func gomain() int {
args := os.Args[1:]
- _, err := app.Parse(args)
+ command, err := app.Parse(args)
if err != nil {
app.Usage(args)
return 1
@@ -119,7 +130,7 @@
return 1
}
- cfg, err := config.LoadFile(*configFile, loader, *allowDeprecated)
+ cfg, err := config.LoadFile(*configFile, loader, *disableDeprecated)
if err != nil {
fmt.Printf("%s\n", err)
return 1
@@ -154,7 +165,7 @@
st.CfgPath = cfgPath
st.CleanupList = cleanupList
st.KeepWorkspace = *keep
- st.AllowDeprecated = *allowDeprecated
+ st.DisableDeprecated = *disableDeprecated
st.ForceSequential = *forceSequential
st.EnableSSHAgent = enableSSHAgent
st.PlanTimeout = *planTimeout
@@ -169,20 +180,53 @@
return 1
}
+ if *graphviz {
+ if *disableDeprecated {
+ fmt.Printf("--graphviz is deprecated, use 'convey graphviz` instead")
+ command = "graphviz"
+ }
+ } else if *listEnvironment {
+ if *disableDeprecated {
+ fmt.Printf("--list-environment is deprecated, use 'convey list environment` instead")
+ command = "list environment"
+ }
+ } else if *listMetaPlans {
+ if *disableDeprecated {
+ fmt.Printf("--list-metaplans is deprecated, use `convey list metaplans` instead")
+ command = "list metaplans"
+ }
+ } else if *listPlans {
+ if *disableDeprecated {
+ fmt.Printf("--list-plans is deprecated, use `convey list plans` instead")
+ command = "list plans"
+ }
+ } else if *listTasks {
+ if *disableDeprecated {
+ fmt.Printf("--list-tasks is deprecated, use `convey list tasks` instead")
+ command = "list tasks"
+ }
+ } else if *showConfig {
+ if *disableDeprecated {
+ fmt.Printf("--list-plans is deprecated, use `convey config` instead")
+ command = "config"
+ }
+ }
+
var runner runners.Runner
- if *graphviz {
+ switch command {
+ case "graphviz":
runner = &runners.Graphviz{}
- } else if *listEnvironment {
+ case "list environment":
runner = &runners.ListEnvironment{}
- } else if *listMetaPlans {
+ case "list metaplans":
runner = &runners.ListMetaPlans{}
- } else if *listPlans {
+ case "list plans":
runner = &runners.ListPlans{}
- } else if *listTasks {
+ case "list tasks":
runner = &runners.ListTasks{}
- } else if *showConfig {
+ case "config":
runner = &runners.ShowConfig{}
- } else {
+ default:
runner = &runners.Default{}
}
--- a/state/state.go Sun Jan 07 04:25:00 2018 -0600
+++ b/state/state.go Sun Jan 07 22:06:42 2018 -0600
@@ -39,10 +39,10 @@
Workspace workspace.Workspace
KeepWorkspace bool
- AllowDeprecated bool
- ForceSequential bool
- EnableSSHAgent bool
- PlanTimeout time.Duration
+ DisableDeprecated bool
+ ForceSequential bool
+ EnableSSHAgent bool
+ PlanTimeout time.Duration
DockerConfig string
CPUShares string