in awscli/customizations/commands.py [0:0]
def __call__(self, args, parsed_globals):
# args is the remaining unparsed args.
# We might be able to parse these args so we need to create
# an arg parser and parse them.
self._subcommand_table = self._build_subcommand_table()
self._arg_table = self._build_arg_table()
event = 'before-building-argument-table-parser.%s' % \
".".join(self.lineage_names)
self._session.emit(event, argument_table=self._arg_table, args=args,
session=self._session, parsed_globals=parsed_globals)
parser = ArgTableArgParser(self.arg_table, self.subcommand_table)
parsed_args, remaining = parser.parse_known_args(args)
# Unpack arguments
for key, value in vars(parsed_args).items():
cli_argument = None
# Convert the name to use dashes instead of underscore
# as these are how the parameters are stored in the
# `arg_table`.
xformed = key.replace('_', '-')
if xformed in self.arg_table:
cli_argument = self.arg_table[xformed]
value = unpack_argument(
self._session,
'custom',
self.name,
cli_argument,
value
)
# If this parameter has a schema defined, then allow plugins
# a chance to process and override its value.
if self._should_allow_plugins_override(cli_argument, value):
override = self._session\
.emit_first_non_none_response(
'process-cli-arg.%s.%s' % ('custom', self.name),
cli_argument=cli_argument, value=value, operation=None)
if override is not None:
# A plugin supplied a conversion
value = override
else:
# Unpack the argument, which is a string, into the
# correct Python type (dict, list, etc)
value = unpack_cli_arg(cli_argument, value)
self._validate_value_against_schema(
cli_argument.argument_model, value)
setattr(parsed_args, key, value)
if hasattr(parsed_args, 'help'):
self._display_help(parsed_args, parsed_globals)
elif getattr(parsed_args, 'subcommand', None) is None:
# No subcommand was specified so call the main
# function for this top level command.
if remaining:
raise ValueError("Unknown options: %s" % ','.join(remaining))
return self._run_main(parsed_args, parsed_globals)
else:
return self.subcommand_table[parsed_args.subcommand](remaining,
parsed_globals)