github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/labels.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 // Labels displays all relevant commands for `deis label`. 9 func Labels(argv []string, cmdr cmd.Commander) error { 10 usage := ` 11 Valid commands for labels: 12 13 labels:list list application's labels 14 labels:set add new application's label 15 labels:unset remove application's label 16 17 Use 'deis help [command]' to learn more. 18 ` 19 20 switch argv[0] { 21 case "labels:list": 22 return labelsList(argv, cmdr) 23 case "labels:set": 24 return labelsSet(argv, cmdr) 25 case "labels:unset": 26 return labelsUnset(argv, cmdr) 27 default: 28 if printHelp(argv, usage) { 29 return nil 30 } 31 32 if argv[0] == "labels" { 33 argv[0] = "labels:list" 34 return labelsList(argv, cmdr) 35 } 36 37 PrintUsage(cmdr) 38 return nil 39 } 40 } 41 42 func labelsList(argv []string, cmdr cmd.Commander) error { 43 usage := ` 44 Prints a list of labels of the application. 45 46 Usage: deis labels:list [options] 47 48 Options: 49 -a --app=<app> 50 the uniquely identifiable name for the application. 51 ` 52 53 args, err := docopt.Parse(usage, argv, true, "", false, true) 54 55 if err != nil { 56 return err 57 } 58 59 return cmdr.LabelsList(safeGetValue(args, "--app")) 60 } 61 62 func labelsSet(argv []string, cmdr cmd.Commander) error { 63 usage := ` 64 Sets labels for an application. 65 66 A label is a key/value pair used to label an application. This label is a general information for deis user. 67 Mostly used for administration/maintenance information, note for application. This information isn't send to scheduler. 68 69 Usage: deis labels:set [options] <key>=<value>... 70 71 Arguments: 72 <key> the label key, for example: "git_repo" or "team" 73 <value> the label value, for example: "https://github.com/teamhephy/workflow" or "frontend" 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 if err != nil { 82 return err 83 } 84 85 app := safeGetValue(args, "--app") 86 tags := args["<key>=<value>"].([]string) 87 88 return cmdr.LabelsSet(app, tags) 89 } 90 91 func labelsUnset(argv []string, cmdr cmd.Commander) error { 92 usage := ` 93 Unsets labels for an application. 94 95 Usage: deis labels:unset [options] <key>... 96 97 Arguments: 98 <key> the label key to unset, for example: "git_repo" or "team" 99 100 Options: 101 -a --app=<app> 102 the uniquely identifiable name for the application. 103 ` 104 105 args, err := docopt.Parse(usage, argv, true, "", false, true) 106 if err != nil { 107 return err 108 } 109 110 app := safeGetValue(args, "--app") 111 tags := args["<key>"].([]string) 112 113 return cmdr.LabelsUnset(app, tags) 114 }