Repository navigation
Expand file tree
/
Copy pathflags.go
More file actions
227 lines (214 loc) · 7.36 KB
/
Copy pathflags.go
File metadata and controls
227 lines (214 loc) · 7.36 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package cli
import (
"strings"
"github.com/urfave/cli/v3"
"github.com/umatare5/cisco-wnc-cli/internal/config"
"github.com/umatare5/cisco-wnc-cli/internal/log"
)
// rootFlags are the flags every command parses, before or after its own name. --dry-run
// stops an action before its RPC and a show command before its read, and generate-token,
// which contacts no controller, has nothing for it to stop.
func rootFlags() []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: config.FlagConfig,
Usage: "path to the JSON configuration file",
Sources: cli.EnvVars(config.EnvConfig),
},
&cli.StringFlag{
Name: config.FlagLogLevel,
Usage: "log verbosity (" + strings.Join(log.Levels(), "|") + ")",
Value: config.DefaultLogLevel,
},
&cli.BoolFlag{
Name: config.FlagDryRun,
Usage: "report what would happen and change nothing",
},
}
}
// showFlags are shared by every show subcommand. urfave makes a parent's flag persistent unless
// Local is set, so declaring them here puts them on every one.
func showFlags() []cli.Flag {
return []cli.Flag{
// Deliberately no Sources. urfave applies a slice flag's environment value at
// the level that declares it, then appends what a deeper command supplies.
//
// "show ap -c host" with WNC_CONTROLLER exported would query the named host
// and the exported ones. config.Resolve reads the variable itself instead.
&cli.StringSliceFlag{
Name: config.FlagController,
Aliases: []string{"c"},
// The variable is spelled out here because Sources is absent, and urfave
// only appends the bracketed name for a flag that declares one.
Usage: "controller host[:port], repeatable [$" + config.EnvController + "]",
},
&cli.StringFlag{
Name: config.FlagAccessToken,
Usage: "Basic auth token for every controller",
Sources: cli.EnvVars(config.EnvAccessToken),
},
&cli.BoolFlag{
Name: config.FlagInsecure,
Aliases: []string{"k"},
Usage: "skip TLS certificate verification",
},
// -o is the conventional short name for an output format, and -f is kept beside it
// because this CLI's own examples are written with it.
&cli.StringFlag{
Name: config.FlagFormat,
Aliases: []string{"o", "f"},
Usage: "output format (" + config.FormatTable + "|" + config.FormatJSON + ")",
Value: config.DefaultFormat,
},
// Pretty is a table style rather than a format: it is inert under --format
// json, where the run still succeeds and a warning says the flag did nothing.
&cli.BoolFlag{
Name: config.FlagPretty,
Usage: "draw the table with borders and status glyphs",
},
&cli.DurationFlag{
Name: config.FlagTimeout,
Aliases: []string{"t"},
Usage: "request timeout",
Value: config.DefaultTimeout,
DefaultText: config.DefaultTimeout.String(),
},
// Long-only on purpose: -o is --format's, and the two take disjoint values.
&cli.StringFlag{
Name: config.FlagSortOrder,
Usage: "sort direction (" + config.OrderAsc + "|" + config.OrderDesc + ")",
Value: config.DefaultSortOrder,
},
&cli.StringSliceFlag{
Name: config.FlagColumns,
Usage: "comma-separated `keys` to print, or " + config.ColumnsAll + " (see --" + config.FlagListKeys + ")",
},
}
}
// execFlags are shared by the commands that act on a controller. The connection flags are
// spelled again rather than extracted from showFlags.
//
// Extracting them would reorder --timeout in every show command's help, and the OPTIONS
// transcripts in docs would have to move with it.
func execFlags() []cli.Flag {
return []cli.Flag{
// No Sources, for the reason showFlags gives: urfave appends a slice flag's
// environment value to what a deeper command supplies.
&cli.StringSliceFlag{
Name: config.FlagController,
Aliases: []string{"c"},
Usage: "controller host[:port] [$" + config.EnvController + "]",
},
&cli.StringFlag{
Name: config.FlagAccessToken,
Usage: "Basic auth token for the controller",
Sources: cli.EnvVars(config.EnvAccessToken),
},
&cli.BoolFlag{
Name: config.FlagInsecure,
Aliases: []string{"k"},
Usage: "skip TLS certificate verification",
},
&cli.DurationFlag{
Name: config.FlagTimeout,
Aliases: []string{"t"},
Usage: "request timeout",
Value: config.DefaultTimeout,
DefaultText: config.DefaultTimeout.String(),
},
}
}
// The binding flags, one set per tag kind. Each leaf declares only its own: a flag on the
// set parent would be persistent and would let "set rf-tag --ap-join-profile" parse into a
// field an RF tag has no room for.
func policyTagFlags() []cli.Flag {
return []cli.Flag{
descriptionFlag(config.KindPolicyTag),
// Both are keys of the wlan-policy list, so one without the other binds nothing and
// is refused rather than dropped.
&cli.StringFlag{
Name: config.FlagWLAN,
Usage: "WLAN profile to bind, required with --" + config.FlagPolicyProfile,
},
&cli.StringFlag{
Name: config.FlagPolicyProfile,
Usage: "policy profile the WLAN is bound to, required with --" + config.FlagWLAN,
},
}
}
func siteTagFlags() []cli.Flag {
return []cli.Flag{
descriptionFlag(config.KindSiteTag),
&cli.StringFlag{
Name: config.FlagAPJoinProfile,
Usage: "AP join profile to bind",
},
// The leaf declares when "../is-local-site = 'false'", so a flex profile clears the
// flag on its own and naming both is refused before anything is sent.
&cli.StringFlag{
Name: config.FlagFlexProfile,
Usage: "flex profile to bind, which clears --" + config.FlagLocalSite,
},
&cli.BoolFlag{
Name: config.FlagLocalSite,
Usage: "mark the site local",
},
}
}
func rfTagFlags() []cli.Flag {
return []cli.Flag{
descriptionFlag(config.KindRFTag),
&cli.StringFlag{
Name: config.FlagProfile24GHz,
Usage: "2.4 GHz RF profile to bind",
},
&cli.StringFlag{
Name: config.FlagProfile5GHz,
Usage: "5 GHz RF profile to bind",
},
&cli.StringFlag{
Name: config.FlagProfile6GHz,
Usage: "6 GHz RF profile to bind",
},
}
}
// tagNameFlag names the tag a set or delete leaf writes, worded per kind as descriptionFlag
// is. The 32-character cap is the controller's own and unreadable from the model, so the help
// states it rather than leaving a 400 to teach it.
func tagNameFlag(kind string) cli.Flag {
return &cli.StringFlag{
Name: config.FlagName,
Usage: kind + " name, at most 32 characters",
}
}
func descriptionFlag(kind string) cli.Flag {
return &cli.StringFlag{
Name: config.FlagDescription,
Usage: "description for the " + kind,
}
}
// sortFlags builds the per-command sort pair. The default differs per command, so the pair is
// declared on each leaf rather than once on the parent.
func sortFlags(defaultKey string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: config.FlagSortBy,
Aliases: []string{"b"},
Usage: "sort `key` (see --" + config.FlagListKeys + ")",
Value: defaultKey,
},
&cli.BoolFlag{
Name: config.FlagListKeys,
Usage: "print the keys --" + config.FlagSortBy + " and --" + config.FlagColumns + " accept, then exit",
},
}
}
// radioFlag filters rows by band. The values are the band column's own display
// strings, so a filter and a rendered row match exactly.
func radioFlag() cli.Flag {
return &cli.StringFlag{
Name: config.FlagRadio,
Aliases: []string{"r"},
Usage: "band filter (" + config.Band24 + "|" + config.Band5 + "|" + config.Band6 + ")",
}
}