当前位置: 首页>>代码示例>>Python>>正文


Python commands.cli_command函数代码示例

本文整理汇总了Python中azure.cli.core.commands.cli_command函数的典型用法代码示例。如果您正苦于以下问题:Python cli_command函数的具体用法?Python cli_command怎么用?Python cli_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cli_command函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: command

 def command(self, name, method_name, transform=None, table_transformer=None, confirmation=None,
             exception_handler=None):
     """
     Register a CLI command
     :param name: Name of the command as it will be called on the command line
     :type name: str
     :param method_name: Name of the method the command maps to on the service adapter
     :type method_name: str
     :param transform: Transform function for transforming the output of the command
     :type transform: function
     :param table_transformer: Transform function to be applied to table output to create a
     better output format for tables.
     :type table_transformer: function
     :param confirmation: Prompt prior to the action being executed. This is useful if the action
     would cause a loss of data.
     :type confirmation: bool
     :param exception_handler: Exception handler for handling non-standard exceptions
     :type exception_handler: function
     :return: None
     :rtype: None
     """
     cli_command(self._scope,
                 '{} {}'.format(self._group_name, name),
                 self._service_adapter(method_name),
                 client_factory=self._client_factory,
                 transform=transform,
                 table_transformer=table_transformer,
                 confirmation=confirmation,
                 exception_handler=exception_handler or self._exception_handler)
开发者ID:akshaysngupta,项目名称:azure-cli,代码行数:29,代码来源:util.py

示例2: test_help_long_description_from_docstring

    def test_help_long_description_from_docstring(self):
        """ Verifies that the first sentence of a docstring is extracted as the short description.
        Verifies that line breaks in the long summary are removed and leaves the text wrapping
        to the help system. """

        def test_handler():
            """Short Description. Long description with\nline break."""
            pass

        setattr(sys.modules[__name__], test_handler.__name__, test_handler)

        cli_command(None, "test", "{}#{}".format(__name__, test_handler.__name__))
        _update_command_definitions(command_table)

        config = Configuration([])
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute("test -h".split())
        self.assertEqual(
            True,
            io.getvalue().startswith(
                "\nCommand\n    az test: Short Description.\n        Long description with line break."
            ),
        )  # pylint: disable=line-too-long
开发者ID:yugangw-msft,项目名称:azure-cli,代码行数:25,代码来源:test_help.py

