How to use cleo - 10 common examples

To help you get started, we’ve selected a few cleo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sdispater / cleo / cleo / helpers / table.py View on Github external
def _get_cell_width(self, row, column):
        """
        Gets cell width.

        :type row: list

        :type column: int

        :rtype: int
        """
        try:
            cell = row[column]
            cell_width = Helper.len_without_decoration(self._output.get_formatter(), cell)

            if isinstance(cell, TableCell) and cell.colspan > 1:
                # we assume that cell value will be across more than one column.
                cell_width = cell_width // cell.colspan

            return cell_width

        except IndexError:
            return 0
github sdispater / cleo / tests / test_application.py View on Github external
def test_setting_input_definition_overwrites_default_values(self):
        application = Application()
        application.set_auto_exit(False)
        application.set_catch_exceptions(False)

        application.set_definition(InputDefinition([
            InputOption('--custom', '-c',
                        InputOption.VALUE_NONE,
                        'Set the custom input definition.')
        ]))

        definition = application.get_definition()

        self.assertFalse(definition.has_argument('command'))

        self.assertFalse(definition.has_option('help'))
        self.assertFalse(definition.has_option('quiet'))
        self.assertFalse(definition.has_option('verbose'))
        self.assertFalse(definition.has_option('version'))
        self.assertFalse(definition.has_option('ansi'))
        self.assertFalse(definition.has_option('no-ansi'))
        self.assertFalse(definition.has_option('no-interaction'))
github sdispater / cleo / tests / test_application.py View on Github external
def test_set_run_custom_single_command(self):
        command = FooCommand()

        application = Application()
        application.set_auto_exit(False)
        application.add(command)
        application.set_default_command(command.get_name(), True)

        tester = ApplicationTester(application)

        tester.run([])
        self.assertIn('called', tester.get_display())

        tester.run([('--help', True)])
        self.assertIn('The foo:bar command', tester.get_display())
github sdispater / cleo / tests / test_application.py View on Github external
def test_get_default_input_definition_returns_default_values(self):
        application = Application()
        application.set_auto_exit(False)
        application.set_catch_exceptions(False)

        definition = application.get_definition()

        self.assertTrue(definition.has_argument('command'))

        self.assertTrue(definition.has_option('help'))
        self.assertTrue(definition.has_option('quiet'))
        self.assertTrue(definition.has_option('verbose'))
        self.assertTrue(definition.has_option('version'))
        self.assertTrue(definition.has_option('ansi'))
        self.assertTrue(definition.has_option('no-ansi'))
        self.assertTrue(definition.has_option('no-interaction'))
github sdispater / cleo / tests / outputs / test_output.py View on Github external
def test_init(self):
        output = MyOutput(Output.VERBOSITY_QUIET, True)
        self.assertEqual(Output.VERBOSITY_QUIET, output.get_verbosity())
        self.assertTrue(output.is_decorated())
github sdispater / cleo / tests / test_application.py View on Github external
Application.render_exception() displays formatted exception.
        """
        application = Application()
        application.set_auto_exit(False)

        os.environ['COLUMNS'] = '120'
        tester = ApplicationTester(application)

        tester.run([('command', 'foo')], {'decorated': False})
        self.assertEqual(
            self.open_fixture('application_renderexception1.txt'),
            tester.get_display()
        )

        tester.run([('command', 'foo')],
                   {'decorated': False, 'verbosity': Output.VERBOSITY_VERBOSE})
        self.assertRegex(
            tester.get_display(),
            'Exception trace'
        )

        tester.run([('command', 'list'), ('--foo', True)], {'decorated': False})
        self.assertEqual(
            self.open_fixture('application_renderexception2.txt'),
            tester.get_display()
        )

        application.add(Foo3Command())
        tester = ApplicationTester(application)
        tester.run([('command', 'foo3:bar')], {'decorated': False})
        self.assertEqual(
            self.open_fixture('application_renderexception3.txt'),
github sdispater / cleo / tests / outputs / test_stream_output.py View on Github external
def test_init(self):
        output = StreamOutput(self.stream, Output.VERBOSITY_QUIET, True)
        self.assertEqual(Output.VERBOSITY_QUIET, output.get_verbosity())
        self.assertTrue(output.is_decorated())
github sdispater / cleo / tests / inputs / test_input_option.py View on Github external
def test_init(self):
        """
        InputOption.__init__() behaves properly
        """
        option = InputOption('foo')
        self.assertEqual('foo', option.get_name(), msg='__init__() takes a name as its first argument')
        option = InputOption('--foo')
        self.assertEqual('foo', option.get_name(), msg='__init__() removes the leading -- of the option name')

        # shortcut argument
        option = InputOption('foo', 'f')
        self.assertEqual('f', option.get_shortcut(), msg='__init__() can take a shortcut as its second argument')
        option = InputOption('foo', '-f')
        self.assertEqual('f', option.get_shortcut(), msg='__init__() removes the leading - of the shortcut')
        option = InputOption('foo')
        self.assertEqual(None, option.get_shortcut(), msg='__init__() makes the shortcut null by default')

        # mode argument
        option = InputOption('foo', 'f')
        self.assertFalse(option.accept_value(),
                         msg='__init__() gives a "InputOption.VALUE_NONE" mode by default')
github sdispater / cleo / tests / inputs / test_input_option.py View on Github external
def test_init(self):
        """
        InputOption.__init__() behaves properly
        """
        option = InputOption('foo')
        self.assertEqual('foo', option.get_name(), msg='__init__() takes a name as its first argument')
        option = InputOption('--foo')
        self.assertEqual('foo', option.get_name(), msg='__init__() removes the leading -- of the option name')

        # shortcut argument
        option = InputOption('foo', 'f')
        self.assertEqual('f', option.get_shortcut(), msg='__init__() can take a shortcut as its second argument')
        option = InputOption('foo', '-f')
        self.assertEqual('f', option.get_shortcut(), msg='__init__() removes the leading - of the shortcut')
        option = InputOption('foo')
        self.assertEqual(None, option.get_shortcut(), msg='__init__() makes the shortcut null by default')

        # mode argument
        option = InputOption('foo', 'f')
        self.assertFalse(option.accept_value(),
                         msg='__init__() gives a "InputOption.VALUE_NONE" mode by default')
        self.assertFalse(option.is_value_required(),
                         msg='__init__() gives a "InputOption.VALUE_NONE" mode by default')
github sdispater / cleo / tests / formatters / test_output_formatter_style.py View on Github external
def test_init(self):
        style = OutputFormatterStyle('green', 'black', ['bold', 'underscore'])
        self.assertEqual('\033[32;40;1;4mfoo\033[0m', style.apply('foo'))

        style = OutputFormatterStyle('red', None, ['blink'])
        self.assertEqual('\033[31;5mfoo\033[0m', style.apply('foo'))

        style = OutputFormatterStyle(None, 'white')
        self.assertEqual('\033[47mfoo\033[0m', style.apply('foo'))