From 57cbb2dd6606dad21991b1315900e4e281f40874 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Mon, 17 Apr 2023 10:01:01 -0400 Subject: [PATCH 1/4] Fix:(issue_1689) Let markdown output behave similar to cli help output --- docs.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs.go b/docs.go index 8b1c9c8a2c..6cd0624aea 100644 --- a/docs.go +++ b/docs.go @@ -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 } From a78aa8cfa680c576c326c17c28b15dd9636b8df3 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Mon, 17 Apr 2023 10:06:31 -0400 Subject: [PATCH 2/4] Update tests --- fish_test.go | 11 ++++++----- testdata/expected-doc-full.man | 2 +- testdata/expected-doc-full.md | 2 +- testdata/expected-doc-no-authors.md | 2 +- testdata/expected-doc-no-commands.md | 2 +- testdata/expected-doc-no-usagetext.md | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/fish_test.go b/fish_test.go index d28b0d4202..da68164174 100644 --- a/fish_test.go +++ b/fish_test.go @@ -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: "svalue", + TakesFile: true, }, &StringFlag{Name: "flag", Aliases: []string{"fl", "f"}}, &BoolFlag{ diff --git a/testdata/expected-doc-full.man b/testdata/expected-doc-full.man index a2131f0f55..bfae3a175c 100644 --- a/testdata/expected-doc-full.man +++ b/testdata/expected-doc-full.man @@ -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: svalue) .SH COMMANDS diff --git a/testdata/expected-doc-full.md b/testdata/expected-doc-full.md index 80ff6a7a68..8f79818ba8 100644 --- a/testdata/expected-doc-full.md +++ b/testdata/expected-doc-full.md @@ -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: svalue) # COMMANDS diff --git a/testdata/expected-doc-no-authors.md b/testdata/expected-doc-no-authors.md index 80ff6a7a68..8f79818ba8 100644 --- a/testdata/expected-doc-no-authors.md +++ b/testdata/expected-doc-no-authors.md @@ -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: svalue) # COMMANDS diff --git a/testdata/expected-doc-no-commands.md b/testdata/expected-doc-no-commands.md index 4db2a375ec..3e285f2d42 100644 --- a/testdata/expected-doc-no-commands.md +++ b/testdata/expected-doc-no-commands.md @@ -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: svalue) diff --git a/testdata/expected-doc-no-usagetext.md b/testdata/expected-doc-no-usagetext.md index d09b69fb6b..8354f4c629 100644 --- a/testdata/expected-doc-no-usagetext.md +++ b/testdata/expected-doc-no-usagetext.md @@ -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: svalue) # COMMANDS From d31582cdebb7e91a76223dc8357d8be8277726d0 Mon Sep 17 00:00:00 2001 From: dearchap Date: Wed, 26 Apr 2023 15:16:20 -0400 Subject: [PATCH 3/4] Update fish_test.go Co-authored-by: Anatoli Babenia --- fish_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fish_test.go b/fish_test.go index da68164174..f74b55aceb 100644 --- a/fish_test.go +++ b/fish_test.go @@ -31,7 +31,7 @@ func testApp() *App { Aliases: []string{"s"}, Usage: "some 'usage' text", Value: "value", - DefaultText: "svalue", + DefaultText: "/some/path", TakesFile: true, }, &StringFlag{Name: "flag", Aliases: []string{"fl", "f"}}, From 5b9c03e5cd963a5c4abc6db5286e09569a1db365 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Wed, 26 Apr 2023 15:20:38 -0400 Subject: [PATCH 4/4] Change from code review --- testdata/expected-doc-full.man | 2 +- testdata/expected-doc-full.md | 2 +- testdata/expected-doc-no-authors.md | 2 +- testdata/expected-doc-no-commands.md | 2 +- testdata/expected-doc-no-usagetext.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/testdata/expected-doc-full.man b/testdata/expected-doc-full.man index bfae3a175c..615f8d6af4 100644 --- a/testdata/expected-doc-full.man +++ b/testdata/expected-doc-full.man @@ -47,7 +47,7 @@ app [first_arg] [second_arg] \fB--flag, --fl, -f\fP="": .PP -\fB--socket, -s\fP="": some 'usage' text (default: svalue) +\fB--socket, -s\fP="": some 'usage' text (default: /some/path) .SH COMMANDS diff --git a/testdata/expected-doc-full.md b/testdata/expected-doc-full.md index 8f79818ba8..65c3fda162 100644 --- a/testdata/expected-doc-full.md +++ b/testdata/expected-doc-full.md @@ -28,7 +28,7 @@ app [first_arg] [second_arg] **--flag, --fl, -f**="": -**--socket, -s**="": some 'usage' text (default: svalue) +**--socket, -s**="": some 'usage' text (default: /some/path) # COMMANDS diff --git a/testdata/expected-doc-no-authors.md b/testdata/expected-doc-no-authors.md index 8f79818ba8..65c3fda162 100644 --- a/testdata/expected-doc-no-authors.md +++ b/testdata/expected-doc-no-authors.md @@ -28,7 +28,7 @@ app [first_arg] [second_arg] **--flag, --fl, -f**="": -**--socket, -s**="": some 'usage' text (default: svalue) +**--socket, -s**="": some 'usage' text (default: /some/path) # COMMANDS diff --git a/testdata/expected-doc-no-commands.md b/testdata/expected-doc-no-commands.md index 3e285f2d42..9f918fe14f 100644 --- a/testdata/expected-doc-no-commands.md +++ b/testdata/expected-doc-no-commands.md @@ -28,5 +28,5 @@ app [first_arg] [second_arg] **--flag, --fl, -f**="": -**--socket, -s**="": some 'usage' text (default: svalue) +**--socket, -s**="": some 'usage' text (default: /some/path) diff --git a/testdata/expected-doc-no-usagetext.md b/testdata/expected-doc-no-usagetext.md index 8354f4c629..50a87d5540 100644 --- a/testdata/expected-doc-no-usagetext.md +++ b/testdata/expected-doc-no-usagetext.md @@ -28,7 +28,7 @@ greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...] **--flag, --fl, -f**="": -**--socket, -s**="": some 'usage' text (default: svalue) +**--socket, -s**="": some 'usage' text (default: /some/path) # COMMANDS