示例3: test_register_cli_argument

    def test_register_cli_argument(self):
        command_table.clear()
        cli_command(None, 'test register sample-vm-get',
                    '{}#Test_command_registration.sample_vm_get'.format(__name__))
        register_cli_argument('test register sample-vm-get', 'vm_name', CliArgumentType(
            options_list=('--wonky-name', '-n'), metavar='VMNAME', help='Completely WONKY name...',
            required=False
        ))

        command_table['test register sample-vm-get'].load_arguments()
        _update_command_definitions(command_table)

        self.assertEqual(len(command_table), 1,
                         'We expect exactly one command in the command table')
        command_metadata = command_table['test register sample-vm-get']
        self.assertEqual(len(command_metadata.arguments), 4, 'We expected exactly 4 arguments')
        some_expected_arguments = {
            'resource_group_name': CliArgumentType(dest='resource_group_name', required=True),
            'vm_name': CliArgumentType(dest='vm_name', required=False),
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            self.assertDictContainsSubset(some_expected_arguments[existing].settings,
                                          command_metadata.arguments[existing].options)
        self.assertEqual(command_metadata.arguments['vm_name'].options_list, ('--wonky-name', '-n'))
开发者ID:Azure,项目名称:azure-cli,代码行数:26,代码来源:test_command_registration.py

示例4: command

 def command(self, name, method_name):
     cli_command(
         self._scope,
         "{} {}".format(self._group_name, name),
         self._service_adapter(method_name),
         client_factory=self._client_factory,
     )
开发者ID:yugangw-msft,项目名称:azure-cli,代码行数:7,代码来源:_util.py

示例5: test_command_build_argument_help_text

    def test_command_build_argument_help_text(self):
        def sample_sdk_method_with_weird_docstring(param_a, param_b, param_c): # pylint: disable=unused-argument
            """
            An operation with nothing good.

            :param dict param_a:
            :param param_b: The name
            of
            nothing.
            :param param_c: The name
            of

            nothing2.
            """
        command_table.clear()
        setattr(sys.modules[__name__], sample_sdk_method_with_weird_docstring.__name__, sample_sdk_method_with_weird_docstring) #pylint: disable=line-too-long
        cli_command(None, 'test command foo', '{}#{}'.format(__name__, sample_sdk_method_with_weird_docstring.__name__), None) #pylint: disable=line-too-long

        command_table['test command foo'].load_arguments()
        _update_command_definitions(command_table)

        command_metadata = command_table['test command foo']
        self.assertEqual(len(command_metadata.arguments), 3, 'We expected exactly 3 arguments')
        some_expected_arguments = {
            'param_a': CliArgumentType(dest='param_a', required=True, help=''),
            'param_b': CliArgumentType(dest='param_b', required=True, help='The name of nothing.'),
            'param_c': CliArgumentType(dest='param_c', required=True, help='The name of nothing2.')
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            self.assertDictContainsSubset(some_expected_arguments[existing].settings,
                                          command_metadata.arguments[existing].options)
        command_table.clear()
开发者ID:Azure,项目名称:azure-cli,代码行数:34,代码来源:test_command_registration.py

示例6: test_register_extra_cli_argument

    def test_register_extra_cli_argument(self):
        command_table.clear()

        cli_command(None, 'test command sample-vm-get',
                    '{}#Test_command_registration.sample_vm_get'.format(__name__), None)
        register_extra_cli_argument(
            'test command sample-vm-get', 'added_param', options_list=('--added-param',),
            metavar='ADDED', help='Just added this right now!', required=True
        )

        command_table['test command sample-vm-get'].load_arguments()
        _update_command_definitions(command_table)

        self.assertEqual(len(command_table), 1,
                         'We expect exactly one command in the command table')
        command_metadata = command_table['test command sample-vm-get']
        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)
            self.assertDictContainsSubset(some_expected_arguments[existing].settings,
                                          command_metadata.arguments[existing].options)

        command_table.clear()
开发者ID:Azure,项目名称:azure-cli,代码行数:28,代码来源:test_command_registration.py

示例7: test_override_using_register_cli_argument

    def test_override_using_register_cli_argument(self):
        def sample_sdk_method(param_a): # pylint: disable=unused-argument
            pass

        def test_validator_completer():
            pass

        command_table.clear()
        setattr(sys.modules[__name__], sample_sdk_method.__name__, sample_sdk_method)
        cli_command(None, 'override_using_register_cli_argument foo',
                    '{}#{}'.format(__name__, sample_sdk_method.__name__),
                    None)
        register_cli_argument('override_using_register_cli_argument',
                              'param_a',
                              options_list=('--overridden', '-r'),
                              validator=test_validator_completer,
                              completer=test_validator_completer,
                              required=False)

        command_table['override_using_register_cli_argument foo'].load_arguments()
        _update_command_definitions(command_table)

        command_metadata = command_table['override_using_register_cli_argument foo']
        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'])
        command_table.clear()
开发者ID:Azure,项目名称:azure-cli,代码行数:31,代码来源:test_command_registration.py

示例8: test_register_command

    def test_register_command(self):
        command_table.clear()
        cli_command(None, 'test command sample-vm-get',
                    '{}#Test_command_registration.sample_vm_get'.format(__name__), None)

        self.assertEqual(len(command_table), 1,
                         'We expect exactly one command in the command table')
        command_table['test command sample-vm-get'].load_arguments()
        command_metadata = command_table['test command sample-vm-get']
        self.assertEqual(len(command_metadata.arguments), 4, 'We expected exactly 4 arguments')
        some_expected_arguments = {
            'resource_group_name': CliArgumentType(dest='resource_group_name',
                                                   required=True,
                                                   help='The name of the resource group.'),
            'vm_name': CliArgumentType(dest='vm_name',
                                       required=True,
                                       help='The name of the virtual machine.'),
            'opt_param': CliArgumentType(required=False,
                                         help='Used to verify reflection correctly identifies optional params.'), # pylint: disable=line-too-long
            'expand': CliArgumentType(required=False,
                                      help='The expand expression to apply on the operation.')
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            self.assertDictContainsSubset(some_expected_arguments[existing].settings,
                                          command_metadata.arguments[existing].options)
        self.assertEqual(command_metadata.arguments['resource_group_name'].options_list,
                         ['--resource-group-name'])
开发者ID:Azure,项目名称:azure-cli,代码行数:29,代码来源:test_command_registration.py

示例9: custom_command

 def custom_command(self, name, custom_func_name, confirmation=None,
                    exception_handler=None):
     cli_command(self._scope,
                 '{} {}'.format(self._group_name, name),
                 self._custom_path.format(custom_func_name),
                 client_factory=self._client_factory,
                 confirmation=confirmation,
                 exception_handler=exception_handler or self._exception_handler)
开发者ID:akshaysngupta,项目名称:azure-cli,代码行数:8,代码来源:util.py

示例10: custom_command

 def custom_command(self, name, custom_func_name, confirmation=None,
                    exception_handler=None, deprecate_info=None, no_wait_param=None):
     cli_command(self._scope,
                 '{} {}'.format(self._group_name, name),
                 self._custom_path.format(custom_func_name),
                 client_factory=self._client_factory,
                 confirmation=confirmation,
                 deprecate_info=deprecate_info,
                 exception_handler=exception_handler or self._exception_handler,
                 no_wait_param=no_wait_param)
开发者ID:cobeystats,项目名称:azure-cli,代码行数:10,代码来源:util.py

示例11: test_register_command_from_extension

    def test_register_command_from_extension(self):
        command_table.clear()

        # A standard command
        cli_command(None, 'hello world', 'dummy_operation', None)
        self.assertEqual(len(command_table), 1)
        self.assertEqual(command_table['hello world'].command_source, None)

        command_table.clear()

        # A command from an extension
        cli_command('{}myextension'.format(EXTENSIONS_MOD_PREFIX), 'hello world', 'dummy_operation', None)
        self.assertEqual(len(command_table), 1)
        cmd_source = command_table['hello world'].command_source
        self.assertTrue(isinstance(cmd_source, ExtensionCommandSource))
        self.assertFalse(cmd_source.overrides_command)

        command_table.clear()

        # A command from an extension that overrides the original command
        cli_command(None, 'hello world', 'dummy_operation', None)
        cli_command('{}myextension'.format(EXTENSIONS_MOD_PREFIX), 'hello world', 'dummy_operation', None)
        self.assertEqual(len(command_table), 1)
        cmd_source = command_table['hello world'].command_source
        self.assertTrue(isinstance(cmd_source, ExtensionCommandSource))
        self.assertTrue(cmd_source.overrides_command)

        command_table.clear()
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:28,代码来源:test_command_registration.py

示例12: set_up_command_table

    def set_up_command_table(self, required_arg=False):
        command_table.clear()

        module_name = __name__ + '.' + self._testMethodName
        cli_command(module_name, 'test sample-vm-list',
                    '{}#TestCommandWithConfiguredDefaults.sample_vm_list'.format(__name__))

        register_cli_argument('test sample-vm-list', 'resource_group_name',
                              CliArgumentType(options_list=('--resource-group-name', '-g'),
                                              configured_default='group', required=required_arg))

        command_table['test sample-vm-list'].load_arguments()
        _update_command_definitions(command_table)

        self.argv = 'az test sample-vm-list'.split()
        config = Configuration()
        config.get_command_table = lambda argv: command_table
        self.application = Application(config)
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:18,代码来源:test_command_with_configured_defaults.py

示例13: test_register_cli_argument_with_overrides

    def test_register_cli_argument_with_overrides(self):
        command_table.clear()

        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')

        cli_command('test vm-get', Test_command_registration.sample_vm_get, None)
        cli_command('test command vm-get-1', Test_command_registration.sample_vm_get, None)
        cli_command('test command vm-get-2', Test_command_registration.sample_vm_get, None)

        register_cli_argument('test', 'vm_name', global_vm_name_type)
        register_cli_argument('test command', 'vm_name', derived_vm_name_type)
        register_cli_argument('test command vm-get-2', 'vm_name', derived_vm_name_type,
                              help='second modification')

        _update_command_definitions(command_table)

        self.assertEqual(len(command_table), 3,
                         'We expect exactly three commands in the command table')
        command1 = command_table['test vm-get'].arguments['vm_name']
        command2 = command_table['test command vm-get-1'].arguments['vm_name']
        command3 = command_table['test command vm-get-2'].arguments['vm_name']

        self.assertTrue(command1.options['help'] == 'foo help')
        self.assertTrue(command2.options['help'] == 'first modification')
        self.assertTrue(command3.options['help'] == 'second modification')
        command_table.clear()
开发者ID:BurtBiel,项目名称:azure-cli,代码行数:30,代码来源:test_command_registration.py

示例14: supported_api_version

    job_list_table_format,
    task_create_table_format,
    account_keys_list_table_format,
    account_list_table_format,
    application_list_table_format,
    account_keys_renew_table_format)

if not supported_api_version(PROFILE_TYPE, max_api='2017-03-09-profile'):
    data_path = 'azure.batch.operations.{}_operations#{}'
    custom_path = 'azure.cli.command_modules.batch.custom#{}'
    mgmt_path = 'azure.mgmt.batch.operations.{}_operations#{}'

    # pylint: disable=line-too-long
    # Mgmt Account Operations

    cli_command(__name__, 'batch account list', custom_path.format('list_accounts'), account_mgmt_client_factory, table_transformer=account_list_table_format)
    cli_command(__name__, 'batch account show', mgmt_path.format('batch_account', 'BatchAccountOperations.get'), account_mgmt_client_factory)
    cli_command(__name__, 'batch account create', custom_path.format('create_account'), account_mgmt_client_factory)
    cli_command(__name__, 'batch account set', custom_path.format('update_account'), account_mgmt_client_factory)
    cli_command(__name__, 'batch account delete', mgmt_path.format('batch_account', 'BatchAccountOperations.delete'), account_mgmt_client_factory, confirmation=True)
    cli_command(__name__, 'batch account autostorage-keys sync', mgmt_path.format('batch_account', 'BatchAccountOperations.synchronize_auto_storage_keys'), account_mgmt_client_factory)
    cli_command(__name__, 'batch account keys list', mgmt_path.format('batch_account', 'BatchAccountOperations.get_keys'), account_mgmt_client_factory, table_transformer=account_keys_list_table_format)
    cli_command(__name__, 'batch account keys renew', mgmt_path.format('batch_account', 'BatchAccountOperations.regenerate_key'), account_mgmt_client_factory, table_transformer=account_keys_renew_table_format)
    cli_command(__name__, 'batch account login', custom_path.format('login_account'), account_mgmt_client_factory)

    cli_command(__name__, 'batch application list', mgmt_path.format('application', 'ApplicationOperations.list'), application_mgmt_client_factory, table_transformer=application_list_table_format)
    cli_command(__name__, 'batch application show', mgmt_path.format('application', 'ApplicationOperations.get'), application_mgmt_client_factory)
    cli_command(__name__, 'batch application create', mgmt_path.format('application', 'ApplicationOperations.create'), application_mgmt_client_factory)
    cli_command(__name__, 'batch application set', custom_path.format('update_application'), application_mgmt_client_factory)
    cli_command(__name__, 'batch application delete', mgmt_path.format('application', 'ApplicationOperations.delete'), application_mgmt_client_factory, confirmation=True)
开发者ID:smoghe,项目名称:azure-cli,代码行数:30,代码来源:commands.py

示例15: CLIError

                              "supported regions, please refer to https://docs.microsoft.com/en-us/"
                              "azure/app-service-web/app-service-linux-intro")
                elif 'Not enough available reserved instance servers to satisfy' in detail:
                    detail = ("Plan with Linux worker can only be created in a group " +
                              "which has never contained a Windows worker, and vice versa. " +
                              "Please use a new resource group. Original error:" + detail)
            ex = CLIError(detail)
        except Exception:  # pylint: disable=broad-except
            pass
        raise ex
    return _polish_bad_errors


