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


Python commands.CliCommand类代码示例

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


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

示例1: test_help_with_param_specified

    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,代码行数:30,代码来源:test_help.py

示例2: test_case_insensitive_enum_choices

    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,代码行数:27,代码来源:test_parser.py

示例3: test_case_insensitive_command_path

    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,代码行数:33,代码来源:test_application.py

示例4: test_help_group_children

    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,代码行数:25,代码来源:test_help.py

示例5: test_choice_list_with_ints

    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,代码行数:15,代码来源:test_help.py

示例6: test_help_plain_short_description

    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,代码行数:16,代码来源:test_help.py

示例7: test_required_parameter

    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,代码行数:17,代码来源:test_parser.py

示例8: test_nargs_parameter

    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,代码行数:17,代码来源:test_parser.py

示例9: test_help_param

    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:BurtBiel,项目名称:azure-cli,代码行数:18,代码来源:test_help.py

示例10: test_help_full_documentations

    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,代码行数:60,代码来源:test_help.py

示例11: test_help_params_documentations

    def test_help_params_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.add_argument('foobar3', '--foobar3', '-fb3', required=False, help='the foobar3')
        command.help = """
            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)
            """
        cmd_table = {'n1': command}

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

        with self.assertRaises(SystemExit):
            app.execute('n1 -h'.split())
        s = """
Command
    az n1

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.
    --foobar3 -fb3           : The foobar3.

Global Arguments
    --help -h                : Show this help message and exit.
"""
        self.assertEqual(s, io.getvalue())
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:49,代码来源:test_help.py

示例12: test_list_value_parameter

    def test_list_value_parameter(self):
        hellos = []

        def handler(args):
            hellos.append(args)

        command = CliCommand('test command', handler)
        command.add_argument('hello', '--hello', nargs='+', action=IterateAction)
        command.add_argument('something', '--something')
        cmd_table = {'test command': command}

        argv = 'az test command --hello world sir --something else'.split()
        config = Configuration()
        config.get_command_table = lambda argv: cmd_table
        application = Application(config)
        application.execute(argv[1:])

        self.assertEqual(2, len(hellos))
        self.assertEqual(hellos[0]['hello'], 'world')
        self.assertEqual(hellos[0]['something'], 'else')
        self.assertEqual(hellos[1]['hello'], 'sir')
        self.assertEqual(hellos[1]['something'], 'else')
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:22,代码来源:test_application.py

示例13: test_help_extra_missing_params

    def test_help_extra_missing_params(self):
        app = Application(Configuration([]))

        def test_handler(foobar2, foobar=None):  # pylint: disable=unused-argument
            pass

        command = CliCommand("n1", test_handler)
        command.add_argument("foobar", "--foobar", "-fb", required=False)
        command.add_argument("foobar2", "--foobar2", "-fb2", required=True)
        cmd_table = {"n1": command}

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

        # work around an argparse behavior where output is not printed and SystemExit
        # is not raised on Python 2.7.9
        if sys.version_info < (2, 7, 10):
            try:
                app.execute("n1 -fb a --foobar value".split())
            except SystemExit:
                pass

            try:
                app.execute("n1 -fb a --foobar2 value --foobar3 extra".split())
            except SystemExit:
                pass
        else:
            with self.assertRaises(SystemExit):
                app.execute("n1 -fb a --foobar value".split())
            with self.assertRaises(SystemExit):
                app.execute("n1 -fb a --foobar2 value --foobar3 extra".split())

            self.assertTrue(
                "required" in io.getvalue()
                and "--foobar/-fb" not in io.getvalue()
                and "--foobar2/-fb2" in io.getvalue()
                and "unrecognized arguments: --foobar3 extra" in io.getvalue()
            )
开发者ID:yugangw-msft,项目名称:azure-cli,代码行数:39,代码来源:test_help.py

示例14: test_help_global_params

    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,代码行数:53,代码来源:test_help.py

示例15: test_help_global_params

    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,代码行数:46,代码来源:test_help.py


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