示例#1
0
    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())
示例#2
0
    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())
示例#3
0
    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(argv)
        config.get_command_table = lambda: 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')
示例#4
0
    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())
示例#5
0
    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())
示例#6
0
    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())
示例#7
0
    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())
示例#8
0
    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())
示例#9
0
    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())
示例#10
0
    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: 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())
示例#11
0
    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())
示例#12
0
    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())
示例#13
0
    def test_client_request_id_is_refreshed_after_execution(self):
        def _handler(args):
            return True

        config = Configuration()
        config.get_command_table = lambda *_: {'test': CliCommand('test', _handler)}
        app = Application(config)

        app.execute(['test'])
        self.assertIn('x-ms-client-request-id', app.session['headers'])
        old_id = app.session['headers']['x-ms-client-request-id']

        app.execute(['test'])
        self.assertIn('x-ms-client-request-id', app.session['headers'])
        self.assertNotEquals(old_id, app.session['headers']['x-ms-client-request-id'])
示例#14
0
    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())
示例#15
0
    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())
示例#16
0
    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())
示例#17
0
    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())
示例#18
0
    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())
示例#19
0
    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
示例#20
0
    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
示例#21
0
    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())
示例#22
0
    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())
    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)
    def test_client_request_id_is_refreshed_after_execution(self):
        def _handler(args):
            return True

        config = Configuration()
        config.get_command_table = lambda *_: {
            'test': CliCommand('test', _handler)
        }
        app = Application(config)

        app.execute(['test'])
        self.assertIn('x-ms-client-request-id', app.session['headers'])
        old_id = app.session['headers']['x-ms-client-request-id']

        app.execute(['test'])
        self.assertIn('x-ms-client-request-id', app.session['headers'])
        self.assertNotEquals(old_id,
                             app.session['headers']['x-ms-client-request-id'])
示例#25
0
    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())
    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(self.argv)
        config.get_command_table = lambda: command_table
        self.application = Application(config)
示例#27
0
    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())
示例#28
0
    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())
示例#29
0
    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
示例#30
0
    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())
示例#31
0
    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()
            )
示例#32
0
    def test_help_long_description_multi_line(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)
        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())

        self.assertEqual(True, io.getvalue().startswith('\nCommand\n    az n1\n        Line1\n        line2.')) # pylint: disable=line-too-long
示例#33
0
    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')
示例#34
0
    def test_help_long_description_multi_line(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)
        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())

        self.assertEqual(True, io.getvalue().startswith('\nCommand\n    az n1\n        Line1\n        line2.')) # pylint: disable=line-too-long
示例#35
0
    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())
示例#36
0
 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:])
示例#37
0
 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:])
