Skip to content

Commit

Permalink
Merge pull request #1723 from dearchap/issue_1689
Browse files Browse the repository at this point in the history
Fix:(issue 1689) Match markdown output with help output
  • Loading branch information
dearchap authored Apr 30, 2023
2 parents c0cc5c2 + 5b9c03e commit 97e1edb
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
11 changes: 8 additions & 3 deletions docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,14 @@ func prepareFlags(
// flagDetails returns a string containing the flags metadata
func flagDetails(flag DocGenerationFlag) string {
description := flag.GetUsage()
value := flag.GetValue()
if value != "" {
description += " (default: " + value + ")"
if flag.TakesValue() {
defaultText := flag.GetDefaultText()
if defaultText == "" {
defaultText = flag.GetValue()
}
if defaultText != "" {
description += " (default: " + defaultText + ")"
}
}
return ": " + description
}
Expand Down
11 changes: 6 additions & 5 deletions fish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ func testApp() *App {
app.Name = "greet"
app.Flags = []Flag{
&StringFlag{
Name: "socket",
Aliases: []string{"s"},
Usage: "some 'usage' text",
Value: "value",
TakesFile: true,
Name: "socket",
Aliases: []string{"s"},
Usage: "some 'usage' text",
Value: "value",
DefaultText: "/some/path",
TakesFile: true,
},
&StringFlag{Name: "flag", Aliases: []string{"fl", "f"}},
&BoolFlag{
Expand Down
2 changes: 1 addition & 1 deletion testdata/expected-doc-full.man
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ app [first_arg] [second_arg]
\fB--flag, --fl, -f\fP="":

.PP
\fB--socket, -s\fP="": some 'usage' text (default: value)
\fB--socket, -s\fP="": some 'usage' text (default: /some/path)


.SH COMMANDS
Expand Down
2 changes: 1 addition & 1 deletion testdata/expected-doc-full.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ app [first_arg] [second_arg]

**--flag, --fl, -f**="":

**--socket, -s**="": some 'usage' text (default: value)
**--socket, -s**="": some 'usage' text (default: /some/path)


# COMMANDS
Expand Down
2 changes: 1 addition & 1 deletion testdata/expected-doc-no-authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ app [first_arg] [second_arg]

**--flag, --fl, -f**="":

**--socket, -s**="": some 'usage' text (default: value)
**--socket, -s**="": some 'usage' text (default: /some/path)


# COMMANDS
Expand Down
2 changes: 1 addition & 1 deletion testdata/expected-doc-no-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ app [first_arg] [second_arg]

**--flag, --fl, -f**="":

**--socket, -s**="": some 'usage' text (default: value)
**--socket, -s**="": some 'usage' text (default: /some/path)

2 changes: 1 addition & 1 deletion testdata/expected-doc-no-usagetext.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]

**--flag, --fl, -f**="":

**--socket, -s**="": some 'usage' text (default: value)
**--socket, -s**="": some 'usage' text (default: /some/path)


# COMMANDS
Expand Down

0 comments on commit 97e1edb

Please sign in to comment.