github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/registry.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 // Registry routes registry commands to their specific function 9 func Registry(argv []string, cmdr cmd.Commander) error { 10 usage := ` 11 Valid commands for registry: 12 13 registry:list list registry info for an app 14 registry:set set registry info for an app 15 registry:unset unset registry info for an app 16 17 Use 'deis help [command]' to learn more. 18 ` 19 20 switch argv[0] { 21 case "registry:list": 22 return registryList(argv, cmdr) 23 case "registry:set": 24 return registrySet(argv, cmdr) 25 case "registry:unset": 26 return registryUnset(argv, cmdr) 27 default: 28 if printHelp(argv, usage) { 29 return nil 30 } 31 32 if argv[0] == "registry" { 33 argv[0] = "registry:list" 34 return registryList(argv, cmdr) 35 } 36 37 PrintUsage(cmdr) 38 return nil 39 } 40 } 41 42 func registryList(argv []string, cmdr cmd.Commander) error { 43 usage := ` 44 Lists registry information for an application. 45 46 Usage: deis registry:list [options] 47 48 Options: 49 -a --app=<app> 50 the uniquely identifiable name of the application. 51 ` 52 53 args, err := docopt.Parse(usage, argv, true, "", false, true) 54 if err != nil { 55 return err 56 } 57 58 return cmdr.RegistryList(safeGetValue(args, "--app")) 59 } 60 61 func registrySet(argv []string, cmdr cmd.Commander) error { 62 usage := ` 63 Sets registry information for an application. These credentials are the same as those used for 64 'docker login' to the private registry. 65 66 Usage: deis registry:set [options] <key>=<value>... 67 68 Arguments: 69 <key> 70 the uniquely identifiable name for logging into the registry. Valid keys are "username" or 71 "password" 72 <value> 73 the value of said environment variable. For example, "bob" or "mysecretpassword" 74 75 Options: 76 -a --app=<app> 77 the uniquely identifiable name for the application. 78 ` 79 80 args, err := docopt.Parse(usage, argv, true, "", false, true) 81 82 if err != nil { 83 return err 84 } 85 86 app := safeGetValue(args, "--app") 87 info := args["<key>=<value>"].([]string) 88 89 return cmdr.RegistrySet(app, info) 90 } 91 92 func registryUnset(argv []string, cmdr cmd.Commander) error { 93 usage := ` 94 Unsets registry information for an application. 95 96 Usage: deis registry:unset [options] <key>... 97 98 Arguments: 99 <key> the registry key to unset, for example: "username" or "password" 100 101 Options: 102 -a --app=<app> 103 the uniquely identifiable name for the application. 104 ` 105 106 args, err := docopt.Parse(usage, argv, true, "", false, true) 107 108 if err != nil { 109 return err 110 } 111 112 app := safeGetValue(args, "--app") 113 key := args["<key>"].([]string) 114 115 return cmdr.RegistryUnset(app, key) 116 }