How to use the cleo.inputs.InputArgument 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 / fixtures / no_configure_command.py View on Github external
# -*- coding: utf-8 -*-

from cleo.commands.command import Command
from cleo.inputs import InputArgument, InputOption


class NoConfigureCommand(Command):

    name = 'no:configure'

    description = 'description'

    help = 'help'

    arguments = [
        InputArgument('foo'),
        InputArgument('bar')
    ]

    options = [
        InputOption('baz', 'z'),
        InputOption('bazz', 'Z')
    ]

    def execute(self, input_, output_):
        output_.writeln('execute called')

    def interact(self, input_, output_):
        output_.writeln('interact called')
github sdispater / cleo / tests / inputs / test_input_definition.py View on Github external
def test_list_argument_has_to_be_last(self):
        self.initialize_arguments()

        definition = InputDefinition()
        definition.add_argument(InputArgument('foolist', InputArgument.IS_LIST))
        self.assertRaisesRegexp(
            Exception,
            'Cannot add an argument after a list argument.',
            definition.add_argument,
            InputArgument('anotherbar')
        )
github sdispater / cleo / tests / inputs / test_argv_input.py View on Github external
def test_parse_list_argument(self):
        input_ = ArgvInput(['cli.py', 'foo', 'bar', 'baz', 'bat'])
        input_.bind(
            InputDefinition([
                InputArgument('name', InputArgument.IS_LIST)
            ])
        )

        self.assertEqual(
            {'name': ['foo', 'bar', 'baz', 'bat']},
            input_.get_arguments()
        )
github sdispater / cleo / tests / inputs / test_input_definition.py View on Github external
def test_get_argument_default(self):
        definition = InputDefinition([
            InputArgument('foo1', InputArgument.OPTIONAL),
            InputArgument('foo2', InputArgument.OPTIONAL, '', 'default'),
            InputArgument('foo3', InputArgument.OPTIONAL | InputArgument.IS_LIST),
        ])
        self.assertEqual(
            {
                'foo1': None,
                'foo2': 'default',
                'foo3': []
            },
            definition.get_argument_defaults()
        )

        definition = InputDefinition([
            InputArgument('foo4', InputArgument.OPTIONAL | InputArgument.IS_LIST, '', [1, 2])
        ])
        self.assertEqual({'foo4': [1, 2]}, definition.get_argument_defaults())
github sdispater / cleo / tests / inputs / test_argv_input.py View on Github external
def test_parse_arguments(self):
        input_ = ArgvInput(['cli.py', 'foo'])
        input_.bind(
            InputDefinition([
                InputArgument('name')
            ])
        )

        self.assertEqual({'name': 'foo'}, input_.get_arguments())

        # parse is stateless
        self.assertEqual({'name': 'foo'}, input_.get_arguments())
github sdispater / cleo / tests / inputs / test_input_definition.py View on Github external
def initialize_arguments(self):
        self.foo = InputArgument('foo')
        self.bar = InputArgument('bar')
        self.foo1 = InputArgument('foo')
        self.foo2 = InputArgument('foo2', InputArgument.REQUIRED)
github sdispater / cleo / tests / inputs / test_input_definition.py View on Github external
def initialize_arguments(self):
        self.foo = InputArgument('foo')
        self.bar = InputArgument('bar')
        self.foo1 = InputArgument('foo')
        self.foo2 = InputArgument('foo2', InputArgument.REQUIRED)
github sdispater / cleo / tests / inputs / test_input.py View on Github external
def test_validate_arguments(self):
        definition = InputDefinition([
            InputArgument('arg', validator=Integer())
        ])

        input = MockInput(definition)

        input.validate_arguments()
        self.assertIsInstance(input.get_argument('arg'), int)

        # Wrong type
        input = MockWrongInput(definition)

        self.assertRaises(
            InvalidArgument,
            input.validate_arguments
        )
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_list_input.py View on Github external
def provider_invalid_input(self):
        return [
            (
                [('foo', 'bar')],
                InputDefinition([
                    InputArgument('name')
                ]),
                'The "foo" argument does not exist.'
            ),
            (
                ['--foo'],
                InputDefinition([
                    InputOption('foo', 'f', InputOption.VALUE_REQUIRED)
                ]),
                'The "--foo" option requires a value.'
            ),
            (
                [('--foo', 'foo')],
                InputDefinition(),
                'The "--foo" option does not exist.'
            ),
            (