示例#38
0
def main():
    parser = argparse.ArgumentParser(description='Azure Shell CLI Index Generator')
    parser.add_argument(
        '-o','--output',
        help='Azure Shell index file output path (ex. /tmp/cli-index.json)')
    parser.add_argument(
        '--verbose', action='store_true',
        help='Increase verbosity')
    args = parser.parse_args()

    ## Logging config
    handler = logging.StreamHandler(sys.stdout)
    if args.verbose:
        handler.setLevel(logging.DEBUG)
        logger.setLevel(logging.DEBUG)
    else:
        handler.setLevel(logging.INFO)
        logger.setLevel(logging.INFO)
    logger.addHandler(handler)

    # Output file validation and config
    if not args.output:
        logger.error('[ERROR] No output file specified with -o or --output param!')
        sys.exit(1)
    output_file = os.path.abspath(args.output)
    if not os.path.isdir(os.path.dirname(output_file)):
        logger.error('[ERROR] No directory exists for output file:{}'.format(output_file))
        sys.exit(1)
 
    ## az executable command path check
    if not find_executable_path('az'):
        logger.error("[ERROR] NO azure cli (az) executable command found!")
        logger.error("Please install Azure CLI 2.0 and set its executable dir to PATH")
        logger.error("See https://github.com/Azure/azure-cli")
        sys.exit(1)

    azure_cli_version = get_cli_version()
    ## Check minimum azure-cli version
    if azure_cli_version < AZURE_SHELL_MINIMUM_AZURE_CLI_VERSION:
        logger.error("[ERROR] Azure CLI 2.0 minimum version failure!")
        logger.error("Minimum azure-cli version required: {} (Your version: {})".format(
                    AZURE_SHELL_MINIMUM_AZURE_CLI_VERSION, azure_cli_version))
        logger.error("Please install the latest azure-cli and set its executable dir to PATH")
        logger.error("See https://github.com/Azure/azure-cli")
        sys.exit(1)    

    ## Import Azure CLI core modules
    module_import_trial_count = 0
    while True:
        try:
            from azure.cli.core.help_files import helps
            from azure.cli.core.application import APPLICATION, Configuration
            break    
        except ImportError:
            if module_import_trial_count > 0:
                logger.error("[ERROR] azure.cli.core module import failure!")
                sys.exit(1)
            ## Getting AzureCLI modules path and append it to current path list
            azurecli_modules_path = get_azurecli_modules_path()
            if azurecli_modules_path:
                sys.path.append(azurecli_modules_path)
        module_import_trial_count = module_import_trial_count + 1

    ## Get command table via acure.cli.core
    azure_cli_version = get_cli_version()
    cmd_table = {}
    if azure_cli_version < '2.0.3':  # External I/F has been changed since azure-cli-2.0.3
        cmd_table = APPLICATION.configuration.get_command_table()
    else:
        config = Configuration()
        cmd_table = config.get_command_table()

    groups_map = {}
    cmds_map = {}
    groups_map = get_groups(cmd_table)
    ## Populate subgroups for each groups
    for group_name in groups_map.keys():
        parent_name = get_parent_name_from_group_name(group_name)
        if parent_name:
            groups_map[parent_name]['subgroups'].append(group_name)

    logger.info("Start generating index...")
    logger.info("Output index file: {}".format(output_file))

    ## Get command list
    cmd_list = cmd_table.keys()
    for cmd in cmd_list:
        try:
            cmds_map[cmd] = capture_cmd(cmd)
        except:
            pass

    ## Create Json Tree from root 'az' group
    index_tree = new_index_command_tree()
    group_to_index_tree(index_tree, 'az', groups_map,cmds_map)
    root_tree = {'az': index_tree}
    result_json = json.dumps(root_tree)
    
    ## Write json to your specified output file
    with open(output_file, "w") as f:
        f.write(result_json)
示例#39
0
import os
import re
import subprocess
import sys

from azure.cli.core.application import Configuration

class Exporter(json.JSONEncoder):

    def default(self, o):#pylint: disable=method-hidden
        try:
            return super(Exporter, self).default(o)
        except TypeError:
            return str(o)

parser = argparse.ArgumentParser(description='Command Table Parser')
parser.add_argument('--commands', metavar='N', nargs='+', help='Filter by command scope')
args = parser.parse_args()
cmd_set_names = args.commands

# ignore the params passed in now so they aren't used by the cli
sys.argv = sys.argv[:1]
config = Configuration([])
cmd_table = config.get_command_table()
cmd_list = sorted([cmd_name for cmd_name in cmd_table.keys() if cmd_set_names is None or cmd_name.split()[0] in cmd_set_names])

for cmd in cmd_list:
    cmd_string = 'az {} -h'.format(cmd)
    os.system(cmd_string)
    print('\n===============================', flush=True)
