Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cleo/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
13 changes: 11 additions & 2 deletions cleo/inputs/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 11 additions & 1 deletion cleo/inputs/input_argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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.
Expand Down