Skip to content

Commit fc660db

Browse files
committed
fix(cli): use usage template for advanced hint to fix trailing whitespace
Move the advanced command hint from a help function wrapper (fmt.Fprintln) into cobra's usage template via SetUsageTemplate. The previous approach wrote outside the template system, so DisableExtraNewlines could not control trailing whitespace consistently across environments.
1 parent 29dfc7e commit fc660db

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

internal/app/azldev/app.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,16 @@ lives), or use -C to point to one.`,
180180
return app
181181
}
182182

183-
// addAdvancedCommandHint customizes the root help output to include a hint about
184-
// the hidden "advanced" command group.
183+
// addAdvancedCommandHint embeds a hint about the hidden "advanced" command group
184+
// into the root command's usage template so that DisableExtraNewlines handles
185+
// trailing whitespace consistently.
185186
func (a *App) addAdvancedCommandHint() {
186-
defaultHelp := a.cmd.HelpFunc()
187-
a.cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
188-
defaultHelp(cmd, args)
189-
190-
if cmd == cmd.Root() {
191-
fmt.Fprintln(cmd.OutOrStdout(),
192-
`Use "azldev advanced --help" for additional tools (mock, mcp, wget).`)
193-
}
194-
})
187+
tmpl := a.cmd.UsageTemplate()
188+
tmpl = strings.TrimSuffix(tmpl, "\n")
189+
tmpl += `{{if not .HasParent}}
190+
Use "{{.CommandPath}} advanced --help" for additional tools (mock, mcp, wget).{{end}}
191+
`
192+
a.cmd.SetUsageTemplate(tmpl)
195193
}
196194

197195
// Returns the names of the app's commands. The optional provided list of ancestors

scenario/__snapshots__/TestSnapshots_--bogus-flag_stderr_1.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Flags:
3131
--version version for azldev
3232

3333
Use "azldev [command] --help" for more information about a command.
34+
Use "azldev advanced --help" for additional tools (mock, mcp, wget).
3435

3536

3637
##:##:## ERR Error: unknown flag: --bogus-flag

scenario/__snapshots__/TestSnapshots_--help_stdout_1.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ Flags:
3838
--version version for azldev
3939

4040
Use "azldev [command] --help" for more information about a command.
41-
4241
Use "azldev advanced --help" for additional tools (mock, mcp, wget).
4342

scenario/__snapshots__/TestSnapshots_--help_with_color_stdout_1.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ Meta commands:
3838
--version version for azldev
3939

4040
Use "azldev [command] --help" for more information about a command.
41+
Use "azldev advanced --help" for additional tools (mock, mcp, wget).
4142

42-
Use "azldev advanced --help" for additional tools (mock, mcp, wget).

scenario/__snapshots__/TestSnapshots_help_stdout_1.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ Flags:
3838
--version version for azldev
3939

4040
Use "azldev [command] --help" for more information about a command.
41-
4241
Use "azldev advanced --help" for additional tools (mock, mcp, wget).
4342

0 commit comments

Comments
 (0)