From bf33c0739555961e32df79ac98fdb06b1ebb163d Mon Sep 17 00:00:00 2001 From: mitchell Date: Wed, 31 Jul 2024 11:15:24 -0400 Subject: [PATCH] Make trailing newline in command help more consistent. - Our template doesn't include a trailing newline, so add it. - output.Print() adds a trailing newline, so strip it from our Help() function. --- cmd/state/internal/cmdtree/exec.go | 2 +- internal/assets/contents/usage.tpl | 2 +- internal/captain/command.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/state/internal/cmdtree/exec.go b/cmd/state/internal/cmdtree/exec.go index 60a59b08c8..1b94068c39 100644 --- a/cmd/state/internal/cmdtree/exec.go +++ b/cmd/state/internal/cmdtree/exec.go @@ -27,7 +27,7 @@ func newExecCommand(prime *primer.Values, args ...string) *captain.Command { []*captain.Argument{}, func(ccmd *captain.Command, args []string) error { if len(args) > 0 && (args[0] == "-h" || args[0] == "--help") { - prime.Output().Print(ccmd.UsageText()) + prime.Output().Print(ccmd.Help()) return nil } else if len(args) > 0 && (args[0] == "-v" || args[0] == "--verbose" || args[0] == "--") { if len(args) > 1 { diff --git a/internal/assets/contents/usage.tpl b/internal/assets/contents/usage.tpl index 8110478bbb..9efc639d0d 100644 --- a/internal/assets/contents/usage.tpl +++ b/internal/assets/contents/usage.tpl @@ -66,4 +66,4 @@ To access the list of full commands, including unstable features still in beta, WARNING: You have access to all State Tool commands, including unstable features still in beta, in order to hide these features run: "state config set optin.unstable false" -{{- end}} \ No newline at end of file +{{- end}} diff --git a/internal/captain/command.go b/internal/captain/command.go index 2efdb298fb..aa9854b030 100644 --- a/internal/captain/command.go +++ b/internal/captain/command.go @@ -209,7 +209,7 @@ func (c *Command) UsageText() string { } func (c *Command) Help() string { - return fmt.Sprintf("%s\n\n%s", c.cobra.Short, c.UsageText()) + return strings.TrimRightFunc(fmt.Sprintf("%s\n\n%s", c.cobra.Short, c.UsageText()), unicode.IsSpace) } func (c *Command) ShortDescription() string { @@ -852,7 +852,7 @@ func (cmd *Command) Usage() error { return errs.Wrap(err, "Unable to write to cobra outWriter") } } else { - cmd.out.Print(out.String()) + cmd.out.Print(strings.TrimRightFunc(out.String(), unicode.IsSpace)) } return nil