From 5c321e53ed82f32fbfefcc5917921c535025c998 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Wed, 7 Jun 2023 15:45:35 +0000 Subject: [PATCH 1/2] fix(cli/help): Show deprecation notice properly for flags --- cli/help.go | 23 +++++++++++++++++++++++ cli/help.tpl | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cli/help.go b/cli/help.go index 6fb5066a152d1..c308e068474e0 100644 --- a/cli/help.go +++ b/cli/help.go @@ -135,6 +135,29 @@ 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 == len(opt.UseInstead)-1 { + _, _ = sb.WriteString(" and ") + } else if i > 0 { + _, _ = 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 diff --git a/cli/help.tpl b/cli/help.tpl index b464cbb248273..97d79db936e43 100644 --- a/cli/help.tpl +++ b/cli/help.tpl @@ -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 }} From 7168a9d12a404c383c3a013203e53fb6c1aa563b Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Thu, 8 Jun 2023 14:04:30 +0000 Subject: [PATCH 2/2] Update golden files, fix and --- cli/help.go | 10 ++++++---- cli/testdata/coder_ssh_--help.golden | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cli/help.go b/cli/help.go index c308e068474e0..fa813febc53e9 100644 --- a/cli/help.go +++ b/cli/help.go @@ -138,10 +138,12 @@ var usageTemplate = template.Must( "useInstead": func(opt clibase.Option) string { var sb strings.Builder for i, s := range opt.UseInstead { - if i == len(opt.UseInstead)-1 { - _, _ = sb.WriteString(" and ") - } else if i > 0 { - _, _ = sb.WriteString(", ") + if i > 0 { + if i == len(opt.UseInstead)-1 { + _, _ = sb.WriteString(" and ") + } else { + _, _ = sb.WriteString(", ") + } } if s.Flag != "" { _, _ = sb.WriteString("--") diff --git a/cli/testdata/coder_ssh_--help.golden b/cli/testdata/coder_ssh_--help.golden index 4880365501690..890c08e1e57c7 100644 --- a/cli/testdata/coder_ssh_--help.golden +++ b/cli/testdata/coder_ssh_--help.golden @@ -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.