Skip to content

Commit fa91e11

Browse files
authored
fix(cli/help): show deprecation notice properly for flags (#7904)
1 parent a1c3295 commit fa91e11

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

cli/help.go

+25
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ var usageTemplate = template.Must(
135135
"isDeprecated": func(opt clibase.Option) bool {
136136
return len(opt.UseInstead) > 0
137137
},
138+
"useInstead": func(opt clibase.Option) string {
139+
var sb strings.Builder
140+
for i, s := range opt.UseInstead {
141+
if i > 0 {
142+
if i == len(opt.UseInstead)-1 {
143+
_, _ = sb.WriteString(" and ")
144+
} else {
145+
_, _ = sb.WriteString(", ")
146+
}
147+
}
148+
if s.Flag != "" {
149+
_, _ = sb.WriteString("--")
150+
_, _ = sb.WriteString(s.Flag)
151+
} else if s.FlagShorthand != "" {
152+
_, _ = sb.WriteString("-")
153+
_, _ = sb.WriteString(s.FlagShorthand)
154+
} else if s.Env != "" {
155+
_, _ = sb.WriteString("$")
156+
_, _ = sb.WriteString(s.Env)
157+
} else {
158+
_, _ = sb.WriteString(s.Name)
159+
}
160+
}
161+
return sb.String()
162+
},
138163
"formatLong": func(long string) string {
139164
// We intentionally don't wrap here because it would misformat
140165
// examples, where the new line would start without the prior

cli/help.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Usage: {{.FullUsage}}
4343
{{- with $option.Description }}
4444
{{- $desc := $option.Description }}
4545
{{ indent $desc 10 }}
46-
{{- if isDeprecated $option }} DEPRECATED {{ end }}
46+
{{- if isDeprecated $option }}{{ indent (printf "DEPRECATED: Use %s instead." (useInstead $option)) 10 }}{{ end }}
4747
{{- end -}}
4848
{{- end }}
4949
{{- end }}

cli/testdata/coder_ssh_--help.golden

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Start a shell into a workspace
2828
Enter workspace immediately after the agent has connected. This is the
2929
default if the template has configured the agent startup script
3030
behavior as non-blocking.
31-
DEPRECATED
31+
DEPRECATED: Use --wait instead.
32+
3233
--stdio bool, $CODER_SSH_STDIO
3334
Specifies whether to emit SSH output over stdin/stdout.
3435

0 commit comments

Comments
 (0)