def test_register_cli_argument_with_overrides(self): cl = CLICommandsLoader(self.mock_ctx) global_vm_name_type = CLIArgumentType( options_list=('--foo', '-f'), metavar='FOO', help='foo help' ) derived_vm_name_type = CLIArgumentType(base_type=global_vm_name_type, help='first modification') with CommandSuperGroup(__name__, cl, '{}#{{}}'.format(__name__)) as sg: with sg.group('test') as g: g.command('sample-get', '{}.{}'.format(TestCommandRegistration.__name__, TestCommandRegistration.sample_command_handler.__name__)) g.command('command sample-get-1', '{}.{}'.format(TestCommandRegistration.__name__, TestCommandRegistration.sample_command_handler.__name__)) g.command('command sample-get-2', '{}.{}'.format(TestCommandRegistration.__name__, TestCommandRegistration.sample_command_handler.__name__)) with ArgumentsContext(cl, 'test') as ac: ac.argument('resource_name', global_vm_name_type) with ArgumentsContext(cl, 'test command') as ac: ac.argument('resource_name', derived_vm_name_type) with ArgumentsContext(cl, 'test command sample-get-2') as ac: ac.argument('resource_name', derived_vm_name_type, help='second modification') cl.load_arguments('test sample-get') cl.load_arguments('test command sample-get-1') cl.load_arguments('test command sample-get-2') self.assertEqual(len(cl.command_table), 3, 'We expect exactly three commands in the command table') command1 = cl.command_table['test sample-get'].arguments['resource_name'] command2 = cl.command_table['test command sample-get-1'].arguments['resource_name'] command3 = cl.command_table['test command sample-get-2'].arguments['resource_name'] self.assertTrue(command1.options['help'] == 'foo help') self.assertTrue(command2.options['help'] == 'first modification') self.assertTrue(command3.options['help'] == 'second modification')
def load_command_table(self, args): #pylint: disable=too-many-statements """Load all Service Fabric commands""" with CommandSuperGroup(__name__, self, 'bkpctl.custom_backup_explorer#{}' ) as super_group: with super_group.group('query') as group: group.command('metadata', 'query_metadata') group.command('collection', 'query_collection') with super_group.group('get') as group: group.command('transactions', 'get_transactions') with super_group.group('update') as group: group.command('collection', 'add_transaction') with super_group.group('backup') as group: group.command('partition', 'trigger_backup') with ArgumentsContext(self, 'query') as ac: ac.argument('name', options_list=['--name', '-n']) with ArgumentsContext(self, 'update') as ac: ac.argument('collectiontype', options_list=['--collectiontype', '-ct']) ac.argument('operation', options_list=['--operation', '-op']) ac.argument('collection', options_list=['--collection', '-c']) ac.argument('partition_id', options_list=['--partitionId', '-p']) ac.argument('etag', options_list=['--etag', '-e']) ac.argument('key', options_list=['--key', '-k']) ac.argument('value', options_list=['--value', '-v']) with ArgumentsContext(self, 'backup') as ac: ac.argument('typeOfBackup', options_list=['--type', '-t']) ac.argument('path', options_list=['--path', '-p']) ac.argument('timeout', options_list=['--timeout', '-to']) ac.argument('cancellationInSecs', options_list=['--cancellationAfter', '-ca']) return OrderedDict(self.command_table)
def load_team_arguments(cli_command_loader): with ArgumentsContext(cli_command_loader, 'login') as ac: ac.argument('team_instance', options_list=('--instance', '-i')) ac.argument('detect', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) with ArgumentsContext(cli_command_loader, 'logout') as ac: ac.argument('team_instance', options_list=('--instance', '-i')) ac.argument('detect', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) with ArgumentsContext(cli_command_loader, 'configure') as ac: ac.argument('defaults', options_list=('--defaults', '-d'), nargs='*') with ArgumentsContext(cli_command_loader, 'project') as ac: ac.argument('team_instance', options_list=('--instance', '-i')) ac.argument('process', options_list=('--process', '-p')) ac.argument('source_control', options_list=('--source-control', '-s'), **enum_choice_list(_SOURCE_CONTROL_VALUES)) ac.argument('description', options_list=('--description', '-d')) ac.argument('detect', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) ac.argument('state', **enum_choice_list(_STATE_VALUES)) ac.argument('project_id', options_list='--id') with ArgumentsContext(cli_command_loader, 'configure') as ac: ac.argument('collect_telemetry', **enum_choice_list(_YES_NO_SWITCH_VALUES)) ac.argument('enable_log_file', **enum_choice_list(_YES_NO_SWITCH_VALUES)) ac.argument('use_git_aliases', **enum_choice_list(_YES_NO_SWITCH_VALUES)) ac.argument('suppress_update_message', **enum_choice_list(_YES_NO_SWITCH_VALUES)) ac.argument('default_output', **enum_choice_list(_OUTPUT_VALUES)) ac.argument('list_config', options_list=('--list', '-l'))
def load_arguments(self, command): with ArgumentsContext(self, 'serve') as ac: ac.argument('env_grpc_port', default=False, required=False) ac.argument('grpc_port', default=3001, type=int, required=False) with ArgumentsContext(self, 'analyze') as ac: ac.argument('env_grpc_port', default=False, required=False) ac.argument('grpc_port', default=3001, type=int, required=False) ac.argument('text', required=True) ac.argument('fields', nargs='*', required=True) super(CommandsLoader, self).load_arguments(command)
def load_admin_arguments(cli_command_loader): with ArgumentsContext(cli_command_loader, 'admin') as ac: ac.argument('team_instance', options_list=['-i', '--instance']) with ArgumentsContext(cli_command_loader, 'admin user') as ac: ac.argument('user_id', options_list='--id') ac.argument('access_level', **enum_choice_list(_ORGANIZATION_LICENSE_TYPES_FOR_ADD)) with ArgumentsContext(cli_command_loader, 'admin banner') as ac: ac.argument('message', options_list=['-m', '--message']) ac.argument('message_id', options_list='--id') ac.argument('banner_type', options_list=['-t', '--type'], **enum_choice_list(_TYPE_FOR_BANNER))
def test_with_command(command, target_value): self._set_command_name(command) with ArgumentsContext(cl, 'test') as c: c.argument('resource_name', base_type) with ArgumentsContext(cl, 'test command') as c: c.argument('resource_name', derived_type) with ArgumentsContext(cl, 'test command sample-get-2') as c: c.argument('resource_name', derived_type, help='help3') cl.load_arguments(command) command1 = cl.command_table[command].arguments['resource_name'] self.assertEqual(command1.options['help'], target_value)
def load_arguments(self, command): for scope in ['n1', 'group alpha', 'group beta']: with ArgumentsContext(self, scope) as c: c.argument('arg1', options_list=['--arg', '-a'], required=False, type=int, choices=[1, 2, 3]) c.argument('arg2', options_list=['-b'], required=True, choices=['a', 'b', 'c']) for scope in ['n4', 'n5']: with ArgumentsContext(self, scope) as c: c.argument('arg1', options_list=['--foobar']) c.argument('arg2', options_list=['--foobar2'], required=True) c.argument('arg3', options_list=['--foobar3'], help='the foobar3') super(HelpTestCommandLoader, self).load_arguments(command)
def load_work_arguments(cli_command_loader): with ArgumentsContext(cli_command_loader, 'work') as ac: ac.argument('open_browser', options_list='--open') ac.argument('project', options_list=('--project', '-p')) ac.argument('team_instance', options_list=('--instance', '-i')) ac.argument('detect', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) with ArgumentsContext(cli_command_loader, 'work item') as ac: ac.argument('work_item_id', type=int, options_list='--id') ac.argument('work_item_type', type=str, options_list='--type') ac.argument('fields', nargs='*', options_list=('--fields', '-f')) with ArgumentsContext(cli_command_loader, 'work item query') as ac: ac.argument('query_id', type=str, options_list='--id')
def test_register_ignore_cli_argument(self): cl = CLICommandsLoader(self.mock_ctx) command_name = 'test register sample-command' with CommandGroup(cl, 'test register', '{}#{{}}'.format(__name__)) as g: g.command('sample-command', '{}.{}'.format(TestCommandRegistration.__name__, TestCommandRegistration.sample_command_handler.__name__)) with ArgumentsContext(cl, 'test register') as ac: ac.argument('resource_name', options_list=['--this']) with ArgumentsContext(cl, 'test register sample-command') as ac: ac.ignore('resource_name') ac.argument('opt_param', options_list=['--this']) cl.load_arguments(command_name) self.assertNotEqual(cl.command_table[command_name].arguments['resource_name'].options_list, cl.command_table[command_name].arguments['opt_param'].options_list, "Name conflict in options list")
def load_arguments(self, command): with ArgumentsContext(self, 'task') as args_context: args_context.argument('name', type=str, default='__current_dir') with ArgumentsContext(self, 'task parse') as args_context: args_context.argument('lang', type=str, default=get_default_language()) with ArgumentsContext(self, 'task test') as args_context: args_context.argument('lang', type=str, default=get_default_language()) with ArgumentsContext(self, 'task testcase') as args_context: args_context.argument('with-output', default=False) super(EgorCommandLoader, self).load_arguments(command)
def load_code_arguments(cli_command_loader): with ArgumentsContext(cli_command_loader, 'code') as ac: ac.argument('open_browser', options_list='--open') ac.argument('project', options_list=('--project', '-p')) ac.argument('team_instance', options_list=('--instance', '-i')) ac.argument('reviewers', nargs='*') ac.argument('detect', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) with ArgumentsContext(cli_command_loader, 'code pr') as ac: ac.argument('description', type=str, options_list=('--description', '-d'), nargs='*') ac.argument('pull_request_id', type=int, options_list='--id') ac.argument('repository', options_list=('--repository', '-r')) ac.argument('source_branch', options_list=('--source-branch', '-s')) ac.argument('target_branch', options_list=('--target-branch', '-t')) ac.argument('title', type=str) with ArgumentsContext(cli_command_loader, 'code pr create') as ac: ac.argument('work_items', nargs='*') with ArgumentsContext(cli_command_loader, 'code pr list') as ac: ac.argument('status', **enum_choice_list(_PR_STATUS_VALUES)) with ArgumentsContext(cli_command_loader, 'code pr reviewers') as ac: ac.argument('reviewers', nargs='+') with ArgumentsContext(cli_command_loader, 'code pr work-items') as ac: ac.argument('work_items', nargs='+') with ArgumentsContext(cli_command_loader, 'code pr update') as ac: ac.argument('auto_complete', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) ac.argument('squash', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) ac.argument('delete_source_branch', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) ac.argument('bypass_policy', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) ac.argument('transition_work_items', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) with ArgumentsContext(cli_command_loader, 'code pr policies') as ac: ac.argument('evaluation_id', options_list=('--evaluation-id', '-e')) with ArgumentsContext(cli_command_loader, 'code pr set-vote') as ac: ac.argument('vote', **enum_choice_list(_VOTE_VALUES)) with ArgumentsContext(cli_command_loader, 'code repo') as ac: ac.argument('repo_id', options_list='--id')
def load_arguments(self, command): with ArgumentsContext(self, 'foo') as c: c.argument('my_param', options_list='--my-param', configured_default='param', required=required) super(TestCommandsLoader, self).load_arguments(command)
def test_override_using_register_cli_argument(self): def sample_sdk_method(param_a): # pylint: disable=unused-argument pass def test_validator_completer(): pass cl = CLICommandsLoader(self.mock_ctx) command_name = self._set_command_name( 'override_using_register_cli_argument foo') setattr(sys.modules[__name__], sample_sdk_method.__name__, sample_sdk_method) with CommandGroup(cl, 'override_using_register_cli_argument', '{}#{{}}'.format(__name__)) as g: g.command('foo', sample_sdk_method.__name__) with ArgumentsContext(cl, 'override_using_register_cli_argument') as ac: ac.argument('param_a', options_list=('--overridden', '-r'), validator=test_validator_completer, completer=test_validator_completer, required=False) cl.load_arguments(command_name) command_metadata = cl.command_table[command_name] self.assertEqual(len(command_metadata.arguments), 1, 'We expected exactly 1 arguments') actual_arg = command_metadata.arguments['param_a'] self.assertEqual(actual_arg.options_list, ('--overridden', '-r')) self.assertEqual(actual_arg.validator, test_validator_completer) self.assertEqual(actual_arg.completer, test_validator_completer) self.assertFalse(actual_arg.options['required'])
def test_register_extra_cli_argument(self): cl = CLICommandsLoader(self.mock_ctx) command_name = self._set_command_name('test register sample-command') with CommandGroup(cl, 'test register', '{}#{{}}'.format(__name__)) as g: g.command( 'sample-command', '{}.{}'.format( TestCommandRegistration.__name__, TestCommandRegistration.sample_command_handler.__name__)) with ArgumentsContext(cl, command_name) as ac: ac.extra('added_param', options_list=('--added-param', ), metavar='ADDED', help='Just added this right now!', required=True) cl.load_arguments(command_name) self.assertEqual(len(cl.command_table), 1, 'We expect exactly one command in the command table') command_metadata = cl.command_table[command_name] self.assertEqual(len(command_metadata.arguments), 5, 'We expected exactly 5 arguments') some_expected_arguments = { 'added_param': CLIArgumentType(dest='added_param', required=True) } for probe in some_expected_arguments: existing = next(arg for arg in command_metadata.arguments if arg == probe) contains_subset = _dictContainsSubset( some_expected_arguments[existing].settings, command_metadata.arguments[existing].options) self.assertTrue(contains_subset)
def load_command_table(self, args): #pylint: disable=too-many-statements """Load all Service Fabric commands""" # Need an empty client for the select and upload operations with CommandSuperGroup(__name__, self, 'rcctl.custom_cluster#{}') as super_group: with super_group.group('cluster') as group: group.command('select', 'select') with CommandSuperGroup(__name__, self, 'rcctl.custom_reliablecollections#{}', client_factory=client_create) as super_group: with super_group.group('dictionary') as group: group.command('query', 'query_reliabledictionary') group.command('execute', 'execute_reliabledictionary') group.command('schema', 'get_reliabledictionary_schema') group.command('list', 'get_reliabledictionary_list') group.command('type-schema', 'get_reliabledictionary_type_schema') with ArgumentsContext(self, 'dictionary') as ac: ac.argument('application_name', options_list=['--application-name', '-a']) ac.argument('service_name', options_list=['--service-name', '-s']) ac.argument('dictionary_name', options_list=['--dictionary-name', '-d']) ac.argument('output_file', options_list=['--output-file', '-out']) ac.argument('input_file', options_list=['--input-file', '-in']) ac.argument('query_string', options_list=['--query-string', '-q']) ac.argument('type_name', options_list=['--type-name', '-t']) return OrderedDict(self.command_table)
def test_register_cli_argument(self): cl = CLICommandsLoader(self.mock_ctx) command_name = 'test register sample-command' with CommandSuperGroup(__name__, cl, '{}#{{}}'.format(__name__)) as sg: with sg.group('test register') as g: g.command('sample-command', '{}.{}'.format(TestCommandRegistration.__name__, TestCommandRegistration.sample_command_handler.__name__)) with ArgumentsContext(cl, command_name) as ac: ac.argument('resource_name', CLIArgumentType( options_list=('--wonky-name', '-n'), metavar='RNAME', help='Completely WONKY name...', required=False )) cl.load_arguments(command_name) self.assertEqual(len(cl.command_table), 1, 'We expect exactly one command in the command table') command_metadata = cl.command_table[command_name] self.assertEqual(len(command_metadata.arguments), 4, 'We expected exactly 4 arguments') some_expected_arguments = { 'group_name': CLIArgumentType(dest='group_name', required=True), 'resource_name': CLIArgumentType(dest='resource_name', required=False), } for probe in some_expected_arguments: existing = next(arg for arg in command_metadata.arguments if arg == probe) contains_subset = _dictContainsSubset(some_expected_arguments[existing].settings, command_metadata.arguments[existing].options) self.assertTrue(contains_subset) self.assertEqual(command_metadata.arguments['resource_name'].options_list, ('--wonky-name', '-n'))
def load_arguments(self, command): enable_trace_pii = os.environ.get('ENABLE_TRACE_PII') if enable_trace_pii is None: enable_trace_pii = False with ArgumentsContext(self, 'serve') as ac: ac.argument('env_grpc_port', default=False, required=False) ac.argument('enable_trace_pii', default=enable_trace_pii, required=False) ac.argument('grpc_port', default=3001, type=int, required=False) with ArgumentsContext(self, 'analyze') as ac: ac.argument('env_grpc_port', default=False, required=False) ac.argument('grpc_port', default=3001, type=int, required=False) ac.argument('text', required=True) ac.argument('fields', nargs='*', required=True) super(CommandsLoader, self).load_arguments(command)
def load_arguments(self, command): with ArgumentsContext(self, 'arg-test') as c: c.argument('arg1', help='Arg1', is_preview=True, action=LoggerAction) super(PreviewTestCommandLoader, self).load_arguments(command)
def load_build_arguments(cli_command_loader): with ArgumentsContext(cli_command_loader, 'build') as ac: ac.argument('open_browser', options_list='--open') ac.argument('project', options_list=('--project', '-p')) ac.argument('team_instance', options_list=('--instance', '-i')) ac.argument('detect', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) with ArgumentsContext(cli_command_loader, 'build list') as ac: ac.argument('definition_ids', nargs='*', type=int) ac.argument('tags', nargs='*') with ArgumentsContext(cli_command_loader, 'build queue') as ac: ac.argument('definition_id', type=int) ac.argument('variables', nargs='*') with ArgumentsContext(cli_command_loader, 'build show') as ac: ac.argument('build_id', options_list='--id', type=int) with ArgumentsContext(cli_command_loader, 'build definition show') as ac: ac.argument('definition_id', options_list='--id', type=int) with ArgumentsContext(cli_command_loader, 'build definition list') as ac: ac.argument('repository_type', choices=[ 'tfsversioncontrol', 'tfsgit', 'git', 'github', 'githubenterprise', 'bitbucket', 'svn' ], type=str.lower) with ArgumentsContext(cli_command_loader, 'build task') as ac: ac.argument('task_id', options_list='--id', type=str)
def load_build_arguments(cli_command_loader): with ArgumentsContext(cli_command_loader, 'build') as ac: ac.argument('open_browser', options_list='--open') ac.argument('project', options_list=('--project', '-p')) ac.argument('team_instance', options_list=('--instance', '-i')) ac.argument('detect', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) with ArgumentsContext(cli_command_loader, 'build list') as ac: ac.argument('definition_ids', nargs='*', type=int) ac.argument('tags', nargs='*') with ArgumentsContext(cli_command_loader, 'build queue') as ac: ac.argument('definition_id', type=int) with ArgumentsContext(cli_command_loader, 'build show') as ac: ac.argument('build_id', options_list='--id', type=int) with ArgumentsContext(cli_command_loader, 'build definition show') as ac: ac.argument('definition_id', options_list='--id', type=int)
def load_arguments(self, command): with ArgumentsContext(self, 'arg-test') as c: c.argument('arg1', help='Arg1', deprecate_info=c.deprecate()) c.argument('opt1', help='Opt1', options_list=[ '--opt1', c.deprecate(redirect='--opt1', target='--alt1') ]) c.argument('arg2', help='Arg2', deprecate_info=c.deprecate(hide='1.0.0')) c.argument('opt2', help='Opt2', options_list=[ '--opt2', c.deprecate(redirect='--opt2', target='--alt2', hide='1.0.0') ]) c.argument('arg3', help='Arg3', deprecate_info=c.deprecate(hide='0.1.0')) c.argument('opt3', help='Opt3', options_list=[ '--opt3', c.deprecate(redirect='--opt3', target='--alt3', hide='0.1.0') ]) c.argument('arg4', deprecate_info=c.deprecate(expiration='1.0.0')) c.argument('opt4', options_list=[ '--opt4', c.deprecate(redirect='--opt4', target='--alt4', expiration='1.0.0') ]) c.argument('arg5', deprecate_info=c.deprecate(expiration='0.1.0')) c.argument('opt5', options_list=[ '--opt5', c.deprecate(redirect='--opt5', target='--alt5', expiration='0.1.0') ]) super(DeprecationTestCommandLoader, self).load_arguments(command)
def load_arguments(self, command): enable_trace_pii = os.environ.get("ENABLE_TRACE_PII") if enable_trace_pii is None: enable_trace_pii = False with ArgumentsContext(self, "serve") as ac: ac.argument("env_grpc_port", default=False, required=False) ac.argument("enable_trace_pii", default=enable_trace_pii, required=False) ac.argument("grpc_port", default=3001, type=int, required=False) ac.argument( "nlp_conf_path", default="conf/default.yaml", type=str, required=False ) ac.argument("max_workers", default=10, type=int, required=False) with ArgumentsContext(self, "analyze") as ac: ac.argument("env_grpc_port", default=False, required=False) ac.argument("grpc_port", default=3001, type=int, required=False) ac.argument("text", required=True) ac.argument("fields", nargs="*", required=True) logger.info(f"cli commands: {command}") super(CommandsLoader, self).load_arguments(command)
def load_arguments(self, command): with ArgumentsContext(self, '') as c: c.argument('arg1', options_list=['--arg', '-a'], required=False, type=int, choices=[1, 2, 3]) c.argument('arg2', options_list=['-b'], required=True, choices=['a', 'b', 'c']) super(PreviewTestCommandLoader, self).load_arguments(command)
def load_arguments(self, command): """ Load the arguments for the specified command :param command: The command to load arguments for :type command: str """ from knack.arguments import ArgumentsContext self.cli_ctx.raise_event(EVENT_CMDLOADER_LOAD_ARGUMENTS, cmd_tbl=self.command_table, command=command) try: self.command_table[command].load_arguments() except KeyError: return # ensure global 'cmd' is ignored with ArgumentsContext(self, '') as c: c.ignore('cmd') self._apply_parameter_info(command, self.command_table[command])
def load_arguments(self, command): from azure.cli.core.commands.parameters import resource_group_name_type, get_location_type, deployment_name_type from knack.arguments import ignore_type command_loaders = self.cmd_to_loader_map.get(command, None) if command_loaders: with ArgumentsContext(self, '') as c: c.argument('resource_group_name', resource_group_name_type) c.argument('location', get_location_type(self.cli_ctx)) c.argument('deployment_name', deployment_name_type) c.argument('cmd', ignore_type) for loader in command_loaders: loader.command_name = command self.command_table[command].load_arguments() # this loads the arguments via reflection loader.load_arguments(command) # this adds entries to the argument registries self.argument_registry.arguments.update(loader.argument_registry.arguments) self.extra_argument_registry.update(loader.extra_argument_registry) loader._update_command_definitions() # pylint: disable=protected-access
def load_release_arguments(cli_command_loader): with ArgumentsContext(cli_command_loader, 'release') as ac: ac.argument('open_browser', options_list='--open') ac.argument('project', options_list=('--project', '-p')) ac.argument('team_instance', options_list=('--instance', '-i')) ac.argument('detect', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) with ArgumentsContext(cli_command_loader, 'release list') as ac: ac.argument('definition_id', type=int) with ArgumentsContext(cli_command_loader, 'release create') as ac: ac.argument('definition_id', type=int) ac.argument('artifact_metadata_list', nargs='*') with ArgumentsContext(cli_command_loader, 'release show') as ac: ac.argument('release_id', options_list='--id', type=int) with ArgumentsContext(cli_command_loader, 'release definition show') as ac: ac.argument('definition_id', options_list='--id', type=int) with ArgumentsContext(cli_command_loader, 'release definition list') as ac: ac.argument('artifact_type', choices=['build', 'jenkins', 'github', 'externaltfsbuild', 'git', 'tfvc'], type=str.lower)
def load_release_arguments(cli_command_loader): with ArgumentsContext(cli_command_loader, 'release') as ac: ac.argument('open_browser', options_list='--open') ac.argument('project', options_list=('--project', '-p')) ac.argument('team_instance', options_list=('--instance', '-i')) ac.argument('detect', **enum_choice_list(_ON_OFF_SWITCH_VALUES)) with ArgumentsContext(cli_command_loader, 'release list') as ac: ac.argument('definition_id', type=int) with ArgumentsContext(cli_command_loader, 'release create') as ac: ac.argument('definition_id', type=int) ac.argument('artifact_metadata_list', nargs='*') with ArgumentsContext(cli_command_loader, 'release show') as ac: ac.argument('release_id', options_list='--id', type=int) with ArgumentsContext(cli_command_loader, 'release definition show') as ac: ac.argument('definition_id', options_list='--id', type=int) with ArgumentsContext(cli_command_loader, 'release definition list') as ac: ac.argument('artifact_type', choices=['Build', 'Jenkins', 'GitHub', 'Nuget', 'Team Build (external)', 'ExternalTFSBuild', 'Git', 'TFVC', 'ExternalTfsXamlBuild'])
def load_arguments(self, _): with ArgumentsContext(self, '') as c: c.argument('modules', options_list=['--modules', '-m'], nargs='+', help='Space-separated list of modules to check. Omit to check all.') c.argument('private', action='store_true', help='Target the private repo.') c.argument('yes', options_list=['--yes', '-y'], action='store_true', help='Answer "yes" to all prompts.') with ArgumentsContext(self, 'setup') as c: c.argument('cli_path', options_list=['--cli', '-c'], nargs='?', const=Flag, help='Path to an existing Azure CLI repo. Omit value to search for the repo.') c.argument('ext_repo_path', options_list=['--repo', '-r'], nargs='+', help='Space-separated list of paths to existing Azure CLI extensions repos.') c.argument('ext', options_list=['--ext', '-e'], nargs='+', help='Space-separated list of extensions to install initially.') with ArgumentsContext(self, 'test') as c: c.argument('discover', options_list='--discover', action='store_true', help='Build an index of test names so that you don\'t need to specify fully qualified test paths.') c.argument('xml_path', options_list='--xml-path', help='Path and filename at which to store the results in XML format. If omitted, the file will be saved as `test_results.xml` in your `.azdev` directory.') c.argument('in_series', options_list='--series', action='store_true', help='Disable test parallelization.') c.argument('run_live', options_list='--live', action='store_true', help='Run all tests live.') c.positional('tests', nargs='*', help='Space-separated list of tests to run. Can specify test filenames, class name or individual method names.', completer=get_test_completion) c.argument('profile', options_list='--profile', help='Run automation against a specific profile. If omit, the tests will run against current profile.') c.argument('pytest_args', nargs=argparse.REMAINDER, options_list=['--pytest-args', '-a'], help='Denotes the remaining args will be passed to pytest.') c.argument('last_failed', options_list='--lf', action='store_true', help='Re-run the last tests that failed.') with ArgumentsContext(self, 'coverage') as c: c.argument('prefix', type=str, help='Filter analysis by command prefix.') c.argument('report', action='store_true', help='Display results as a report.') c.argument('untested_params', nargs='+', help='Space-separated list of param dest values to search for (OR logic)') with ArgumentsContext(self, 'style') as c: c.positional('modules', nargs='*', help='Space-separated list of modules or extensions to check.') c.argument('pylint', action='store_true', help='Run pylint.') c.argument('pep8', action='store_true', help='Run flake8 to check PEP8.') for scope in ['history', 'version']: with ArgumentsContext(self, 'verify {}'.format(scope)) as c: c.positional('modules', nargs='*', help='Space-separated list of modules to check.') with ArgumentsContext(self, 'verify version') as c: c.argument('update', action='store_true', help='If provided, the command will update the versions in azure-cli\'s setup.py file.') c.argument('pin', action='store_true', help='If provided and used with --update, will pin the module versions in azure-cli\'s setup.py file.') with ArgumentsContext(self, 'linter') as c: c.positional('modules', nargs='*', help='Space-separated list of modules or extensions to check.') c.argument('rules', options_list=['--rules', '-r'], nargs='+', help='Space-separated list of rules to run. Omit to run all rules.') c.argument('rule_types', options_list=['--rule-types', '-t'], nargs='+', choices=['params', 'commands', 'command_groups', 'help_entries'], help='Space-separated list of rule types to run. Omit to run all.') c.argument('ci_exclusions', action='store_true', help='Force application of CI exclusions list when run locally.') with ArgumentsContext(self, 'perf') as c: c.argument('runs', type=int, help='Number of runs to average performance over.') with ArgumentsContext(self, 'extension') as c: c.argument('dist_dir', help='Name of a directory in which to save the resulting WHL files.') with ArgumentsContext(self, 'extension publish') as c: c.argument('update_index', action='store_true', help='Update the index.json file after publishing is complete.') with ArgumentsContext(self, 'extension publish') as c: c.argument('storage_account', help='Name of the storage account to publish to.', arg_group='Storage', configured_default='storage_account') c.argument('storage_container', help='Name of the storage container to publish to.', arg_group='Storage', configured_default='storage_container') c.argument('storage_subscription', help='Subscription ID of the storage account.', arg_group='Storage', configured_default='storage_subscription') for scope in ['extension add', 'extension remove', 'extension build', 'extension publish']: with ArgumentsContext(self, scope) as c: c.positional('extensions', metavar='NAME', nargs='+', help='Space-separated list of extension names.') for scope in ['extension repo add', 'extension repo remove']: with ArgumentsContext(self, scope) as c: c.positional('repos', metavar='PATH', nargs='+', help='Space-separated list of paths to Git repositories.') with ArgumentsContext(self, 'extension update-index') as c: c.positional('extensions', nargs='+', metavar='URL', help='Space-separated list of URLs to extension WHL files.') with ArgumentsContext(self, 'cli check-versions') as c: c.positional('modules', nargs='*', help='Space-separated list of modules to check.')
def load_arguments(self, _): modules_type = CLIArgumentType( nargs='*', help= "Space-separated list of modules or extensions (dev mode) to check. " "Use 'CLI' to check built-in modules or 'EXT' to check extensions. " "Omit to check all. ") with ArgumentsContext(self, '') as c: c.argument('private', action='store_true', help='Target the private repo.') c.argument('yes', options_list=['--yes', '-y'], action='store_true', help='Answer "yes" to all prompts.') c.argument( 'use_ext_index', action='store_true', help= 'Run command on extensions registered in the azure-cli-extensions index.json.' ) c.argument( 'git_source', options_list='--src', arg_group='Git', help= 'Name of the Git source branch to check (i.e. master or upstream/master).' ) c.argument( 'git_target', options_list='--tgt', arg_group='Git', help= 'Name of the Git target branch to check (i.e. dev or upstream/dev)' ) c.argument('git_repo', options_list='--repo', arg_group='Git', help='Path to the Git repo to check.') with ArgumentsContext(self, 'setup') as c: c.argument( 'cli_path', options_list=['--cli', '-c'], nargs='?', const=Flag, help= "Path to an existing Azure CLI repo. Omit value to search for the repo or use special value 'EDGE' to install the latest developer edge build." ) c.argument( 'ext_repo_path', options_list=['--repo', '-r'], nargs='+', help= 'Space-separated list of paths to existing Azure CLI extensions repos.' ) c.argument( 'ext', options_list=['--ext', '-e'], nargs='+', help= "Space-separated list of extensions to install initially. Use '*' to install all extensions." ) with ArgumentsContext(self, 'test') as c: c.argument( 'discover', options_list='--discover', action='store_true', help= 'Build an index of test names so that you don\'t need to specify fully qualified test paths.' ) c.argument( 'xml_path', options_list='--xml-path', help= 'Path and filename at which to store the results in XML format. If omitted, the file will be saved as `test_results.xml` in your `.azdev` directory.' ) c.argument('in_series', options_list='--series', action='store_true', help='Disable test parallelization.') c.argument('run_live', options_list='--live', action='store_true', help='Run all tests live.') c.positional( 'tests', nargs='*', help= "Space-separated list of tests to run. Can specify module or extension names, test filenames, class name or individual method names. " "Omit to check all or use 'CLI' or 'EXT' to check only CLI modules or extensions respectively.", completer=get_test_completion) c.argument( 'profile', options_list='--profile', help= 'Run automation against a specific profile. If omit, the tests will run against current profile.' ) c.argument('pytest_args', nargs=argparse.REMAINDER, options_list=['--pytest-args', '-a'], help='Denotes the remaining args will be passed to pytest.') c.argument('last_failed', options_list='--lf', action='store_true', help='Re-run the last tests that failed.') c.argument('no_exit_first', options_list='--no-exitfirst', action='store_true', help='Do not exit on first error or failed test') # CI parameters c.argument( 'cli_ci', action='store_true', arg_group='Continuous Integration', help='Apply incremental test strategy to Azure CLI on Azure DevOps' ) with ArgumentsContext(self, 'coverage') as c: c.argument('prefix', type=str, help='Filter analysis by command prefix.') c.argument('report', action='store_true', help='Display results as a report.') c.argument( 'untested_params', nargs='+', help= 'Space-separated list of param dest values to search for (OR logic)' ) with ArgumentsContext(self, 'style') as c: c.positional('modules', modules_type) c.argument('pylint', action='store_true', help='Run pylint.') c.argument('pep8', action='store_true', help='Run flake8 to check PEP8.') with ArgumentsContext(self, 'cli check-versions') as c: c.argument( 'update', action='store_true', help= 'If provided, the command will update the versions in azure-cli\'s setup.py file.' ) c.argument( 'pin', action='store_true', help= 'If provided and used with --update, will pin the module versions in azure-cli\'s setup.py file.' ) with ArgumentsContext(self, 'cli update-setup') as c: c.argument( 'pin', action='store_true', help='Pin the module versions in azure-cli\'s setup.py file.') # region linter with ArgumentsContext(self, 'linter') as c: c.positional('modules', modules_type) c.argument( 'rules', options_list=['--rules', '-r'], nargs='+', help='Space-separated list of rules to run. Omit to run all rules.' ) c.argument( 'rule_types', options_list=['--rule-types', '-t'], nargs='+', choices=['params', 'commands', 'command_groups', 'help_entries'], help='Space-separated list of rule types to run. Omit to run all.') c.argument( 'ci_exclusions', action='store_true', help='Force application of CI exclusions list when run locally.') c.argument( 'include_whl_extensions', action='store_true', help= "Allow running linter on extensions installed by `az extension add`." ) # endregion with ArgumentsContext(self, 'perf') as c: c.argument('runs', type=int, help='Number of runs to average performance over.') with ArgumentsContext(self, 'extension') as c: c.argument( 'dist_dir', help='Name of a directory in which to save the resulting WHL files.' ) with ArgumentsContext(self, 'extension publish') as c: c.argument( 'update_index', action='store_true', help='Update the index.json file after publishing is complete.') with ArgumentsContext(self, 'extension publish') as c: c.argument( 'storage_account', help= 'Name of the storage account to publish to. Environment variable: AZDEV_DEFAULTS_STORAGE_ACCOUNT.', arg_group='Storage', configured_default='storage_account') c.argument( 'storage_container', help= 'Name of the storage container to publish to. Environment variable: AZDEV_DEFAULTS_STORAGE_CONTAINER.', arg_group='Storage', configured_default='storage_container') c.argument('storage_account_key', help='Key of the storage account to publish to. ', arg_group='Storage', configured_default='storage_account') for scope in [ 'extension add', 'extension remove', 'extension build', 'extension publish' ]: with ArgumentsContext(self, scope) as c: c.positional('extensions', metavar='NAME', nargs='+', help='Space-separated list of extension names.') for scope in ['extension repo add', 'extension repo remove']: with ArgumentsContext(self, scope) as c: c.positional( 'repos', metavar='PATH', nargs='+', help='Space-separated list of paths to Git repositories.') with ArgumentsContext(self, 'extension update-index') as c: c.positional( 'extensions', nargs='+', metavar='URL', help='Space-separated list of URLs to extension WHL files.') with ArgumentsContext(self, 'cli create') as c: c.positional('mod_name', help='Name of the module to create.') with ArgumentsContext(self, 'cli create') as c: c.ignore('local_sdk') with ArgumentsContext(self, 'extension create') as c: c.positional('ext_name', help='Name of the extension to create.') for scope in ['extension create', 'cli create']: with ArgumentsContext(self, scope) as c: c.argument( 'github_alias', help= 'Github alias for the individual who will be the code owner for this package.' ) c.argument( 'not_preview', action='store_true', help='Do not create template commands under a "Preview" status.' ) c.argument( 'required_sdk', help= 'Name and version of the underlying Azure SDK that is published on PyPI. (ex: azure-mgmt-contoso==0.1.0).', arg_group='SDK') c.argument( 'local_sdk', help= 'Path to a locally saved SDK. Use if your SDK is not available on PyPI.', arg_group='SDK') c.argument( 'client_name', help= 'Name of the Python SDK client object (ex: ContosoManagementClient).', arg_group='SDK') c.argument( 'operation_name', help= 'Name of the principal Python SDK operation class (ex: ContosoOperations).', arg_group='SDK') c.argument( 'sdk_property', help= 'The name of the Python variable that describes the main object name in the SDK calls (i.e.: account_name)', arg_group='SDK') c.argument('repo_name', help='Name of the repo the extension will exist in.') c.argument('display_name', arg_group='Help', help='Description to display in help text.') c.argument('display_name_plural', arg_group='Help', help='Description to display in help text when plural.') with ArgumentsContext(self, 'cli generate-docs') as c: c.argument( 'all_profiles', action='store_true', help= "If specified, generate docs for all CLI profiles. NOTE: this command updates the current CLI profile and will attempt to reset it to its original value. " "Please check the CLI's profile after running this command.") for scope in ['cli', 'extension']: with ArgumentsContext(self, '{} generate-docs'.format(scope)) as c: c.argument( 'output_dir', help= 'Directory to place the generated docs in. Defaults to a temporary directory. ' 'If the base directory does not exist, it will be created') c.argument('output_type', choices=['xml', 'html', 'text', 'man', 'latex'], default="xml", help='Output type of the generated docs.')
def load_arguments(self, command): """ Load command line arguments """ with ArgumentsContext(self, _LOGIN) as arg_context: arg_context.argument( 'client_id', options_list=['--clid', '-i'], type=str, required=False, help='The client ID.') arg_context.argument( 'tenant', options_list=['--tenant', '-t'], type=str, required=False, help='The tenant.') arg_context.argument( 'authority_url', options_list=['--authority_url', '-a'], type=str, required=False, help='Authority URL for login.') arg_context.argument( 'resource', options_list=['--resource', '-r'], type=str, required=False, help='Resource URL for login.') arg_context.argument( SETTINGS, options_list=SETTINGS_OPTIONS, type=str, required=False, help=SETTINGS_HELP) arg_context.argument( 'force', options_list=['--force', '-f'], type=bool, required=False, nargs='?', default=False, const=True, help='Override a previous login, if exists.') with ArgumentsContext(self, _DOWNLOAD) as arg_context: arg_context.argument( ENVIRONMENT, options_list=ENVIRONMENT_OPTIONS, type=str, required=False, help=ENVIRONMENT_HELP) arg_context.argument( CONNECTOR_ID, options_list=CONNECTOR_ID_OPTIONS, type=str, required=False, help=CONNECTOR_ID_HELP) arg_context.argument( 'destination', options_list=['--dest', '-d'], type=str, required=False, help='Destination directory. Non-existent directories will be created.') arg_context.argument( POWERAPPS_URL, options_list=POWERAPPS_URL_OPTIONS, type=str, required=False, help=POWERAPPS_URL_HELP) arg_context.argument( POWERAPPS_VERSION, options_list=POWERAPPS_VERSION_OPTIONS, type=str, required=False, help=POWERAPPS_VERSION_HELP) arg_context.argument( SETTINGS, options_list=SETTINGS_OPTIONS, type=str, required=False, help=SETTINGS_HELP) arg_context.argument( 'overwrite', options_list=['--overwrite', '-w'], type=bool, required=False, nargs='?', default=False, const=True, help='Overwrite all the existing connector and settings files.') with ArgumentsContext(self, _CREATE) as arg_context: arg_context.argument( ENVIRONMENT, options_list=ENVIRONMENT_OPTIONS, type=str, required=False, help=ENVIRONMENT_HELP) arg_context.argument( API_PROPERTIES, options_list=API_PROPERTIES_OPTIONS, type=str, required=False, help=API_PROPERTIES_HELP) arg_context.argument( API_DEFINITION, options_list=API_DEFINITION_OPTIONS, type=str, required=False, help=API_DEFINITION_HELP) arg_context.argument( ICON, options_list=ICON_OPTIONS, type=str, required=False, help=ICON_HELP) arg_context.argument( POWERAPPS_URL, options_list=POWERAPPS_URL_OPTIONS, type=str, required=False, help=POWERAPPS_URL_HELP) arg_context.argument( POWERAPPS_VERSION, options_list=POWERAPPS_VERSION_OPTIONS, type=str, required=False, help=POWERAPPS_VERSION_HELP) arg_context.argument( CLIENT_SECRET, options_list=CLIENT_SECRET_OPTIONS, type=str, required=False, help=CLIENT_SECRET_HELP) arg_context.argument( SETTINGS, options_list=SETTINGS_OPTIONS, type=str, required=False, help=SETTINGS_HELP) arg_context.argument( 'overwrite_settings', options_list=['--overwrite-settings', '-w'], type=bool, required=False, nargs='?', default=False, const=True, help='Overwrite the existing settings file.') with ArgumentsContext(self, _UPDATE) as arg_context: arg_context.argument( ENVIRONMENT, options_list=ENVIRONMENT_OPTIONS, type=str, required=False, help=ENVIRONMENT_HELP) arg_context.argument( API_PROPERTIES, options_list=API_PROPERTIES_OPTIONS, type=str, required=False, help=API_PROPERTIES_HELP) arg_context.argument( API_DEFINITION, options_list=API_DEFINITION_OPTIONS, type=str, required=False, help=API_DEFINITION_HELP) arg_context.argument( ICON, options_list=ICON_OPTIONS, type=str, required=False, help=ICON_HELP) arg_context.argument( CONNECTOR_ID, options_list=CONNECTOR_ID_OPTIONS, type=str, required=False, help=CONNECTOR_ID_HELP) arg_context.argument( POWERAPPS_URL, options_list=POWERAPPS_URL_OPTIONS, type=str, required=False, help=POWERAPPS_URL_HELP) arg_context.argument( POWERAPPS_VERSION, options_list=POWERAPPS_VERSION_OPTIONS, type=str, required=False, help=POWERAPPS_VERSION_HELP) arg_context.argument( CLIENT_SECRET, options_list=CLIENT_SECRET_OPTIONS, type=str, required=False, help=CLIENT_SECRET_HELP) arg_context.argument( SETTINGS, options_list=SETTINGS_OPTIONS, type=str, required=False, help=SETTINGS_HELP) with ArgumentsContext(self, _VALIDATE) as arg_context: arg_context.argument( API_DEFINITION, options_list=API_DEFINITION_OPTIONS, type=str, required=False, help=API_DEFINITION_HELP) arg_context.argument( POWERAPPS_URL, options_list=POWERAPPS_URL_OPTIONS, type=str, required=False, help=POWERAPPS_URL_HELP) arg_context.argument( POWERAPPS_VERSION, options_list=POWERAPPS_VERSION_OPTIONS, type=str, required=False, help=POWERAPPS_VERSION_HELP) arg_context.argument( SETTINGS, options_list=SETTINGS_OPTIONS, type=str, required=False, help=SETTINGS_HELP)