From 5effa6288cb88f995c5113a0a265d56e7ce3e96e Mon Sep 17 00:00:00 2001 From: Tim Soethout Date: Thu, 26 Feb 2026 13:31:55 +0000 Subject: [PATCH 1/5] fix: simplify help command visibility logic and add test for hidden help command --- help.go | 3 +-- help_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/help.go b/help.go index 37b1091126..c5a993fd90 100644 --- a/help.go +++ b/help.go @@ -124,8 +124,7 @@ func helpCommandAction(ctx context.Context, cmd *Command) error { } // Case 3, 5 - if (len(cmd.Commands) == 1 && !cmd.HideHelp) || - (len(cmd.Commands) == 0 && cmd.HideHelp) { + if len(cmd.VisibleCommands()) == 0 { tmpl := cmd.CustomHelpTemplate if tmpl == "" { diff --git a/help_test.go b/help_test.go index fad4242128..3f10333945 100644 --- a/help_test.go +++ b/help_test.go @@ -797,6 +797,52 @@ GLOBAL OPTIONS: assert.Contains(t, output.String(), expected, "expected output to include global options") } +func TestShowSubcommandHelp_GlobalOptions_HideHelpCommand(t *testing.T) { + cmd := &Command{ + HideHelpCommand: true, + Flags: []Flag{ + &StringFlag{ + Name: "foo", + }, + }, + Commands: []*Command{ + { + Name: "frobbly", + Flags: []Flag{ + &StringFlag{ + Name: "bar", + Local: true, + }, + }, + Action: func(context.Context, *Command) error { + return nil + }, + }, + }, + } + + output := &bytes.Buffer{} + cmd.Writer = output + + _ = cmd.Run(buildTestContext(t), []string{"foo", "frobbly", "--help"}) + + expected := `NAME: + foo frobbly + +USAGE: + foo frobbly [options] + +OPTIONS: + --bar string + --help, -h show help + +GLOBAL OPTIONS: + --foo string +` + + assert.Contains(t, output.String(), expected, "expected output to include global options") +} + func TestShowSubcommandHelp_SubcommandUsageText(t *testing.T) { cmd := &Command{ Commands: []*Command{ From 87c262304994f31519d46b59cd5836a13ff3630b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Feb 2026 19:31:03 +0000 Subject: [PATCH 2/5] Initial plan From d6047e03146dde220284fe4b054d03384d0a9316 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Feb 2026 19:35:44 +0000 Subject: [PATCH 3/5] fix(test): set HideHelpCommand on leaf subcommand to properly validate fix Co-authored-by: TimSoethout <593132+TimSoethout@users.noreply.github.com> --- docs/go.mod | 6 ------ docs/go.sum | 12 +----------- help_test.go | 4 ++-- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/docs/go.mod b/docs/go.mod index 80ac54b0c4..c7f0d40768 100644 --- a/docs/go.mod +++ b/docs/go.mod @@ -8,9 +8,3 @@ require ( github.com/urfave/cli-altsrc/v3 v3.0.1 github.com/urfave/cli/v3 v3.1.1 ) - -require ( - github.com/BurntSushi/toml v1.5.0 // indirect - github.com/stretchr/testify v1.11.1 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/docs/go.sum b/docs/go.sum index 8127db6371..97ad2164f9 100644 --- a/docs/go.sum +++ b/docs/go.sum @@ -1,20 +1,10 @@ -github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= -github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= -github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= -github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -github.com/urfave/cli-altsrc/v3 v3.0.0-alpha2 h1:j4SaBpPB8++L0c0KuTnz/Yus3UQoWJ54hQjhIMW8rCM= -github.com/urfave/cli-altsrc/v3 v3.0.0-alpha2/go.mod h1:Q79oyIY/z4jtzIrKEK6MUeWC7/szGr46x4QdOaOAIWc= github.com/urfave/cli-altsrc/v3 v3.0.1 h1:v+gHk59syLk8ao9rYybZs43+D5ut/gzj0omqQ1XYl8k= github.com/urfave/cli-altsrc/v3 v3.0.1/go.mod h1:8UtsKKcxFVzvaoySFPfvQOk413T+IXJhaCWyyoPW3yM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/help_test.go b/help_test.go index 3f10333945..6a11bd9e19 100644 --- a/help_test.go +++ b/help_test.go @@ -799,7 +799,6 @@ GLOBAL OPTIONS: func TestShowSubcommandHelp_GlobalOptions_HideHelpCommand(t *testing.T) { cmd := &Command{ - HideHelpCommand: true, Flags: []Flag{ &StringFlag{ Name: "foo", @@ -807,7 +806,8 @@ func TestShowSubcommandHelp_GlobalOptions_HideHelpCommand(t *testing.T) { }, Commands: []*Command{ { - Name: "frobbly", + Name: "frobbly", + HideHelpCommand: true, Flags: []Flag{ &StringFlag{ Name: "bar", From d895eca40651389faff33eddbe2f2d2be741e02f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Feb 2026 21:00:02 +0000 Subject: [PATCH 4/5] Remove docs/go.mod and docs/go.sum (not relevant to PR) Co-authored-by: TimSoethout <593132+TimSoethout@users.noreply.github.com> --- docs/go.mod | 10 ---------- docs/go.sum | 10 ---------- 2 files changed, 20 deletions(-) delete mode 100644 docs/go.mod delete mode 100644 docs/go.sum diff --git a/docs/go.mod b/docs/go.mod deleted file mode 100644 index c7f0d40768..0000000000 --- a/docs/go.mod +++ /dev/null @@ -1,10 +0,0 @@ -module github.com/urfave/cli/docs/v3 - -go 1.23.2 - -replace github.com/urfave/cli/v3 => ../ - -require ( - github.com/urfave/cli-altsrc/v3 v3.0.1 - github.com/urfave/cli/v3 v3.1.1 -) diff --git a/docs/go.sum b/docs/go.sum deleted file mode 100644 index 97ad2164f9..0000000000 --- a/docs/go.sum +++ /dev/null @@ -1,10 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -github.com/urfave/cli-altsrc/v3 v3.0.1 h1:v+gHk59syLk8ao9rYybZs43+D5ut/gzj0omqQ1XYl8k= -github.com/urfave/cli-altsrc/v3 v3.0.1/go.mod h1:8UtsKKcxFVzvaoySFPfvQOk413T+IXJhaCWyyoPW3yM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From f5d0884435b62dcd552f1b4331918f516b5a85a4 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Feb 2026 22:15:23 +0100 Subject: [PATCH 5/5] Restore docs/go.mod and docs/go.sum (#5) * Initial plan * Restore docs/go.mod and docs/go.sum to original content Co-authored-by: TimSoethout <593132+TimSoethout@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: TimSoethout <593132+TimSoethout@users.noreply.github.com> --- docs/go.mod | 16 ++++++++++++++++ docs/go.sum | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 docs/go.mod create mode 100644 docs/go.sum diff --git a/docs/go.mod b/docs/go.mod new file mode 100644 index 0000000000..80ac54b0c4 --- /dev/null +++ b/docs/go.mod @@ -0,0 +1,16 @@ +module github.com/urfave/cli/docs/v3 + +go 1.23.2 + +replace github.com/urfave/cli/v3 => ../ + +require ( + github.com/urfave/cli-altsrc/v3 v3.0.1 + github.com/urfave/cli/v3 v3.1.1 +) + +require ( + github.com/BurntSushi/toml v1.5.0 // indirect + github.com/stretchr/testify v1.11.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/docs/go.sum b/docs/go.sum new file mode 100644 index 0000000000..8127db6371 --- /dev/null +++ b/docs/go.sum @@ -0,0 +1,20 @@ +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= +github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/urfave/cli-altsrc/v3 v3.0.0-alpha2 h1:j4SaBpPB8++L0c0KuTnz/Yus3UQoWJ54hQjhIMW8rCM= +github.com/urfave/cli-altsrc/v3 v3.0.0-alpha2/go.mod h1:Q79oyIY/z4jtzIrKEK6MUeWC7/szGr46x4QdOaOAIWc= +github.com/urfave/cli-altsrc/v3 v3.0.1 h1:v+gHk59syLk8ao9rYybZs43+D5ut/gzj0omqQ1XYl8k= +github.com/urfave/cli-altsrc/v3 v3.0.1/go.mod h1:8UtsKKcxFVzvaoySFPfvQOk413T+IXJhaCWyyoPW3yM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=