How to use the cleo.inputs.InputDefinition 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 / inputs / test_input_definition.py View on Github external
def test_get_option_for_multi_shortcut(self):
        self.initialize_options()

        definition = InputDefinition([self.multi])
        self.assertEqual(self.multi, definition.get_option_for_shortcut('m'))
        self.assertEqual(self.multi, definition.get_option_for_shortcut('mmm'))
github sdispater / cleo / tests / inputs / test_input_definition.py View on Github external
def test_get_options_defaults(self):
        definition = InputDefinition([
            InputOption('foo1', None, InputOption.VALUE_NONE),
            InputOption('foo2', None, InputOption.VALUE_REQUIRED),
            InputOption('foo3', None, InputOption.VALUE_REQUIRED, '', 'default'),
            InputOption('foo4', None, InputOption.VALUE_OPTIONAL),
            InputOption('foo5', None, InputOption.VALUE_OPTIONAL, '', 'default'),
            InputOption('foo6', None, InputOption.VALUE_OPTIONAL | InputOption.VALUE_IS_LIST),
            InputOption('foo7', None, InputOption.VALUE_OPTIONAL | InputOption.VALUE_IS_LIST, '', [1, 2])
        ])
        defaults = {
            'foo1': False,
            'foo2': None,
            'foo3': 'default',
            'foo4': None,
            'foo5': 'default',
            'foo6': [],
            'foo7': [1, 2]
github sdispater / cleo / tests / test_application.py View on Github external
def get_default_input_definition(self):
        return InputDefinition([
            InputOption('--custom', '-c',
                        InputOption.VALUE_NONE,
                        'Set the custom input definition.')
        ])
github sdispater / cleo / tests / inputs / test_input_definition.py View on Github external
def test_get_synopsis(self):
        definition = InputDefinition([InputOption('foo')])
        self.assertEqual('[--foo]', definition.get_synopsis())
        definition = InputDefinition([InputOption('foo', 'f')])
        self.assertEqual('[-f|--foo]', definition.get_synopsis())
        definition = InputDefinition([InputOption('foo', 'f', InputOption.VALUE_REQUIRED)])
        self.assertEqual('[-f|--foo FOO]', definition.get_synopsis())
        definition = InputDefinition([InputOption('foo', 'f', InputOption.VALUE_OPTIONAL)])
        self.assertEqual('[-f|--foo [FOO]]', definition.get_synopsis())

        definition = InputDefinition([InputArgument('foo')])
        self.assertEqual('[]', definition.get_synopsis())
        definition = InputDefinition([InputArgument('foo', InputArgument.REQUIRED)])
        self.assertEqual('', definition.get_synopsis())
        definition = InputDefinition([InputArgument('foo', InputArgument.IS_LIST)])
        self.assertEqual('[]...', definition.get_synopsis())
        definition = InputDefinition([InputArgument('foo', InputArgument.REQUIRED | InputArgument.IS_LIST)])
        self.assertEqual(' ()...', definition.get_synopsis())
github sdispater / cleo / tests / inputs / test_input_definition.py View on Github external
def test_arguments_must_have_different_names(self):
        self.initialize_arguments()

        definition = InputDefinition()
        definition.add_argument(self.foo)
        self.assertRaisesRegexp(
            Exception,
            'An argument with name "foo" already exists.',
            definition.add_argument,
            self.foo1
        )
github sdispater / cleo / tests / inputs / test_input_definition.py View on Github external
def test_set_options(self):
        self.initialize_options()

        definition = InputDefinition([self.foo])
        self.assertEqual([self.foo], definition.get_options())
        definition.set_options([self.bar])
        self.assertEqual([self.bar], definition.get_options())
github sdispater / cleo / tests / inputs / test_argv_input.py View on Github external
['cli.py', '-f'],
                InputDefinition([
                    InputOption('foo', 'f', InputOption.VALUE_REQUIRED)
                ]),
                'The "--foo" option requires a value.'
            ),
            (
                ['cli.py', '-ffoo'],
                InputDefinition([
                    InputOption('foo', 'f', InputOption.VALUE_NONE)
                ]),
                'The "-o" option does not exist.'
            ),
            (
                ['cli.py', '--foo=bar'],
                InputDefinition([
                    InputOption('foo', 'f', InputOption.VALUE_NONE)
                ]),
                'The "--foo" option does not accept a value.'
            ),
            (
                ['cli.py', 'foo', 'bar'],
                InputDefinition(),
                'Too many arguments.'
            ),
            (
                ['cli.py', '--foo'],
                InputDefinition(),
                'The "--foo" option does not exist.'
            ),
            (
                ['cli.py', '-f'],
github sdispater / cleo / tests / inputs / test_list_input.py View on Github external
),
            (
                ['--foo'],
                InputDefinition([
                    InputOption('foo', 'f', InputOption.VALUE_REQUIRED)
                ]),
                'The "--foo" option requires a value.'
            ),
            (
                [('--foo', 'foo')],
                InputDefinition(),
                'The "--foo" option does not exist.'
            ),
            (
                [('-f', 'foo')],
                InputDefinition(),
                'The "-f" option does not exist.'
            ),
github sdispater / cleo / tests / inputs / test_input_definition.py View on Github external
def test_has_argument(self):
        self.initialize_arguments()

        definition = InputDefinition()
        definition.add_arguments([self.foo])

        self.assertTrue(definition.has_argument('foo'))
        self.assertFalse(definition.has_argument('bar'))
github sdispater / cleo / tests / inputs / test_input_definition.py View on Github external
def test_add_duplicate_option(self):
        self.initialize_options()

        definition = InputDefinition()
        definition.add_option(self.foo)
        self.assertRaisesRegexp(
            Exception,
            'An option named "foo" already exists.',
            definition.add_option,
            self.foo2
        )