MCPcopy
hub / github.com/urfave/cli / Test_HelpCommand_ParsesFlags

Function Test_HelpCommand_ParsesFlags

help_test.go:171–194  ·  help_test.go::Test_HelpCommand_ParsesFlags

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)

Source from the content-addressed store, hash-verified

169// Previously in v3.6.2 flag pre-parsing was skipped for any command named
170// "help", causing such flags to be silently dropped.
171func 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
196func Test_Help_Custom_Flags(t *testing.T) {
197 oldFlag := HelpFlag

Callers

nothing calls this directly

Calls 3

RunMethod · 0.95
buildTestContextFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected