diff --git a/app_test.go b/app_test.go index 63f0fc4..f785a44 100644 --- a/app_test.go +++ b/app_test.go @@ -885,32 +885,50 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) { appCommands []Command expectedAnError bool }{ + // expectations: + // - empty input, when a required flag is present, errors and shows the flag error message { - // expectations: - // - empty input, when a required flag is present, shows the help message - // - empty input, when a required flag is present, errors and shows the flag error message testCase: "error_case_empty_input_with_required_flag", appRunInput: []string{"myCLI"}, appFlags: []Flag{StringFlag{Name: "requiredFlag", Required: true}}, expectedAnError: true, }, + // expectations: + // - inputing --help, when a required flag is present, does not error { - // expectations: - // - inputing --help, when a required flag is present, shows the help message - // - inputing --help, when a required flag is present, does not error testCase: "valid_case_help_input_with_required_flag", appRunInput: []string{"myCLI", "--help"}, appFlags: []Flag{StringFlag{Name: "requiredFlag", Required: true}}, }, { - // expectations: - // - giving optional input, when a required flag is present, shows the help message - // - giving optional input, when a required flag is present, errors and shows the flag error message + testCase: "valid_case_help_input_with_required_flag_command", + appRunInput: []string{"myCLI", "myCommand", "--help"}, + appCommands: []Command{Command{ + Name: "myCommand", + Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}}, + }}, + }, + { + testCase: "valid_case_help_input_with_required_flag_subcommand", + appRunInput: []string{"myCLI", "myCommand", "mySubCommand", "--help"}, + appCommands: []Command{Command{ + Name: "myCommand", + Subcommands: []Command{Command{ + Name: "mySubCommand", + Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}}, + }}, + }}, + }, + // expectations: + // - giving optional input, when a required flag is present, shows the help message + // - giving optional input, when a required flag is present, errors and shows the flag error message + { testCase: "error_case_optional_input_with_required_flag", appRunInput: []string{"myCLI", "--optional", "cats"}, appFlags: []Flag{StringFlag{Name: "requiredFlag", Required: true}, StringFlag{Name: "optional"}}, expectedAnError: true, }, + // valid input cases { testCase: "valid_case_required_flag_input", appRunInput: []string{"myCLI", "--requiredFlag", "cats"},