github.com/naphatkrit/deis@v1.12.3/client/parser/config.go (about) 1 package parser 2 3 import ( 4 "github.com/deis/deis/client/cmd" 5 docopt "github.com/docopt/docopt-go" 6 ) 7 8 // Config routes config commands to their specific function. 9 func Config(argv []string) 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) 25 case "config:set": 26 return configSet(argv) 27 case "config:unset": 28 return configUnset(argv) 29 case "config:pull": 30 return configPull(argv) 31 case "config:push": 32 return configPush(argv) 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) 41 } 42 43 PrintUsage() 44 return nil 45 } 46 } 47 48 func configList(argv []string) 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 -a --app=<app> 58 the uniquely identifiable name of the application. 59 ` 60 61 args, err := docopt.Parse(usage, argv, true, "", false, true) 62 63 if err != nil { 64 return err 65 } 66 67 return cmd.ConfigList(safeGetValue(args, "--app"), args["--oneline"].(bool)) 68 } 69 70 func configSet(argv []string) error { 71 usage := ` 72 Sets environment variables for an application. 73 74 Usage: deis config:set <var>=<value> [<var>=<value>...] [options] 75 76 Arguments: 77 <var> 78 the uniquely identifiable name for the environment variable. 79 <value> 80 the value of said environment variable. 81 82 Options: 83 -a --app=<app> 84 the uniquely identifiable name for the application. 85 ` 86 87 args, err := docopt.Parse(usage, argv, true, "", false, true) 88 89 if err != nil { 90 return err 91 } 92 93 return cmd.ConfigSet(safeGetValue(args, "--app"), args["<var>=<value>"].([]string)) 94 } 95 96 func configUnset(argv []string) error { 97 usage := ` 98 Unsets an environment variable for an application. 99 100 Usage: deis config:unset <key>... [options] 101 102 Arguments: 103 <key> 104 the variable to remove from the application's environment. 105 106 Options: 107 -a --app=<app> 108 the uniquely identifiable name for the application. 109 ` 110 111 args, err := docopt.Parse(usage, argv, true, "", false, true) 112 113 if err != nil { 114 return err 115 } 116 117 return cmd.ConfigUnset(safeGetValue(args, "--app"), args["<key>"].([]string)) 118 } 119 120 func configPull(argv []string) error { 121 usage := ` 122 Extract all environment variables from an application for local use. 123 124 Your environment will be stored locally in a file named .env. This file can be 125 read by foreman to load the local environment for your app. 126 127 Usage: deis config:pull [options] 128 129 Options: 130 -a --app=<app> 131 The application that you wish to pull from 132 -i --interactive 133 Prompts for each value to be overwritten 134 -o --overwrite 135 Allows you to have the pull overwrite keys in .env 136 ` 137 138 args, err := docopt.Parse(usage, argv, true, "", false, true) 139 140 if err != nil { 141 return err 142 } 143 144 app := safeGetValue(args, "--app") 145 interactive := args["--interactive"].(bool) 146 overwrite := args["--overwrite"].(bool) 147 148 return cmd.ConfigPull(app, interactive, overwrite) 149 } 150 151 func configPush(argv []string) error { 152 usage := ` 153 Sets environment variables for an application. 154 155 The environment is read from <path>. This file can be read by foreman 156 to load the local environment for your app. 157 158 Usage: deis config:push [options] 159 160 Options: 161 -a --app=<app> 162 the uniquely identifiable name for the application. 163 -p <path>, --path=<path> 164 a path leading to an environment file [default: .env] 165 ` 166 167 args, err := docopt.Parse(usage, argv, true, "", false, true) 168 169 if err != nil { 170 return err 171 } 172 173 return cmd.ConfigPush(safeGetValue(args, "--app"), safeGetValue(args, "--path")) 174 }