diff --git a/cleo/application.py b/cleo/application.py index 8a1e0323..a1b49841 100644 --- a/cleo/application.py +++ b/cleo/application.py @@ -528,7 +528,7 @@ def get_command_name(self, input_): def get_default_input_definition(self): return InputDefinition([ - InputArgument('command', InputArgument.REQUIRED, 'The command to execute'), + InputArgument('command', InputArgument.REQUIRED, 'The command to execute', is_application_argument=True), InputOption('--help', '-h', InputOption.VALUE_NONE, 'Display this help message'), InputOption('--quiet', '-q', InputOption.VALUE_NONE, 'Do not output any message'), diff --git a/cleo/inputs/input.py b/cleo/inputs/input.py index de2ac554..adc28dfa 100644 --- a/cleo/inputs/input.py +++ b/cleo/inputs/input.py @@ -64,8 +64,17 @@ def parse(self): raise NotImplementedError() def validate(self): - if len(self.get_arguments()) < self.definition.get_argument_required_count(): - raise MissingArguments('Not enough arguments') + current_args = self.get_arguments() + + required_arguments = [ + argument + for argument in self.definition.get_arguments() + if argument.is_required() and not argument.is_application_argument() + ] + + for argument in required_arguments: + if current_args.get(argument.get_name()) is None: + raise MissingArguments('Not enough arguments') self.validate_arguments() self.validate_options() diff --git a/cleo/inputs/input_argument.py b/cleo/inputs/input_argument.py index 3cfd5313..d40e1a08 100644 --- a/cleo/inputs/input_argument.py +++ b/cleo/inputs/input_argument.py @@ -34,7 +34,7 @@ class InputArgument(object): IS_LIST = 4 def __init__(self, name, mode=None, - description='', default=None, validator=None): + description='', default=None, validator=None, is_application_argument=False): """ Constructor @@ -58,6 +58,7 @@ def __init__(self, name, mode=None, self._mode = mode self._description = description or '' self._validator = VALIDATORS.get(validator) + self._is_application_argument = is_application_argument self.set_default(default) @@ -88,6 +89,15 @@ def is_list(self): """ return self.__class__.IS_LIST == (self.__class__.IS_LIST & self._mode) + def is_application_argument(self): + """ + Returns True if the argument is from application + + :return: True if argument is from application, False otherwise + :rtype: bool + """ + return self._is_application_argument + def set_default(self, default=None): """ Sets the default value.