How to use the cleo.inputs.input_option.InputOption 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_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 / inputs / test_input_option.py View on Github external
def test_get_default(self):
        """
        InputOption.get_default() returns the default value
        """
        option = InputOption('foo', 'f', InputOption.VALUE_OPTIONAL, '', 'default')
        self.assertEqual('default', option.get_default(),
                         msg='.get_default() returns the default value')
        option = InputOption('foo', 'f', InputOption.VALUE_REQUIRED, '', 'default')
        self.assertEqual('default', option.get_default(),
                         msg='.get_default() returns the default value')
        option = InputOption('foo', 'f', InputOption.VALUE_REQUIRED)
        self.assertEqual(None, option.get_default(),
                         msg='.get_default() returns None if no default value is configured')
        option = InputOption('foo', 'f', InputOption.VALUE_NONE)
        self.assertEqual(False, option.get_default(),
                         msg='.get_default() returns False if the option does not take a value')
github sdispater / cleo / tests / inputs / test_input_option.py View on Github external
def test_get_default(self):
        """
        InputOption.get_default() returns the default value
        """
        option = InputOption('foo', 'f', InputOption.VALUE_OPTIONAL, '', 'default')
        self.assertEqual('default', option.get_default(),
                         msg='.get_default() returns the default value')
        option = InputOption('foo', 'f', InputOption.VALUE_REQUIRED, '', 'default')
        self.assertEqual('default', option.get_default(),
                         msg='.get_default() returns the default value')
        option = InputOption('foo', 'f', InputOption.VALUE_REQUIRED)
        self.assertEqual(None, option.get_default(),
                         msg='.get_default() returns None if no default value is configured')
        option = InputOption('foo', 'f', InputOption.VALUE_NONE)
        self.assertEqual(False, option.get_default(),
                         msg='.get_default() returns False if the option does not take a value')
github sdispater / cleo / tests / inputs / test_input_option.py View on Github external
"""
        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')
        self.assertFalse(option.is_value_optional(),
                         msg='__init__() gives a "InputOption.VALUE_NONE" mode by default')

        option = InputOption('foo', 'f', None)
        self.assertFalse(option.accept_value(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')
        self.assertFalse(option.is_value_required(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')
        self.assertFalse(option.is_value_optional(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')

        option = InputOption('foo', 'f', InputOption.VALUE_NONE)
github sdispater / cleo / tests / inputs / test_input_option.py View on Github external
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')
        self.assertFalse(option.is_value_optional(),
                         msg='__init__() gives a "InputOption.VALUE_NONE" mode by default')

        option = InputOption('foo', 'f', None)
        self.assertFalse(option.accept_value(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')
        self.assertFalse(option.is_value_required(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')
        self.assertFalse(option.is_value_optional(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')

        option = InputOption('foo', 'f', InputOption.VALUE_NONE)
        self.assertFalse(option.accept_value(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')
        self.assertFalse(option.is_value_required(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')
        self.assertFalse(option.is_value_optional(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')

        option = InputOption('foo', 'f', InputOption.VALUE_REQUIRED)
github sdispater / cleo / tests / inputs / test_input_option.py View on Github external
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')
        self.assertFalse(option.is_value_optional(),
                         msg='__init__() gives a "InputOption.VALUE_NONE" mode by default')

        option = InputOption('foo', 'f', None)
        self.assertFalse(option.accept_value(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')
        self.assertFalse(option.is_value_required(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')
        self.assertFalse(option.is_value_optional(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')

        option = InputOption('foo', 'f', InputOption.VALUE_NONE)
        self.assertFalse(option.accept_value(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')
        self.assertFalse(option.is_value_required(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')
        self.assertFalse(option.is_value_optional(),
                         msg='__init__() can take "InputOption.VALUE_NONE" as its mode')

        option = InputOption('foo', 'f', InputOption.VALUE_REQUIRED)
        self.assertTrue(option.accept_value(),
                        msg='__init__() can take "InputOption.VALUE_REQUIRED" as its mode')
        self.assertTrue(option.is_value_required(),
                        msg='__init__() can take "InputOption.VALUE_REQUIRED" as its mode')
        self.assertFalse(option.is_value_optional(),
                         msg='__init__() can take "InputOption.VALUE_REQUIRED" as its mode')

        option = InputOption('foo', 'f', InputOption.VALUE_OPTIONAL)
github sdispater / cleo / cleo / inputs / api.py View on Github external
:param validator: An optional validator.
    :type validator: Validator or str

    :rtype: InputOption
    """
    mode = InputOption.VALUE_IS_FLAG

    if value_required is True:
        mode = InputOption.VALUE_REQUIRED
    elif value_required is False:
        mode = InputOption.VALUE_OPTIONAL

    if is_list:
        mode |= InputOption.VALUE_IS_LIST

    return InputOption(name, shortcut, mode, description, default, validator)
github sdispater / cleo / cleo / inputs / api.py View on Github external
:type is_list: bool

    :param default: The default value.
    :type default: mixed

    :param validator: An optional validator.
    :type validator: Validator or str

    :rtype: InputOption
    """
    mode = InputOption.VALUE_IS_FLAG

    if value_required is True:
        mode = InputOption.VALUE_REQUIRED
    elif value_required is False:
        mode = InputOption.VALUE_OPTIONAL

    if is_list:
        mode |= InputOption.VALUE_IS_LIST

    return InputOption(name, shortcut, mode, description, default, validator)