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

Function TestCommand_UseShortOptionHandlingSubCommand

command_test.go:1330–1364  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1328}
1329
1330func TestCommand_UseShortOptionHandlingSubCommand(t *testing.T) {
1331 var one, two bool
1332 var name string
1333
1334 cmd := buildMinimalTestCommand()
1335 cmd.UseShortOptionHandling = true
1336 cmd.Commands = []*Command{
1337 {
1338 Name: "cmd",
1339 Commands: []*Command{
1340 {
1341 Name: "sub",
1342 Flags: []Flag{
1343 &BoolFlag{Name: "one", Aliases: []string{"o"}},
1344 &BoolFlag{Name: "two", Aliases: []string{"t"}},
1345 &StringFlag{Name: "name", Aliases: []string{"n"}},
1346 },
1347 Action: func(_ context.Context, cmd *Command) error {
1348 one = cmd.Bool("one")
1349 two = cmd.Bool("two")
1350 name = cmd.String("name")
1351 return nil
1352 },
1353 },
1354 },
1355 },
1356 }
1357
1358 expected := "expectedName"
1359
1360 require.NoError(t, cmd.Run(buildTestContext(t), []string{"", "cmd", "sub", "-on", expected}))
1361 require.True(t, one)
1362 require.False(t, two)
1363 require.Equal(t, expected, name)
1364}
1365
1366func TestCommand_UseShortOptionHandlingSubCommand_missing_value(t *testing.T) {
1367 cmd := buildMinimalTestCommand()

Callers

nothing calls this directly

Calls 5

buildMinimalTestCommandFunction · 0.85
buildTestContextFunction · 0.85
BoolMethod · 0.80
StringMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected