--- a/main.go Sun Jan 14 04:39:16 2018 -0600
+++ b/main.go Sun Jan 14 05:12:00 2018 -0600
@@ -51,19 +51,21 @@
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()
+ disableDeprecated = app.Flag("disable-deprecated", "Allow the use of deprecated features").Default("False").Bool() + graphviz = app.Flag("graphviz", "Output a graphviz diagram of the config file").Short('g').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() + showConfig = app.Flag("show-config", "Show a dump of the config file").Short('C').Hidden().Default("false").Bool() _ = app.Command("config", "Show a dump of the config file")
@@ -82,6 +84,118 @@
_ = ls.Command("tasks", "List the tasks defined in the configuration file.")
+// determineLoader will return the config loader to use. +func determineLoader() config.Loader { + return &bitbucket.Loader{} + return &convey.Loader{} +// determineRunner will return the runner that handles the given command. +func determineRunner(command string) runners.Runner { + return &runners.Graphviz{} + case "list environment": + return &runners.ListEnvironment{} + return &runners.ListMetaPlans{} + return &runners.ListPlans{} + return &runners.ListTasks{} + return &runners.ShowConfig{} + return &runners.Default{} +// handleDeprecatedCommands will check deprecated command line flags and return +// the current command that they should run. +func handleDeprecatedCommands() string { + if *disableDeprecated { + fmt.Printf("--graphviz is deprecated, use 'convey graphviz` instead") + } else if *listEnvironment { + fmt.Printf("--list-environment is deprecated, use 'convey list environment` instead") + command = "list environment" + } else if *listMetaPlans { + fmt.Printf("--list-metaplans is deprecated, use `convey list metaplans` instead") + command = "list metaplans" + fmt.Printf("--list-plans is deprecated, use `convey list plans` instead") + fmt.Printf("--list-tasks is deprecated, use `convey list tasks` instead") + } else if *showConfig { + fmt.Printf("--list-plans is deprecated, use `convey config` instead") +// resolvePlans will run through all of the plans in the config and resolve +// their names via the loader. +func resolvePlans(cfg *config.Config, loader config.Loader, st *state.State) []string { + realPlans := []string{} + for _, planName := range *planNames { + if metaPlan, found := cfg.MetaPlans[planName]; found { + realPlans = append(realPlans, metaPlan.Plans...) + realPlans = append(realPlans, loader.ResolvePlanName(planName, cfg, st)) +// loadConfig will load the config and it's path or an error. +func loadConfig(loader config.Loader) (*config.Config, string, error) { + // if a config file was not provided search for the loader's default file + for _, filename := range loader.Filenames() { + if _, err := os.Stat(filename); os.IsNotExist(err) { + // now make sure we found a config file + err := fmt.Errorf("config file not found, looking for %s\n", strings.Join(loader.Filenames(), ",")) + // figure out the path to the config file + cfgPath, err := filepath.Abs(filepath.Dir(*configFile)) + cfg, err := config.LoadFile(*configFile, loader, *disableDeprecated) + return cfg, cfgPath, nil @@ -99,40 +213,9 @@
defer gomol.ShutdownLoggers()
- var loader config.Loader
- loader = &convey.Loader{}
- loader = &bitbucket.Loader{}
- // if a config file was not provided search for the loader's default file
- for _, filename := range loader.Filenames() {
- if _, err := os.Stat(filename); os.IsNotExist(err) {
+ loader := determineLoader()
- // now make sure we found a config file
- fmt.Printf("config file not found, looking for %s\n", strings.Join(loader.Filenames(), ","))
- // figure out the path to the config file
- cfgPath, err := filepath.Abs(filepath.Dir(*configFile))
- fmt.Printf("%#v\n", err)
- cfg, err := config.LoadFile(*configFile, loader, *disableDeprecated)
+ cfg, cfgPath, err := loadConfig(loader) @@ -182,69 +265,18 @@
- if *disableDeprecated {
- fmt.Printf("--graphviz is deprecated, use 'convey graphviz` instead")
- } 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"
- if *disableDeprecated {
- fmt.Printf("--list-plans is deprecated, use `convey list plans` instead")
- if *disableDeprecated {
- fmt.Printf("--list-tasks is deprecated, use `convey list tasks` instead")
- } else if *showConfig {
- if *disableDeprecated {
- fmt.Printf("--list-plans is deprecated, use `convey config` instead")
+ if commandOverride := handleDeprecatedCommands(); commandOverride != "" { + command = commandOverride - var runner runners.Runner
- runner = &runners.Graphviz{}
- case "list environment":
- runner = &runners.ListEnvironment{}
- runner = &runners.ListMetaPlans{}
- runner = &runners.ListPlans{}
- runner = &runners.ListTasks{}
- runner = &runners.ShowConfig{}
- runner = &runners.Default{}
+ runner := determineRunner(command) if len(*planNames) == 0 {
*planNames = []string{loader.DefaultPlan()}
// resolve the plan name with the load and options
- realPlans := []string{}
- for _, planName := range *planNames {
- if metaPlan, found := cfg.MetaPlans[planName]; found {
- realPlans = append(realPlans, metaPlan.Plans...)
- realPlans = append(realPlans, loader.ResolvePlanName(planName, cfg, st))
+ realPlans := resolvePlans(cfg, loader, st) return runner.Run(cfg, realPlans, *env, st)