| 4328 | } |
| 4329 | |
| 4330 | func TestCommand_IsSet(t *testing.T) { |
| 4331 | cmd := &Command{ |
| 4332 | Name: "frob", |
| 4333 | Flags: []Flag{ |
| 4334 | &BoolFlag{ |
| 4335 | Name: "one-flag", |
| 4336 | }, |
| 4337 | &BoolFlag{ |
| 4338 | Name: "two-flag", |
| 4339 | }, |
| 4340 | &StringFlag{ |
| 4341 | Name: "three-flag", |
| 4342 | Value: "hello world", |
| 4343 | }, |
| 4344 | }, |
| 4345 | } |
| 4346 | pCmd := &Command{ |
| 4347 | Name: "root", |
| 4348 | Flags: []Flag{ |
| 4349 | &BoolFlag{ |
| 4350 | Name: "top-flag", |
| 4351 | Value: true, |
| 4352 | }, |
| 4353 | }, |
| 4354 | Commands: []*Command{ |
| 4355 | cmd, |
| 4356 | }, |
| 4357 | } |
| 4358 | |
| 4359 | r := require.New(t) |
| 4360 | |
| 4361 | r.NoError(pCmd.Run(context.Background(), []string{"foo", "frob", "--one-flag", "--top-flag", "--two-flag", "--three-flag", "dds"})) |
| 4362 | |
| 4363 | r.True(cmd.IsSet("one-flag")) |
| 4364 | r.True(cmd.IsSet("two-flag")) |
| 4365 | r.True(cmd.IsSet("three-flag")) |
| 4366 | r.True(cmd.IsSet("top-flag")) |
| 4367 | r.False(cmd.IsSet("bogus")) |
| 4368 | } |
| 4369 | |
| 4370 | // XXX Corresponds to hack in context.IsSet for flags with EnvVar field |
| 4371 | // Should be moved to `flag_test` in v2 |