Skip to content

fix(cli/help): show deprecation notice properly for flags #7904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cli/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,31 @@ var usageTemplate = template.Must(
"isDeprecated": func(opt clibase.Option) bool {
return len(opt.UseInstead) > 0
},
"useInstead": func(opt clibase.Option) string {
var sb strings.Builder
for i, s := range opt.UseInstead {
if i > 0 {
if i == len(opt.UseInstead)-1 {
_, _ = sb.WriteString(" and ")
} else {
_, _ = sb.WriteString(", ")
}
}
if s.Flag != "" {
_, _ = sb.WriteString("--")
_, _ = sb.WriteString(s.Flag)
} else if s.FlagShorthand != "" {
_, _ = sb.WriteString("-")
_, _ = sb.WriteString(s.FlagShorthand)
} else if s.Env != "" {
_, _ = sb.WriteString("$")
_, _ = sb.WriteString(s.Env)
} else {
_, _ = sb.WriteString(s.Name)
}
}
return sb.String()
},
"formatLong": func(long string) string {
// We intentionally don't wrap here because it would misformat
// examples, where the new line would start without the prior
Expand Down
2 changes: 1 addition & 1 deletion cli/help.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Usage: {{.FullUsage}}
{{- with $option.Description }}
{{- $desc := $option.Description }}
{{ indent $desc 10 }}
{{- if isDeprecated $option }} DEPRECATED {{ end }}
{{- if isDeprecated $option }}{{ indent (printf "DEPRECATED: Use %s instead." (useInstead $option)) 10 }}{{ end }}
{{- end -}}
{{- end }}
{{- end }}
Expand Down
3 changes: 2 additions & 1 deletion cli/testdata/coder_ssh_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Start a shell into a workspace
Enter workspace immediately after the agent has connected. This is the
default if the template has configured the agent startup script
behavior as non-blocking.
DEPRECATED
DEPRECATED: Use --wait instead.

--stdio bool, $CODER_SSH_STDIO
Specifies whether to emit SSH output over stdin/stdout.

Expand Down