How to use the cleo.application.Application function in cleo

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 / 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 / test_application.py View on Github external
def test_find_alternative_commands(self):
        application = Application()
        application.add(FooCommand())
        application.add(Foo1Command())
        application.add(Foo2Command())

        command_name = 'Unknown command'
        try:
            application.find(command_name)
            self.fail('.find() raises an Exception if command does not exist')
        except Exception as e:
            self.assertEqual(
                'Command "%s" is not defined.' % command_name,
                str(e)
            )

        command_name = 'bar1'
        try:
github sdispater / cleo / tests / test_application.py View on Github external
def test_find_ambiguous_namespace(self):
        """
        Application.find_namespace() should raise an error when namespace is ambiguous
        """
        application = Application()
        application.add(BarBucCommand())
        application.add(FooCommand())
        application.add(Foo2Command())

        self.assertRaisesRegexp(
            Exception,
            'The namespace "f" is ambiguous \(foo, foo1\)\.',
            application.find_namespace,
            'f'
        )
github sdispater / cleo / tests / test_application.py View on Github external
def test_help(self):
        """
        Application.get_help() returns the help message of the application
        """
        application = Application()

        self.assertEqual(
            self.open_fixture('application_gethelp.txt'),
            application.get_help()
        )
github sdispater / cleo / tests / test_application.py View on Github external
def find_alternative_commands_with_an_alias(self):
        foo_command = FooCommand()
        foo_command.set_aliases(['foo2'])

        application = Application()
        application.add(foo_command)

        result = application.find('foo')

        self.assertEqual(foo_command, result)
github sdispater / cleo / tests / test_application.py View on Github external
def test_find_alternative_exception_message_single(self):
        """
        Application.find() raises an exception when an alternative has been found
        """
        data = [
            'foo3:baR',
            'foO3:bar'
        ]

        application = Application()
        application.add(Foo3Command())

        for d in data:
            self.assertRaisesRegexp(
                Exception,
                'Did you mean this',
                application.find,
                d
            )
github sdispater / cleo / tests / test_application.py View on Github external
def test_get_long_version(self):
        """
        Application.get_long_version() returns the long version of the application
        """
        application = Application('foo', 'bar')

        self.assertEqual(
            'foo bar',
            application.get_long_version()
        )
github sdispater / cleo / tests / test_application.py View on Github external
def test_add_command_with_empty_constructor(self):
        """
        Application.add() should raise an exception when command constructor is empty
        """
        application = Application()

        self.assertRaisesRegexp(
            Exception,
            'Command class "Foo5Command" is not correctly initialized\.'
            'You probably forgot to call the parent constructor\.',
            application.add,
            Foo5Command()
        )
github sdispater / cleo / cleo / descriptors / descriptor.py View on Github external
:param options: The options
        :type options: dict
        """
        from ..application import Application

        self.output = output

        if isinstance(obj, InputArgument):
            self._describe_input_argument(obj, **options)
        elif isinstance(obj, InputOption):
            self._describe_input_option(obj, **options)
        elif isinstance(obj, InputDefinition):
            self._describe_input_definition(obj, **options)
        elif isinstance(obj, BaseCommand):
            self._describe_command(obj, **options)
        elif isinstance(obj, Application):
            self._describe_application(obj, **options)
        else:
            raise CleoException(
                'Object of type "%s" is not describable' % obj.__class__.__name__
            )