Skip to content

Commit

Permalink
Fixed default printing for string flags
Browse files Browse the repository at this point in the history
The special case for printing out the default for a string flag was
missing a closing paren. Updated the long-form version to quote the
default value as well.
  • Loading branch information
angrycub committed Aug 30, 2023
1 parent b5010b3 commit 201b95b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/pkg/flag/flag_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ func (f *Set) VarFlagP(i *VarFlagP) {
}

if i.Default != "" {
usage += fmt.Sprintf(" Defaults to %s.", i.Default)
if i.Value.Type() == "string" {
usage += fmt.Sprintf(" Defaults to %q.", i.Default)
} else {
usage += fmt.Sprintf(" Defaults to %s.", i.Default)
}
}

if i.EnvVar != "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/flag/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func printFlagDetail(w io.Writer, f *flag.Flag) {

if !defaultIsZeroValue(f) {
if f.Value.Type() == "string" {
fmt.Fprintf(w, " (default %q", f.DefValue)
fmt.Fprintf(w, " (default %q)", f.DefValue)
} else {
fmt.Fprintf(w, " (default %s)", f.DefValue)
}
Expand Down

0 comments on commit 201b95b

Please sign in to comment.