Skip to content

Commit

Permalink
Make trailing newline in command help more consistent.
Browse files Browse the repository at this point in the history
- Our template doesn't include a trailing newline, so add it.
- output.Print() adds a trailing newline, so strip it from our Help() function.
  • Loading branch information
mitchell-as committed Jul 31, 2024
1 parent 03c5e90 commit bf33c07
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/state/internal/cmdtree/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/assets/contents/usage.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
{{- end}}
4 changes: 2 additions & 2 deletions internal/captain/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bf33c07

Please sign in to comment.