Skip to content

Commit

Permalink
Flags now show their default values (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
FollowTheProcess authored Oct 3, 2024
1 parent 869bad3 commit 2037fb9
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ tasks:
desc: Render the demo gifs
sources:
- ./docs/src/*.tape
- examples/**/*.go
- "**/*.go"
preconditions:
- sh: command -v vhs
msg: vhs not installed, see https://github.com/charmbracelet/vhs
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.
22 changes: 21 additions & 1 deletion internal/flag/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,27 @@ func (s *Set) Usage() (string, error) {
shorthand = "N/A"
}

tab.Row(" %s\t--%s\t%s\t%s\n", colour.Bold(shorthand), colour.Bold(entry.Name), entry.Value.Type(), entry.Usage)
if entry.DefaultValue != "" {
// Plain string
tab.Row(
" %s\t--%s\t%s\t%s [default %s]\n",
colour.Bold(shorthand),
colour.Bold(entry.Name),
entry.Value.Type(),
entry.Usage,
entry.DefaultValue,
)
} else {
// Empty string so use the quotes
tab.Row(
" %s\t--%s\t%s\t%s [default %q]\n",
colour.Bold(shorthand),
colour.Bold(entry.Name),
entry.Value.Type(),
entry.Usage,
entry.DefaultValue,
)
}
}

if err := tab.Flush(); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions internal/flag/testdata/TestUsage/full.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-c --count int Count things
-h --help bool Show help for test
-t --thing string Name the thing
N/A --update bool Update something
-V --version bool Show version info for test
-c --count int Count things [default 0]
-h --help bool Show help for test [default false]
-t --thing string Name the thing [default ""]
N/A --update bool Update something [default false]
-V --version bool Show version info for test [default false]
6 changes: 3 additions & 3 deletions internal/flag/testdata/TestUsage/no-shorthand.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-h --help bool Show help for test
N/A --update bool Update something
-V --version bool Show version info for test
-h --help bool Show help for test [default false]
N/A --update bool Update something [default false]
-V --version bool Show version info for test [default false]
4 changes: 2 additions & 2 deletions internal/flag/testdata/TestUsage/simple.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-h --help bool Show help for test
-V --version bool Show version info for test
-h --help bool Show help for test [default false]
-V --version bool Show version info for test [default false]
4 changes: 2 additions & 2 deletions testdata/TestHelp/default-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ A placeholder for something cool
Usage: test [OPTIONS] ARGS...

Options:
-h --help bool Show help for test
-V --version bool Show version info for test
-h --help bool Show help for test [default false]
-V --version bool Show version info for test [default false]
4 changes: 2 additions & 2 deletions testdata/TestHelp/full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ A longer, probably multiline description
Usage: test [OPTIONS] ARGS...

Options:
-h --help bool Show help for test
-V --version bool Show version info for test
-h --help bool Show help for test [default false]
-V --version bool Show version info for test [default false]
4 changes: 2 additions & 2 deletions testdata/TestHelp/no-about.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ A placeholder for something cool
Usage: test [OPTIONS] ARGS...

Options:
-h --help bool Show help for test
-V --version bool Show version info for test
-h --help bool Show help for test [default false]
-V --version bool Show version info for test [default false]
4 changes: 2 additions & 2 deletions testdata/TestHelp/subcommands-different-lengths.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Commands:
very-long-subcommand Wow so long

Options:
-h --help bool Show help for test
-V --version bool Show version info for test
-h --help bool Show help for test [default false]
-V --version bool Show version info for test [default false]

Use "test [command] -h/--help" for more information about a command.
8 changes: 4 additions & 4 deletions testdata/TestHelp/subcommands-flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Commands:
sub2 Do another thing

Options:
N/A --count int Count something
-d --delete bool Delete something
-h --help bool Show help for test
-V --version bool Show version info for test
N/A --count int Count something [default -1]
-d --delete bool Delete something [default false]
-h --help bool Show help for test [default false]
-V --version bool Show version info for test [default false]

Use "test [command] -h/--help" for more information about a command.
4 changes: 2 additions & 2 deletions testdata/TestHelp/subcommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Commands:
sub2 Do another thing

Options:
-h --help bool Show help for test
-V --version bool Show version info for test
-h --help bool Show help for test [default false]
-V --version bool Show version info for test [default false]

Use "test [command] -h/--help" for more information about a command.
4 changes: 2 additions & 2 deletions testdata/TestHelp/with-examples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ $ test do thing --now
$ test do thing --different

Options:
-h --help bool Show help for test
-V --version bool Show version info for test
-h --help bool Show help for test [default false]
-V --version bool Show version info for test [default false]
4 changes: 2 additions & 2 deletions testdata/TestHelp/with-named-arguments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Arguments:
dest Destination to copy to [default ./dest]

Options:
-h --help bool Show help for test
-V --version bool Show version info for test
-h --help bool Show help for test [default false]
-V --version bool Show version info for test [default false]

0 comments on commit 2037fb9

Please sign in to comment.