示例#40
0
def verify_packages(built_packages_dir):
    all_modules = automation_path.get_all_module_paths()
    all_command_modules = automation_path.get_command_modules_paths(
        include_prefix=True)

    modules_missing_manifest_in = [
        name for name, path in all_modules
        if not os.path.isfile(os.path.join(path, 'MANIFEST.in'))
    ]
    if modules_missing_manifest_in:
        print_heading(
            'Error: The following modules are missing the MANIFEST.in file.')
        print(modules_missing_manifest_in)
        sys.exit(1)

    # STEP 1:: Validate the installation
    try:
        az_output = subprocess.check_output(['az', '--debug'],
                                            stderr=subprocess.STDOUT,
                                            universal_newlines=True)
        success = 'Error loading command module' not in az_output
        print(az_output, file=sys.stderr)
    except subprocess.CalledProcessError as err:
        success = False
        print(err, file=sys.stderr)

    if not success:
        print_heading('Error running the CLI!', f=sys.stderr)
        sys.exit(1)

    # STEP 2:: Run -h on each command
    print('Running --help on all commands.')
    from azure.cli.core.application import Configuration
    config = Configuration()

    all_commands = list(config.get_command_table())
    command_results = []
    p = multiprocessing.Pool(multiprocessing.cpu_count())
    for i, res in enumerate(
            p.imap_unordered(run_help_on_command_without_err, all_commands,
                             10), 1):
        sys.stderr.write('{}/{} \t'.format(i, len(all_commands)))
        sys.stderr.flush()
        command_results.append(res)

    p.close()
    p.join()
    if not all(command_results):
        print_heading('Error running --help on commands in the CLI!',
                      f=sys.stderr)
        sys.exit(1)
    print('OK.')

    # STEP 3:: Determine if any modules failed to install

    pip.utils.pkg_resources = imp.reload(pip.utils.pkg_resources)
    installed_command_modules = [
        dist.key for dist in pip.get_installed_distributions(local_only=True)
        if dist.key.startswith(COMMAND_MODULE_PREFIX)
    ]

    print('Installed command modules', installed_command_modules)

    missing_modules = set([name for name, fullpath in all_command_modules]) - set(installed_command_modules) - \
                      EXCLUDE_MODULES

    if missing_modules:
        print_heading(
            'Error: The following modules were not installed successfully',
            f=sys.stderr)
        print(missing_modules, file=sys.stderr)
        sys.exit(1)

    # STEP 4:: Verify the wheels that get produced
    print_heading('Verifying wheels...')
    invalid_wheels = []
    for wheel_path in glob.glob(os.path.join(built_packages_dir, '*.whl')):
        # Verify all non-nspkg wheels
        if 'nspkg' not in wheel_path and not _valid_wheel(wheel_path):
            invalid_wheels.append(wheel_path)
    if invalid_wheels:
        print_heading('Error: The following wheels are invalid', f=sys.stderr)
        print(invalid_wheels, file=sys.stderr)
        print(VALID_WHEEL_HELP, file=sys.stderr)
        sys.exit(1)
    print_heading('Verified wheels successfully.')

    print_heading('OK')
