Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74836c8

Browse files
committed
review
1 parent 4869325 commit 74836c8

File tree

8 files changed

+28
-13
lines changed

8 files changed

+28
-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: 28 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,20 @@ 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.Cap()
1338+
_, _ = warnStr.WriteString(translateSource(opt.ValueSource, opt))
1339+
_, _ = warnStr.WriteString(" is deprecated, please use ")
13281340
for i, use := range opt.UseInstead {
1329-
warnStr += translateSource(opt.ValueSource, use) + " "
1341+
_, _ = warnStr.WriteString(translateSource(opt.ValueSource, use))
13301342
if i != len(opt.UseInstead)-1 {
1331-
warnStr += "and "
1343+
_, _ = warnStr.WriteString(" and ")
13321344
}
13331345
}
1334-
warnStr += "instead.\n"
1346+
_, _ = warnStr.WriteString(" instead.\n")
13351347

13361348
cliui.Warn(inv.Stderr,
1337-
warnStr,
1349+
warnStr.String(),
13381350
)
13391351
}
13401352

@@ -1352,8 +1364,18 @@ func translateSource(target serpent.ValueSource, opt serpent.Option) string {
13521364
case serpent.ValueSourceEnv:
13531365
return fmt.Sprintf("`%s`", opt.Env)
13541366
case serpent.ValueSourceYAML:
1355-
return fmt.Sprintf("`%s`", opt.YAML)
1367+
return fmt.Sprintf("`%s`", fullYamlName(opt))
13561368
default:
13571369
return opt.Name
13581370
}
13591371
}
1372+
1373+
func fullYamlName(opt serpent.Option) string {
1374+
var full strings.Builder
1375+
for _, name := range opt.Group.Ancestry() {
1376+
_, _ = full.WriteString(name.YAML)
1377+
_, _ = full.WriteString(".")
1378+
}
1379+
_, _ = full.WriteString(opt.YAML)
1380+
return full.String()
1381+
}

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)