grim/convey

Added --list-environment. Fixes #132

2017-11-13, Gary Kramlich
71d5eff74393
Added --list-environment. Fixes #132
--- a/ChangeLog Mon Nov 13 22:14:31 2017 -0600
+++ b/ChangeLog Mon Nov 13 22:41:57 2017 -0600
@@ -1,5 +1,6 @@
0.11.2:
* Changed TaskTimeout to PlanTimeout. Fixed # 134
+ * Added --list-environment to show the config and builtin environment variables. Fixed #132
0.11.1: 20171021
* Fix a regression in the environment mapper that could mess up script attributes. PR #37 (Eric Fritz)
--- a/main.go Mon Nov 13 22:14:31 2017 -0600
+++ b/main.go Mon Nov 13 22:41:57 2017 -0600
@@ -52,9 +52,10 @@
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()
- listTasks = app.Flag("list-tasks", "List the supported tasks").Short('L').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()
@@ -156,6 +157,8 @@
var runner runners.Runner
if *graphviz {
runner = &runners.Graphviz{}
+ } else if *listEnvironment {
+ runner = &runners.ListEnvironment{}
} else if *listMetaPlans {
runner = &runners.ListMetaPlans{}
} else if *listPlans {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/runners/listenvironment.go Mon Nov 13 22:41:57 2017 -0600
@@ -0,0 +1,52 @@
+/*
+ * Convey
+ * Copyright 2016-2017 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package runners
+
+import (
+ "fmt"
+ "os"
+ "sort"
+ "strings"
+
+ "bitbucket.org/rw_grim/convey/config"
+ "bitbucket.org/rw_grim/convey/state"
+)
+
+type ListEnvironment struct{}
+
+func (l *ListEnvironment) Run(cfg *config.Config, plans []string, env []string, st *state.State) int {
+ fmt.Printf("Builtins:\n")
+ stateEnv := st.GetEnv()
+ sort.Strings(stateEnv)
+ for _, key := range stateEnv {
+ fmt.Printf(" %s=%s\n", key, os.Getenv(key))
+ }
+
+ fmt.Printf("Config:\n")
+ cfgEnv := cfg.Environment
+ sort.Strings(cfgEnv)
+ for _, env := range cfgEnv {
+ if strings.Contains(env, "=") {
+ fmt.Printf(" %s\n", env)
+ } else {
+ fmt.Printf(" %s=%s\n", env, os.Getenv(env))
+ }
+ }
+
+ return 0
+}