|
| 1 | +package parser |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/deis/deis/client-go/cmd" |
| 7 | + docopt "github.com/docopt/docopt-go" |
| 8 | +) |
| 9 | + |
| 10 | +// Tags routes tags commands to their specific function |
| 11 | +func Tags(argv []string) error { |
| 12 | + usage := ` |
| 13 | +Valid commands for tags: |
| 14 | +
|
| 15 | +tags:list list tags for an app |
| 16 | +tags:set set tags for an app |
| 17 | +tags:unset unset tags for an app |
| 18 | +
|
| 19 | +Use 'deis help [command]' to learn more. |
| 20 | +` |
| 21 | + if len(argv) < 2 { |
| 22 | + return tagsList([]string{"tags:list"}) |
| 23 | + } |
| 24 | + |
| 25 | + switch argv[1] { |
| 26 | + case "list": |
| 27 | + return tagsList(combineCommand(argv)) |
| 28 | + case "set": |
| 29 | + return tagsSet(combineCommand(argv)) |
| 30 | + case "unset": |
| 31 | + return tagsUnset(combineCommand(argv)) |
| 32 | + case "--help": |
| 33 | + fmt.Print(usage) |
| 34 | + return nil |
| 35 | + default: |
| 36 | + PrintUsage() |
| 37 | + return nil |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func tagsList(argv []string) error { |
| 42 | + usage := ` |
| 43 | +Lists tags for an application. |
| 44 | +
|
| 45 | +Usage: deis tags:list [options] |
| 46 | +
|
| 47 | +Options: |
| 48 | + -a --app=<app> |
| 49 | + the uniquely identifiable name of the application. |
| 50 | +` |
| 51 | + |
| 52 | + args, err := docopt.Parse(usage, argv, true, "", false, true) |
| 53 | + |
| 54 | + if err != nil { |
| 55 | + return err |
| 56 | + } |
| 57 | + |
| 58 | + return cmd.TagsList(safeGetValue(args, "--app")) |
| 59 | +} |
| 60 | + |
| 61 | +func tagsSet(argv []string) error { |
| 62 | + usage := ` |
| 63 | +Sets tags for an application. |
| 64 | +
|
| 65 | +A tag is a key/value pair used to tag an application's containers and is passed to the |
| 66 | +scheduler. This is often used to restrict workloads to specific hosts matching the |
| 67 | +scheduler-configured metadata. |
| 68 | +
|
| 69 | +Usage: deis tags:set [options] <key>=<value>... |
| 70 | +
|
| 71 | +Arguments: |
| 72 | + <key> the tag key, for example: "environ" or "rack" |
| 73 | + <value> the tag value, for example: "prod" or "1" |
| 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 | + tags := args["<key>=<value>"].([]string) |
| 88 | + |
| 89 | + return cmd.TagsSet(app, tags) |
| 90 | +} |
| 91 | + |
| 92 | +func tagsUnset(argv []string) error { |
| 93 | + usage := ` |
| 94 | +Unsets tags for an application. |
| 95 | +
|
| 96 | +Usage: deis tags:unset [options] <key>... |
| 97 | +
|
| 98 | +Arguments: |
| 99 | + <key> the tag key to unset, for example: "environ" or "rack" |
| 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 | + tags := args["<key>"].([]string) |
| 114 | + |
| 115 | + return cmd.TagsUnset(app, tags) |
| 116 | +} |
0 commit comments