Skip to content

Commit

Permalink
Arg with default needs the square brackets (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
FollowTheProcess authored Sep 27, 2024
1 parent 0ff93a9 commit cdb7573
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,12 +579,16 @@ func defaultHelp(cmd *Command) error {
// format for the top level usage string in the help text string builder.
func writePositionalArgs(cmd *Command, s *strings.Builder) {
for _, arg := range cmd.positionalArgs {
displayName := strings.ToUpper(arg.name)
if arg.defaultValue != "" {
s.WriteString(strings.ToUpper(arg.name))
} else {
// If it has a default, it's an optional argument so wrap it
// in brackets e.g. [FILE]
s.WriteString("[")
s.WriteString(strings.ToUpper(arg.name))
s.WriteString(displayName)
s.WriteString("]")
} else {
// It's required, so just FILE
s.WriteString(displayName)
}
s.WriteString(" ")
}
Expand Down
Binary file modified docs/img/quickstart.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion testdata/TestHelp/with-named-arguments.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
A placeholder for something cool

Usage: test [OPTIONS] [SRC] DEST
Usage: test [OPTIONS] SRC [DEST]

Arguments:
src The file to copy
Expand Down

0 comments on commit cdb7573

Please sign in to comment.