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


Python CliCommand.add_argument方法代码示例

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


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

示例1: test_help_with_param_specified

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_help_with_param_specified(self, _):
        app = Application(Configuration([]))
        def test_handler():
            pass

        command = CliCommand('n1', test_handler)
        command.add_argument('arg', '--arg', '-a', required=False)
        command.add_argument('b', '-b', required=False)
        cmd_table = {'n1': command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('n1 --arg foo -h'.split())

        s = """
Command
    az n1

Arguments
    --arg -a
    -b

Global Arguments
    --help -h: Show this help message and exit.
"""

        self.assertEqual(s, io.getvalue())
开发者ID:BurtBiel,项目名称:azure-cli,代码行数:32,代码来源:test_help.py

示例2: test_case_insensitive_enum_choices

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_case_insensitive_enum_choices(self):
        from enum import Enum

        class TestEnum(Enum):  # pylint: disable=too-few-public-methods

            opt1 = "ALL_CAPS"
            opt2 = "camelCase"
            opt3 = "snake_case"

        def test_handler():
            pass

        command = CliCommand('test command', test_handler)
        command.add_argument('opt', '--opt', required=True, **enum_choice_list(TestEnum))
        cmd_table = {'test command': command}

        parser = AzCliCommandParser()
        parser.load_command_table(cmd_table)

        args = parser.parse_args('test command --opt alL_cAps'.split())
        self.assertEqual(args.opt, 'ALL_CAPS')

        args = parser.parse_args('test command --opt CAMELCASE'.split())
        self.assertEqual(args.opt, 'camelCase')

        args = parser.parse_args('test command --opt sNake_CASE'.split())
        self.assertEqual(args.opt, 'snake_case')
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:29,代码来源:test_parser.py

示例3: test_case_insensitive_command_path

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_case_insensitive_command_path(self):
        import argparse

        def handler(args):
            return 'PASSED'

        command = CliCommand('test command', handler)
        command.add_argument('var', '--var', '-v')
        cmd_table = {'test command': command}

        def _test(cmd_line):
            argv = cmd_line.split()
            config = Configuration()
            config.get_command_table = lambda argv: cmd_table
            application = Application(config)
            return application.execute(argv[1:])

        # case insensitive command paths
        result = _test('az TEST command --var blah')
        self.assertEqual(result.result, 'PASSED')

        result = _test('az test COMMAND --var blah')
        self.assertEqual(result.result, 'PASSED')

        result = _test('az test command -v blah')
        self.assertEqual(result.result, 'PASSED')

        # verify that long and short options remain case sensitive
        with self.assertRaises(SystemExit):
            _test('az test command --vAR blah')

        with self.assertRaises(SystemExit):
            _test('az test command -V blah')
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:35,代码来源:test_application.py

示例4: test_help_full_documentations

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_help_full_documentations(self, _):
        app = Application(Configuration())

        def test_handler():
            pass

        command = CliCommand('n1', test_handler)
        command.add_argument('foobar', '--foobar', '-fb', required=False)
        command.add_argument('foobar2', '--foobar2', '-fb2', required=True)
        command.help = """
                short-summary: this module does xyz one-line or so
                long-summary: |
                    this module.... kjsdflkj... klsfkj paragraph1
                    this module.... kjsdflkj... klsfkj paragraph2
                parameters:
                    - name: --foobar -fb
                      type: string
                      required: false
                      short-summary: one line partial sentence
                      long-summary: text, markdown, etc.
                      populator-commands:
                        - az vm list
                        - default
                    - name: --foobar2 -fb2
                      type: string
                      required: true
                      short-summary: one line partial sentence
                      long-summary: paragraph(s)
                examples:
                    - name: foo example
                      text: example details
            """
        cmd_table = {'n1': command}

        config = Configuration()
        config.get_command_table = lambda args: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('n1 -h'.split())
        s = """
Command
    az n1: This module does xyz one-line or so.
        This module.... kjsdflkj... klsfkj paragraph1
        this module.... kjsdflkj... klsfkj paragraph2.

Arguments
    --foobar2 -fb2 [Required]: One line partial sentence.
        Paragraph(s).
    --foobar -fb             : One line partial sentence.  Values from: az vm list, default.
        Text, markdown, etc.

Global Arguments
    --help -h                : Show this help message and exit.

Examples
    foo example
        example details
"""
        self.assertEqual(s, io.getvalue())
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:62,代码来源:test_help.py

示例5: test_help_global_params

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_help_global_params(self, mock_register_extensions, _):
        def register_globals(global_group):
            global_group.add_argument(
                "--query2",
                dest="_jmespath_query",
                metavar="JMESPATH",
                help="JMESPath query string. See http://jmespath.org/ " "for more information and examples.",
            )

        mock_register_extensions.return_value = None

        def _register_global_parser(appl):
            # noqa pylint: disable=protected-access
            appl._event_handlers[appl.GLOBAL_PARSER_CREATED].append(register_globals)

        mock_register_extensions.side_effect = _register_global_parser

        def test_handler():
            pass

        command = CliCommand("n1", test_handler)
        command.add_argument("arg", "--arg", "-a", required=False)
        command.add_argument("b", "-b", required=False)
        command.help = """
            long-summary: |
                line1
                line2
        """
        cmd_table = {"n1": command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute("n1 -h".split())

        s = """
Command
    az n1
        Line1
        line2.

Arguments
    --arg -a
    -b

Global Arguments
    --help -h: Show this help message and exit.
    --query2 : JMESPath query string. See http://jmespath.org/ for more information and examples.
"""

        self.assertEqual(s, io.getvalue())
开发者ID:yugangw-msft,项目名称:azure-cli,代码行数:55,代码来源:test_help.py

示例6: test_help_group_children

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_help_group_children(self):
        app = Application(Configuration([]))
        def test_handler():
            pass
        def test_handler2():
            pass

        command = CliCommand('group1 group3 n1', test_handler)
        command.add_argument('foobar', '--foobar', '-fb', required=False)
        command.add_argument('foobar2', '--foobar2', '-fb2', required=True)

        command2 = CliCommand('group1 group2 n1', test_handler2)
        command2.add_argument('foobar', '--foobar', '-fb', required=False)
        command2.add_argument('foobar2', '--foobar2', '-fb2', required=True)

        cmd_table = {'group1 group3 n1': command, 'group1 group2 n1': command2}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('group1 -h'.split())
        s = '\nGroup\n    az group1\n\nSubgroups:\n    group2\n    group3\n\n'
        self.assertEqual(s, io.getvalue())
开发者ID:BurtBiel,项目名称:azure-cli,代码行数:27,代码来源:test_help.py

示例7: test_choice_list_with_ints

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_choice_list_with_ints(self):
        def test_handler():
            pass

        command = CliCommand('n1', test_handler)
        command.add_argument('arg', '--arg', '-a', required=False, choices=[1, 2, 3])
        command.add_argument('b', '-b', required=False, choices=['a', 'b', 'c'])
        cmd_table = {'n1': command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application()
        app.initialize(config)
        with self.assertRaises(SystemExit):
            app.execute('n1 -h'.split())
开发者ID:BurtBiel,项目名称:azure-cli,代码行数:17,代码来源:test_help.py

示例8: test_help_plain_short_description

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_help_plain_short_description(self):
        def test_handler():
            pass

        command = CliCommand("n1", test_handler, description="the description")
        command.add_argument("arg", "--arg", "-a", required=False)
        command.add_argument("b", "-b", required=False)
        cmd_table = {"n1": command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute("n1 -h".split())
        self.assertEqual(True, "n1: The description." in io.getvalue())
开发者ID:yugangw-msft,项目名称:azure-cli,代码行数:18,代码来源:test_help.py

示例9: test_required_parameter

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_required_parameter(self):
        def test_handler(args): # pylint: disable=unused-argument
            pass

        command = CliCommand('test command', test_handler)
        command.add_argument('req', '--req', required=True)
        cmd_table = {'test command': command}

        parser = AzCliCommandParser()
        parser.load_command_table(cmd_table)

        args = parser.parse_args('test command --req yep'.split())
        self.assertIs(args.func, test_handler)

        AzCliCommandParser.error = VerifyError(self)
        parser.parse_args('test command'.split())
        self.assertTrue(AzCliCommandParser.error.called)
开发者ID:BurtBiel,项目名称:azure-cli,代码行数:19,代码来源:test_parser.py

示例10: test_help_global_params

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_help_global_params(self, mock_register_extensions, _):
        def register_globals(global_group):
            global_group.add_argument('--query2', dest='_jmespath_query', metavar='JMESPATH',
                                      help='JMESPath query string. See http://jmespath.org/ '
                                      'for more information and examples.')

        mock_register_extensions.return_value = None
        mock_register_extensions.side_effect = lambda app: \
            app._event_handlers[app.GLOBAL_PARSER_CREATED].append(register_globals) # pylint: disable=protected-access

        def test_handler():
            pass

        command = CliCommand('n1', test_handler)
        command.add_argument('arg', '--arg', '-a', required=False)
        command.add_argument('b', '-b', required=False)
        command.help = """
            long-summary: |
                line1
                line2
        """
        cmd_table = {'n1': command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('n1 -h'.split())

        s = """
Command
    az n1
        Line1
        line2.

Arguments
    --arg -a
    -b

Global Arguments
    --help -h: Show this help message and exit.
    --query2 : JMESPath query string. See http://jmespath.org/ for more information and examples.
"""

        self.assertEqual(s, io.getvalue())
开发者ID:BurtBiel,项目名称:azure-cli,代码行数:48,代码来源:test_help.py

示例11: test_help_docstring_description_overrides_short_description

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_help_docstring_description_overrides_short_description(self):
        def test_handler():
            pass

        command = CliCommand('n1', test_handler, description='short description')
        command.add_argument('arg', '--arg', '-a', required=False)
        command.add_argument('b', '-b', required=False)
        command.help = 'short-summary: docstring summary'
        cmd_table = {'n1': command}

        config = Configuration()
        config.get_command_table = lambda args: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('n1 -h'.split())
        self.assertEqual(True, 'n1: Docstring summary.' in io.getvalue())
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:19,代码来源:test_help.py

示例12: test_help_long_description_and_short_description

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_help_long_description_and_short_description(self):
        def test_handler():
            pass

        command = CliCommand('n1', test_handler, description='short description')
        command.add_argument('arg', '--arg', '-a', required=False)
        command.add_argument('b', '-b', required=False)
        command.help = 'long description'
        cmd_table = {'n1': command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

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

示例13: test_nargs_parameter

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_nargs_parameter(self):
        def test_handler():
            pass

        command = CliCommand('test command', test_handler)
        command.add_argument('req', '--req', required=True, nargs=2)
        cmd_table = {'test command': command}

        parser = AzCliCommandParser()
        parser.load_command_table(cmd_table)

        args = parser.parse_args('test command --req yep nope'.split())
        self.assertIs(args.func, command)

        AzCliCommandParser.error = VerifyError(self)
        parser.parse_args('test command -req yep'.split())
        self.assertTrue(AzCliCommandParser.error.called)
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:19,代码来源:test_parser.py

示例14: test_help_param

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_help_param(self):
        def test_handler():
            pass

        command = CliCommand("n1", test_handler)
        command.add_argument("arg", "--arg", "-a", required=False)
        command.add_argument("b", "-b", required=False)
        cmd_table = {"n1": command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application()
        app.initialize(config)
        with self.assertRaises(SystemExit):
            app.execute("n1 -h".split())

        with self.assertRaises(SystemExit):
            app.execute("n1 --help".split())
开发者ID:yugangw-msft,项目名称:azure-cli,代码行数:20,代码来源:test_help.py

示例15: test_help_long_description_and_short_description

# 需要导入模块: from azure.cli.core.commands import CliCommand [as 别名]
# 或者: from azure.cli.core.commands.CliCommand import add_argument [as 别名]
    def test_help_long_description_and_short_description(self):
        def test_handler():
            pass

        command = CliCommand("n1", test_handler, description="short description")
        command.add_argument("arg", "--arg", "-a", required=False)
        command.add_argument("b", "-b", required=False)
        command.help = "long description"
        cmd_table = {"n1": command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

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


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