示例#41
0
    def test_help_group_help(self):
        app = Application(Configuration([]))

        def test_handler():
            pass

        azure.cli.core.help_files.helps['test_group1 test_group2'] = """
            type: group
            short-summary: this module does xyz one-line or so
            long-summary: |
                this module.... kjsdflkj... klsfkj paragraph1
                this module.... kjsdflkj... klsfkj paragraph2
            examples:
                - name: foo example
                  text: example details
            """

        command = CliCommand('test_group1 test_group2 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 = {'test_group1 test_group2 n1': command}

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

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

Commands:
    n1: This module does xyz one-line or so.


Examples
    foo example
        example details
"""
        self.assertEqual(s, io.getvalue())

        del azure.cli.core.help_files.helps['test_group1 test_group2']
示例#42
0
def verify_packages():
    # tmp dir to store all the built packages
    built_packages_dir = tempfile.mkdtemp()

    all_modules = automation_path.get_all_module_paths()
    all_command_modules = automation_path.get_command_modules_paths(
        include_prefix=True)

    modules_missing_manifest_in = [
        name for name, path in all_modules
        if not os.path.isfile(os.path.join(path, 'MANIFEST.in'))
    ]
    if modules_missing_manifest_in:
        print_heading(
            'Error: The following modules are missing the MANIFEST.in file.')
        print(modules_missing_manifest_in)
        sys.exit(1)

    # STEP 1:: Build the packages
    for name, path in all_modules:
        build_package(path, built_packages_dir)

    # STEP 2:: Install the CLI and dependencies
    azure_cli_modules_path = next(path for name, path in all_modules
                                  if name == 'azure-cli')
    install_package(azure_cli_modules_path, 'azure-cli', built_packages_dir)

    # Install the remaining command modules
    for name, fullpath in all_command_modules:
        install_package(fullpath, name, built_packages_dir)

    # STEP 3:: Validate the installation
    try:
        az_output = subprocess.check_output(['az', '--debug'],
                                            stderr=subprocess.STDOUT,
                                            universal_newlines=True)
        success = 'Error loading command module' not in az_output
        print(az_output, file=sys.stderr)
    except subprocess.CalledProcessError as err:
        success = False
        print(err, file=sys.stderr)

    if not success:
        print_heading('Error running the CLI!', f=sys.stderr)
        sys.exit(1)

    # STEP 4:: Run -h on each command
    print('Running --help on all commands.')
    from azure.cli.core.application import Configuration
    config = Configuration()

    all_commands = list(config.get_command_table())
    pool_size = 5
    chunk_size = 10
    command_results = []
    p = multiprocessing.Pool(pool_size)
    prev_percent = 0
    for i, res in enumerate(
            p.imap_unordered(run_help_on_command_without_err, all_commands,
                             chunk_size), 1):
        command_results.append(res)
        cur_percent = int((i / len(all_commands)) * 100)
        if cur_percent != prev_percent:
            print('{}% complete'.format(cur_percent), file=sys.stderr)
        prev_percent = cur_percent
    p.close()
    p.join()
    if not all(command_results):
        print_heading('Error running --help on commands in the CLI!',
                      f=sys.stderr)
        sys.exit(1)
    print('OK.')

    # STEP 5:: Determine if any modules failed to install

    pip.utils.pkg_resources = imp.reload(pip.utils.pkg_resources)
    installed_command_modules = [
        dist.key for dist in pip.get_installed_distributions(local_only=True)
        if dist.key.startswith(COMMAND_MODULE_PREFIX)
    ]

    print('Installed command modules', installed_command_modules)

    missing_modules = \
        set([name for name, fullpath in all_command_modules]) - set(installed_command_modules)

    if missing_modules:
        print_heading(
            'Error: The following modules were not installed successfully',
            f=sys.stderr)
        print(missing_modules, file=sys.stderr)
        sys.exit(1)

    # STEP 6:: Verify the wheels that get produced
    print_heading('Verifying wheels...')
    invalid_wheels = []
    for wheel_path in glob.glob(os.path.join(built_packages_dir, '*.whl')):
        # Verify all non-nspkg wheels
        if 'nspkg' not in wheel_path and not _valid_wheel(wheel_path):
            invalid_wheels.append(wheel_path)
    if invalid_wheels:
        print_heading('Error: The following wheels are invalid', f=sys.stderr)
        print(invalid_wheels, file=sys.stderr)
        print(VALID_WHEEL_HELP, file=sys.stderr)
        sys.exit(1)
    print_heading('Verified wheels successfully.')

    print_heading('OK')
示例#43
0
def verify_packages(built_packages_dir):
    all_modules = automation_path.get_all_module_paths()
    all_command_modules = automation_path.get_command_modules_paths(include_prefix=True)

    modules_missing_manifest_in = [name for name, path in all_modules if not os.path.isfile(os.path.join(path, 'MANIFEST.in'))]
    if modules_missing_manifest_in:
        print_heading('Error: The following modules are missing the MANIFEST.in file.')
        print(modules_missing_manifest_in)
        sys.exit(1)

    # STEP 1:: Validate the installation
    try:
        az_output = subprocess.check_output(['az', '--debug'], stderr=subprocess.STDOUT,
                                            universal_newlines=True)
        success = 'Error loading command module' not in az_output
        print(az_output, file=sys.stderr)
    except subprocess.CalledProcessError as err:
        success = False
        print(err, file=sys.stderr)

    if not success:
        print_heading('Error running the CLI!', f=sys.stderr)
        sys.exit(1)

    # STEP 2:: Run -h on each command
    print('Running --help on all commands.')
    from azure.cli.core.application import Configuration
    config = Configuration()

    all_commands = list(config.get_command_table())
    command_results = []
    p = multiprocessing.Pool(multiprocessing.cpu_count())
    for i, res in enumerate(p.imap_unordered(run_help_on_command_without_err, all_commands, 10), 1):
        sys.stderr.write('{}/{} \t'.format(i, len(all_commands)))
        sys.stderr.flush()
        command_results.append(res)

    p.close()
    p.join()
    if not all(command_results):
        print_heading('Error running --help on commands in the CLI!', f=sys.stderr)
        sys.exit(1)
    print('OK.')

    # STEP 3:: Determine if any modules failed to install

    pip.utils.pkg_resources = imp.reload(pip.utils.pkg_resources)
    installed_command_modules = [dist.key for dist in
                                 pip.get_installed_distributions(local_only=True)
                                 if dist.key.startswith(COMMAND_MODULE_PREFIX)]

    print('Installed command modules', installed_command_modules)

    missing_modules = set([name for name, fullpath in all_command_modules]) - set(installed_command_modules) - \
                      EXCLUDE_MODULES

    if missing_modules:
        print_heading('Error: The following modules were not installed successfully', f=sys.stderr)
        print(missing_modules, file=sys.stderr)
        sys.exit(1)

    # STEP 4:: Verify the wheels that get produced
    print_heading('Verifying wheels...')
    invalid_wheels = []
    for wheel_path in glob.glob(os.path.join(built_packages_dir, '*.whl')):
        # Verify all non-nspkg wheels
        if 'nspkg' not in wheel_path and not _valid_wheel(wheel_path):
            invalid_wheels.append(wheel_path)
    if invalid_wheels:
        print_heading('Error: The following wheels are invalid', f=sys.stderr)
        print(invalid_wheels, file=sys.stderr)
        print(VALID_WHEEL_HELP, file=sys.stderr)
        sys.exit(1)
    print_heading('Verified wheels successfully.')

    print_heading('OK')
示例#44
0
    def test_help_group_help(self):
        app = Application(Configuration([]))
        def test_handler():
            pass

        azure.cli.core.help_files.helps['test_group1 test_group2'] = """
            type: group
            short-summary: this module does xyz one-line or so
            long-summary: |
                this module.... kjsdflkj... klsfkj paragraph1
                this module.... kjsdflkj... klsfkj paragraph2
            examples:
                - name: foo example
                  text: example details
            """

        command = CliCommand('test_group1 test_group2 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 = {'test_group1 test_group2 n1': command}

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

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

Commands:
    n1: This module does xyz one-line or so.


Examples
    foo example
        example details
"""
        self.assertEqual(s, io.getvalue())

        del azure.cli.core.help_files.helps['test_group1 test_group2']
parser.add_argument('--commands',
                    metavar='N',
                    nargs='+',
                    help='Filter by first level command (OR)')
parser.add_argument('--params',
                    metavar='N',
                    nargs='+',
                    help='Filter by parameters (OR)')
args = parser.parse_args()
cmd_set_names = args.commands
param_names = args.params

# ignore the params passed in now so they aren't used by the cli
sys.argv = sys.argv[:1]
config = Configuration([])
cmd_table = config.get_command_table()
cmd_list = [
    cmd_name for cmd_name in cmd_table.keys()
    if cmd_set_names is None or cmd_name.split()[0] in cmd_set_names
]
results = []

if param_names:
    for name in cmd_list:
        cmd_name = [x for x in cmd_table.keys() if name == x][0]
        cmd_args = cmd_table[cmd_name]['arguments']
        match = False
        for arg in cmd_args:
            if match:
                break
            arg_name = re.sub('--', '', arg['name']).split(' ')[0]
示例#46
0
def verify_packages():
    # tmp dir to store all the built packages
    built_packages_dir = tempfile.mkdtemp()

    all_modules = automation_path.get_all_module_paths()
    all_command_modules = automation_path.get_command_modules_paths(include_prefix=True)

    modules_missing_manifest_in = [name for name, path in all_modules if not os.path.isfile(os.path.join(path, 'MANIFEST.in'))]
    if modules_missing_manifest_in:
        print_heading('Error: The following modules are missing the MANIFEST.in file.')
        print(modules_missing_manifest_in)
        sys.exit(1)

    # STEP 1:: Build the packages
    for name, path in all_modules:
        build_package(path, built_packages_dir)

    # STEP 2:: Install the CLI and dependencies
    azure_cli_modules_path = next(path for name, path in all_modules if name == 'azure-cli')
    install_package(azure_cli_modules_path, 'azure-cli', built_packages_dir)

    # Install the remaining command modules
    for name, fullpath in all_command_modules:
        install_package(fullpath, name, built_packages_dir)

    # STEP 3:: Validate the installation
    try:
        az_output = subprocess.check_output(['az', '--debug'], stderr=subprocess.STDOUT,
                                            universal_newlines=True)
        success = 'Error loading command module' not in az_output
        print(az_output, file=sys.stderr)
    except subprocess.CalledProcessError as err:
        success = False
        print(err, file=sys.stderr)

    if not success:
        print_heading('Error running the CLI!', f=sys.stderr)
        sys.exit(1)

    # STEP 4:: Run -h on each command
    print('Running --help on all commands.')
    from azure.cli.core.application import Configuration
    config = Configuration()

    all_commands = list(config.get_command_table())
    pool_size = 5
    chunk_size = 10
    command_results = []
    p = multiprocessing.Pool(pool_size)
    prev_percent = 0
    for i, res in enumerate(p.imap_unordered(run_help_on_command_without_err, all_commands, chunk_size), 1):
        command_results.append(res)
        cur_percent = int((i/len(all_commands))*100)
        if cur_percent != prev_percent:
            print('{}% complete'.format(cur_percent), file=sys.stderr)
        prev_percent = cur_percent
    p.close()
    p.join()
    if not all(command_results):
        print_heading('Error running --help on commands in the CLI!', f=sys.stderr)
        sys.exit(1)
    print('OK.')

    # STEP 5:: Determine if any modules failed to install

    pip.utils.pkg_resources = imp.reload(pip.utils.pkg_resources)
    installed_command_modules = [dist.key for dist in
                                 pip.get_installed_distributions(local_only=True)
                                 if dist.key.startswith(COMMAND_MODULE_PREFIX)]

    print('Installed command modules', installed_command_modules)

    missing_modules = \
        set([name for name, fullpath in all_command_modules]) - set(installed_command_modules)

    if missing_modules:
        print_heading('Error: The following modules were not installed successfully', f=sys.stderr)
        print(missing_modules, file=sys.stderr)
        sys.exit(1)

    # STEP 6:: Verify the wheels that get produced
    print_heading('Verifying wheels...')
    invalid_wheels = []
    for wheel_path in glob.glob(os.path.join(built_packages_dir, '*.whl')):
        # Verify all non-nspkg wheels
        if 'nspkg' not in wheel_path and not _valid_wheel(wheel_path):
            invalid_wheels.append(wheel_path)
    if invalid_wheels:
        print_heading('Error: The following wheels are invalid', f=sys.stderr)
        print(invalid_wheels, file=sys.stderr)
        print(VALID_WHEEL_HELP, file=sys.stderr)
        sys.exit(1)
    print_heading('Verified wheels successfully.')

    print_heading('OK')