custom_path = 'azure.cli.command_modules.appservice.custom#'

cli_command(__name__, 'webapp create', custom_path + 'create_webapp', exception_handler=ex_handler_factory())
cli_command(__name__, 'webapp list', custom_path + 'list_webapp', table_transformer=transform_web_list_output)
cli_command(__name__, 'webapp show', custom_path + 'show_webapp', exception_handler=empty_on_404, table_transformer=transform_web_output)
cli_command(__name__, 'webapp delete', custom_path + 'delete_webapp')
cli_command(__name__, 'webapp stop', custom_path + 'stop_webapp')
cli_command(__name__, 'webapp start', custom_path + 'start_webapp')
cli_command(__name__, 'webapp restart', custom_path + 'restart_webapp')
cli_command(__name__, 'webapp traffic-routing set', custom_path + 'set_traffic_routing')
cli_command(__name__, 'webapp traffic-routing show', custom_path + 'show_traffic_routing')
cli_command(__name__, 'webapp traffic-routing clear', custom_path + 'clear_traffic_routing')

cli_command(__name__, 'webapp config set', custom_path + 'update_site_configs')
cli_command(__name__, 'webapp config show', custom_path + 'get_site_configs', exception_handler=empty_on_404)
cli_command(__name__, 'webapp config appsettings list', custom_path + 'get_app_settings', exception_handler=empty_on_404)
cli_command(__name__, 'webapp config appsettings set', custom_path + 'update_app_settings')
cli_command(__name__, 'webapp config appsettings delete', custom_path + 'delete_app_settings')
开发者ID:smoghe,项目名称:azure-cli,代码行数:31,代码来源:commands.py


注:本文中的azure.cli.core.commands.cli_command函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。