Test_HelpCommand_ParsesFlags is a regression test for #2271: flags declared on a user-supplied command named "help" must still be parsed. Previously in v3.6.2 flag pre-parsing was skipped for any command named "help", causing such flags to be silently dropped.
(t *testing.T)
| 169 | // Previously in v3.6.2 flag pre-parsing was skipped for any command named |
| 170 | // "help", causing such flags to be silently dropped. |
| 171 | func Test_HelpCommand_ParsesFlags(t *testing.T) { |
| 172 | var parsed string |
| 173 | |
| 174 | cmd := &Command{ |
| 175 | Name: "app", |
| 176 | Commands: []*Command{ |
| 177 | { |
| 178 | Name: "help", |
| 179 | Flags: []Flag{ |
| 180 | &StringFlag{Name: "topic", Aliases: []string{"t"}}, |
| 181 | }, |
| 182 | Action: func(_ context.Context, c *Command) error { |
| 183 | parsed = c.String("topic") |
| 184 | return nil |
| 185 | }, |
| 186 | }, |
| 187 | }, |
| 188 | } |
| 189 | |
| 190 | err := cmd.Run(buildTestContext(t), []string{"app", "help", "--topic", "foo"}) |
| 191 | require.NoError(t, err) |
| 192 | assert.Equal(t, "foo", parsed, |
| 193 | "expected --topic flag on help subcommand to be parsed") |
| 194 | } |
| 195 | |
| 196 | func Test_Help_Custom_Flags(t *testing.T) { |
| 197 | oldFlag := HelpFlag |
nothing calls this directly
no test coverage detected