Example #1
0
    def test_help_with_param_specified(self, _):
        def test_handler():
            pass

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

        with mock.patch.object(CLICommandsLoader, 'load_command_table', return_value=cmd_table):
            with self.assertRaises(SystemExit):
                self.mock_ctx.invoke('n1 --arg foo -h'.split())

        s = """
Command
    {} n1

Arguments
    --arg -a
    -b

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

        self.assertEqual(s.format(self.cliname), io.getvalue())
Example #2
0
    def test_help_full_documentations(self, _):
        def test_handler():
            pass

        self.mock_ctx = MockContext()
        command = CLICommand(self.mock_ctx, '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:
                        - mycli abc xyz
                        - 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}

        with mock.patch.object(CLICommandsLoader, 'load_command_table', return_value=cmd_table):
            with self.assertRaises(SystemExit):
                self.mock_ctx.invoke('n1 -h'.split())
        s = """
Command
    {} 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: mycli abc xyz, default.
        Text, markdown, etc.

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

Examples
    foo example
        example details

"""
        self.assertEqual(s.format(self.cliname), io.getvalue())
Example #3
0
    def test_help_params_documentations(self, _):
        def test_handler():
            pass

        self.mock_ctx = MockContext()
        command = CLICommand(self.mock_ctx, '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:
                    - mycli abc xyz
                    - default
                - name: --foobar2 -fb2
                  type: string
                  required: true
                  short-summary: one line partial sentence
                  long-summary: paragraph(s)
            """
        cmd_table = {'n1': command}

        with mock.patch.object(CLICommandsLoader, 'load_command_table', return_value=cmd_table):
            with self.assertRaises(SystemExit):
                self.mock_ctx.invoke('n1 -h'.split())
        s = """
Command
    {} n1

Arguments
    --foobar2 -fb2 [Required]: One line partial sentence.
        Paragraph(s).
    --foobar -fb             : One line partial sentence.  Values from: mycli abc xyz, default.
        Text, markdown, etc.
    --foobar3 -fb3           : The foobar3.

Global Arguments
    --help -h                : Show this help message and exit.
"""
        self.assertEqual(s.format(self.cliname), io.getvalue())
Example #4
0
    def test_help_global_params(self, _):

        def register_globals(_, **kwargs):
            arg_group = kwargs.get('arg_group')
            arg_group.add_argument('--exampl',
                                   help='This is a new global argument.')

        self.mock_ctx = MockContext()
        self.mock_ctx._event_handlers[EVENT_PARSER_GLOBAL_CREATE].append(register_globals)  # pylint: disable=protected-access

        def test_handler():
            pass

        command = CLICommand(self.mock_ctx, '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}

        with mock.patch.object(CLICommandsLoader, 'load_command_table', return_value=cmd_table):
            with self.assertRaises(SystemExit):
                self.mock_ctx.invoke('n1 -h'.split())

        s = """
Command
    {} n1
        Line1
        line2.

Arguments
    --arg -a
    -b

Global Arguments
    --exampl : This is a new global argument.
    --help -h: Show this help message and exit.
"""
        self.assertEqual(s.format(self.cliname), io.getvalue())
Example #5
0
 def setUp(self):
     self.mock_ctx = MockContext()
     self.io = StringIO()
 def setUp(self):
     self.mock_ctx = MockContext()
Example #7
0
 def setUp(self):
     self.mock_ctx = MockContext()
     self.cli_logging = CLILogging('clitest', cli_ctx=self.mock_ctx)
Example #8
0
 def setUp(self):
     self.mock_ctx = MockContext()
     self.cli_query = CLIQuery(cli_ctx=self.mock_ctx)
Example #9
0
 def setUp(self):
     self.mock_ctx = MockContext()
     self.cliname = self.mock_ctx.name