-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlabels.go
More file actions
114 lines (86 loc) · 2.45 KB
/
labels.go
File metadata and controls
114 lines (86 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package parser
import (
docopt "github.com/docopt/docopt-go"
"github.com/drycc/workflow-cli/cmd"
)
// Labels displays all relevant commands for `drycc label`.
func Labels(argv []string, cmdr cmd.Commander) error {
usage := `
Valid commands for labels:
labels:list list application's labels
labels:set add new application's label
labels:unset remove application's label
Use 'drycc help [command]' to learn more.
`
switch argv[0] {
case "labels:list":
return labelsList(argv, cmdr)
case "labels:set":
return labelsSet(argv, cmdr)
case "labels:unset":
return labelsUnset(argv, cmdr)
default:
if printHelp(argv, usage) {
return nil
}
if argv[0] == "labels" {
argv[0] = "labels:list"
return labelsList(argv, cmdr)
}
PrintUsage(cmdr)
return nil
}
}
func labelsList(argv []string, cmdr cmd.Commander) error {
usage := `
Prints a list of labels of the application.
Usage: drycc labels:list [options]
Options:
-a --app=<app>
the uniquely identifiable name for the application.
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
return cmdr.LabelsList(safeGetString(args, "--app"))
}
func labelsSet(argv []string, cmdr cmd.Commander) error {
usage := `
Sets labels for an application.
A label is a key/value pair used to label an application. This label is a general information for drycc user.
Mostly used for administration/maintenance information, note for application. This information isn't send to scheduler.
Usage: drycc labels:set [options] <key>=<value>...
Arguments:
<key> the label key, for example: "git_repo" or "team"
<value> the label value, for example: "https://github.com/drycc/workflow" or "frontend"
Options:
-a --app=<app>
the uniquely identifiable name for the application.
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
app := safeGetString(args, "--app")
tags := args["<key>=<value>"].([]string)
return cmdr.LabelsSet(app, tags)
}
func labelsUnset(argv []string, cmdr cmd.Commander) error {
usage := `
Unsets labels for an application.
Usage: drycc labels:unset [options] <key>...
Arguments:
<key> the label key to unset, for example: "git_repo" or "team"
Options:
-a --app=<app>
the uniquely identifiable name for the application.
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
app := safeGetString(args, "--app")
tags := args["<key>"].([]string)
return cmdr.LabelsUnset(app, tags)
}