Skip to content

Commit 3f74426

Browse files
committed
review
1 parent 4869325 commit 3f74426

File tree

8 files changed

+27
-13
lines changed

8 files changed

+27
-13
lines changed

cli/restart.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func (r *RootCmd) restart() *serpent.Command {
2626
Short: "Restart a workspace",
2727
Middleware: serpent.Chain(
2828
serpent.RequireNArgs(1),
29-
PrintDeprecatedOptions(),
3029
r.InitClient(client),
3130
),
3231
Options: serpent.OptionSet{cliui.SkipPromptOption()},

cli/root.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ func (r *RootCmd) Command(subcommands []*serpent.Command) (*serpent.Command, err
325325
}
326326
})
327327

328+
// Add the PrintDeprecatedOptions middleware to all commands.
329+
cmd.Walk(func(cmd *serpent.Command) {
330+
if cmd.Middleware == nil {
331+
cmd.Middleware = PrintDeprecatedOptions()
332+
} else {
333+
cmd.Middleware = serpent.Chain(cmd.Middleware, PrintDeprecatedOptions())
334+
}
335+
})
336+
328337
if r.agentURL == nil {
329338
r.agentURL = new(url.URL)
330339
}
@@ -1324,17 +1333,19 @@ func PrintDeprecatedOptions() serpent.MiddlewareFunc {
13241333
continue
13251334
}
13261335

1327-
warnStr := translateSource(opt.ValueSource, opt) + " is deprecated, please use "
1336+
var warnStr strings.Builder
1337+
_, _ = warnStr.WriteString(translateSource(opt.ValueSource, opt))
1338+
_, _ = warnStr.WriteString(" is deprecated, please use ")
13281339
for i, use := range opt.UseInstead {
1329-
warnStr += translateSource(opt.ValueSource, use) + " "
1340+
_, _ = warnStr.WriteString(translateSource(opt.ValueSource, use))
13301341
if i != len(opt.UseInstead)-1 {
1331-
warnStr += "and "
1342+
_, _ = warnStr.WriteString(" and ")
13321343
}
13331344
}
1334-
warnStr += "instead.\n"
1345+
_, _ = warnStr.WriteString(" instead.\n")
13351346

13361347
cliui.Warn(inv.Stderr,
1337-
warnStr,
1348+
warnStr.String(),
13381349
)
13391350
}
13401351

@@ -1352,8 +1363,18 @@ func translateSource(target serpent.ValueSource, opt serpent.Option) string {
13521363
case serpent.ValueSourceEnv:
13531364
return fmt.Sprintf("`%s`", opt.Env)
13541365
case serpent.ValueSourceYAML:
1355-
return fmt.Sprintf("`%s`", opt.YAML)
1366+
return fmt.Sprintf("`%s`", fullYamlName(opt))
13561367
default:
13571368
return opt.Name
13581369
}
13591370
}
1371+
1372+
func fullYamlName(opt serpent.Option) string {
1373+
var full strings.Builder
1374+
for _, name := range opt.Group.Ancestry() {
1375+
_, _ = full.WriteString(name.YAML)
1376+
_, _ = full.WriteString(".")
1377+
}
1378+
_, _ = full.WriteString(opt.YAML)
1379+
return full.String()
1380+
}

cli/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
294294
Options: opts,
295295
Middleware: serpent.Chain(
296296
WriteConfigMW(vals),
297-
PrintDeprecatedOptions(),
298297
serpent.RequireNArgs(0),
299298
),
300299
Handler: func(inv *serpent.Invocation) error {

cli/ssh.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ func (r *RootCmd) ssh() *serpent.Command {
7777
Middleware: serpent.Chain(
7878
serpent.RequireNArgs(1),
7979
r.InitClient(client),
80-
PrintDeprecatedOptions(),
8180
initAppearance(client, &appearanceConfig),
8281
),
8382
Handler: func(inv *serpent.Invocation) (retErr error) {

cli/start.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ func (r *RootCmd) start() *serpent.Command {
2525
Short: "Start a workspace",
2626
Middleware: serpent.Chain(
2727
serpent.RequireNArgs(1),
28-
PrintDeprecatedOptions(),
2928
r.InitClient(client),
3029
),
3130
Options: serpent.OptionSet{cliui.SkipPromptOption()},

cli/update.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func (r *RootCmd) update() *serpent.Command {
2222
Long: "Use --always-prompt to change the parameter values of the workspace.",
2323
Middleware: serpent.Chain(
2424
serpent.RequireNArgs(1),
25-
PrintDeprecatedOptions(),
2625
r.InitClient(client),
2726
),
2827
Handler: func(inv *serpent.Invocation) error {

enterprise/cli/provisionerdaemonstart.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
5858
Use: "start",
5959
Short: "Run a provisioner daemon",
6060
Middleware: serpent.Chain(
61-
agpl.PrintDeprecatedOptions(),
6261
// disable checks and warnings because this command starts a daemon; it is
6362
// not meant for humans typing commands. Furthermore, the checks are
6463
// incompatible with PSK auth that this command uses

enterprise/cli/proxyserver.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ func (r *RootCmd) proxyServer() *serpent.Command {
110110
Options: opts,
111111
Middleware: serpent.Chain(
112112
cli.WriteConfigMW(cfg),
113-
cli.PrintDeprecatedOptions(),
114113
serpent.RequireNArgs(0),
115114
),
116115
Handler: func(inv *serpent.Invocation) error {

0 commit comments

Comments
 (0)