(t *testing.T)
| 4418 | } |
| 4419 | |
| 4420 | func TestCommand_NumFlags(t *testing.T) { |
| 4421 | rootCmd := &Command{ |
| 4422 | Flags: []Flag{ |
| 4423 | &BoolFlag{ |
| 4424 | Name: "myflagGlobal", |
| 4425 | Value: true, |
| 4426 | }, |
| 4427 | }, |
| 4428 | } |
| 4429 | cmd := &Command{ |
| 4430 | Flags: []Flag{ |
| 4431 | &BoolFlag{ |
| 4432 | Name: "myflag", |
| 4433 | }, |
| 4434 | &StringFlag{ |
| 4435 | Name: "otherflag", |
| 4436 | Value: "hello world", |
| 4437 | }, |
| 4438 | }, |
| 4439 | } |
| 4440 | |
| 4441 | _ = cmd.Run(context.Background(), []string{"", "--myflag", "--otherflag=foo"}) |
| 4442 | _ = rootCmd.Run(context.Background(), []string{"", "--myflagGlobal"}) |
| 4443 | require.Equal(t, 2, cmd.NumFlags()) |
| 4444 | actualFlags := cmd.LocalFlagNames() |
| 4445 | sort.Strings(actualFlags) |
| 4446 | |
| 4447 | require.Equal(t, []string{"myflag", "otherflag"}, actualFlags) |
| 4448 | |
| 4449 | actualFlags = cmd.FlagNames() |
| 4450 | sort.Strings(actualFlags) |
| 4451 | |
| 4452 | require.Equal(t, []string{"myflag", "otherflag"}, actualFlags) |
| 4453 | |
| 4454 | cmd.parent = rootCmd |
| 4455 | lineage := cmd.Lineage() |
| 4456 | |
| 4457 | r := require.New(t) |
| 4458 | r.Equal(2, len(lineage)) |
| 4459 | r.Equal(cmd, lineage[0]) |
| 4460 | r.Equal(rootCmd, lineage[1]) |
| 4461 | } |
| 4462 | |
| 4463 | func TestCommand_Set(t *testing.T) { |
| 4464 | cmd := &Command{ |
nothing calls this directly
no test coverage detected