github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/config.go (about) 1 package parser 2 3 import ( 4 "github.com/teamhephy/workflow-cli/cmd" 5 docopt "github.com/docopt/docopt-go" 6 ) 7 8 // Config routes config commands to their specific function. 9 func Config(argv []string, cmdr cmd.Commander) error { 10 usage := ` 11 Valid commands for config: 12 13 config:list list environment variables for an app 14 config:set set environment variables for an app 15 config:unset unset environment variables for an app 16 config:pull extract environment variables to .env 17 config:push set environment variables from .env 18 19 Use 'deis help [command]' to learn more. 20 ` 21 22 switch argv[0] { 23 case "config:list": 24 return configList(argv, cmdr) 25 case "config:set": 26 return configSet(argv, cmdr) 27 case "config:unset": 28 return configUnset(argv, cmdr) 29 case "config:pull": 30 return configPull(argv, cmdr) 31 case "config:push": 32 return configPush(argv, cmdr) 33 default: 34 if printHelp(argv, usage) { 35 return nil 36 } 37 38 if argv[0] == "config" { 39 argv[0] = "config:list" 40 return configList(argv, cmdr) 41 } 42 43 PrintUsage(cmdr) 44 return nil 45 } 46 } 47 48 func configList(argv []string, cmdr cmd.Commander) error { 49 usage := ` 50 Lists environment variables for an application. 51 52 Usage: deis config:list [options] 53 54 Options: 55 --oneline 56 print output on one line. 57 --diff 58 print output on multiple lines for comparison against .env files. 59 -a --app=<app> 60 the uniquely identifiable name of the application. 61 ` 62 63 args, err := docopt.Parse(usage, argv, true, "", false, true) 64 65 if err != nil { 66 return err 67 } 68 app := safeGetValue(args, "--app") 69 oneline := args["--oneline"].(bool) 70 diff := args["--diff"].(bool) 71 72 format := "" 73 if oneline { 74 format = "oneline" 75 } else if diff { 76 format = "diff" 77 } 78 79 return cmdr.ConfigList(app, format) 80 } 81 82 func configSet(argv []string, cmdr cmd.Commander) error { 83 usage := ` 84 Sets environment variables for an application. 85 86 Usage: deis config:set <var>=<value> [<var>=<value>...] [options] 87 88 Arguments: 89 <var> 90 the uniquely identifiable name for the environment variable. 91 <value> 92 the value of said environment variable. 93 94 Options: 95 -a --app=<app> 96 the uniquely identifiable name for the application. 97 ` 98 99 args, err := docopt.Parse(usage, argv, true, "", false, true) 100 101 if err != nil { 102 return err 103 } 104 105 app := safeGetValue(args, "--app") 106 107 return cmdr.ConfigSet(app, args["<var>=<value>"].([]string)) 108 } 109 110 func configUnset(argv []string, cmdr cmd.Commander) error { 111 usage := ` 112 Unsets an environment variable for an application. 113 114 Usage: deis config:unset <key>... [options] 115 116 Arguments: 117 <key> 118 the variable to remove from the application's environment. 119 120 Options: 121 -a --app=<app> 122 the uniquely identifiable name for the application. 123 ` 124 125 args, err := docopt.Parse(usage, argv, true, "", false, true) 126 127 if err != nil { 128 return err 129 } 130 app := safeGetValue(args, "--app") 131 132 return cmdr.ConfigUnset(app, args["<key>"].([]string)) 133 } 134 135 func configPull(argv []string, cmdr cmd.Commander) error { 136 usage := ` 137 Extract all environment variables from an application for local use. 138 139 The environmental variables can be piped into a file, 'deis config:pull > file', 140 or stored locally in a file named .env. This file can be 141 read by foreman to load the local environment for your app. 142 143 Usage: deis config:pull [options] 144 145 Options: 146 -a --app=<app> 147 The application that you wish to pull from 148 -i --interactive 149 Prompts for each value to be overwritten 150 -o --overwrite 151 Allows you to have the pull overwrite keys in .env 152 ` 153 154 args, err := docopt.Parse(usage, argv, true, "", false, true) 155 156 if err != nil { 157 return err 158 } 159 160 app := safeGetValue(args, "--app") 161 interactive := args["--interactive"].(bool) 162 overwrite := args["--overwrite"].(bool) 163 164 return cmdr.ConfigPull(app, interactive, overwrite) 165 } 166 167 func configPush(argv []string, cmdr cmd.Commander) error { 168 usage := ` 169 Sets environment variables for an application. 170 171 This file can be read by foreman 172 to load the local environment for your app. The file should be piped via 173 stdin, 'deis config:push < .env', or using the --path option. 174 175 Usage: deis config:push [options] 176 177 Options: 178 -a --app=<app> 179 the uniquely identifiable name for the application. 180 -p <path>, --path=<path> 181 a path leading to an environment file [default: .env] 182 ` 183 184 args, err := docopt.Parse(usage, argv, true, "", false, true) 185 186 if err != nil { 187 return err 188 } 189 190 app := safeGetValue(args, "--app") 191 path := safeGetValue(args, "--path") 192 193 return cmdr.ConfigPush(app, path) 194 }