コード例 #1
0
    def test_validator_parsing(self):
        results = Parser.parse(
            'command:name {argument (integer)} {--option (boolean) : Description with (parenthesis)}'
        )

        self.assertEqual('argument', results['arguments'][0].get_name())
        self.assertEqual('option', results['options'][0].get_name())
        self.assertIsInstance(results['arguments'][0].get_validator(), Integer)
        self.assertIsInstance(results['options'][0].get_validator(), Boolean)
コード例 #2
0
    def test_shortcut_name_parsing(self):
        results = Parser.parse('command:name {--o|option}')

        self.assertEqual('command:name', results['name'])
        self.assertEqual('option', results['options'][0].get_name())
        self.assertEqual('o', results['options'][0].get_shortcut())
        self.assertFalse(results['options'][0].accept_value())

        results = Parser.parse('command:name {--o|option=}')

        self.assertEqual('command:name', results['name'])
        self.assertEqual('option', results['options'][0].get_name())
        self.assertEqual('o', results['options'][0].get_shortcut())
        self.assertTrue(results['options'][0].accept_value())

        results = Parser.parse('command:name {--o|option=*}')

        self.assertEqual('command:name', results['name'])
        self.assertEqual('option', results['options'][0].get_name())
        self.assertEqual('o', results['options'][0].get_shortcut())
        self.assertTrue(results['options'][0].accept_value())
        self.assertTrue(results['options'][0].is_list())

        results = Parser.parse(
            'command:name {--o|option=* : The option description.}')

        self.assertEqual('command:name', results['name'])
        self.assertEqual('option', results['options'][0].get_name())
        self.assertEqual('o', results['options'][0].get_shortcut())
        self.assertEqual('The option description.',
                         results['options'][0].get_description())
        self.assertTrue(results['options'][0].accept_value())
        self.assertTrue(results['options'][0].is_list())

        results = Parser.parse('command:name '
                               '{--o|option=* : The option description.}')

        self.assertEqual('command:name', results['name'])
        self.assertEqual('option', results['options'][0].get_name())
        self.assertEqual('o', results['options'][0].get_shortcut())
        self.assertEqual('The option description.',
                         results['options'][0].get_description())
        self.assertTrue(results['options'][0].accept_value())
        self.assertTrue(results['options'][0].is_list())
コード例 #3
0
ファイル: command.py プロジェクト: sdispater/cleo
    def _configure_using_fluent_definition(self):
        """
        Configure the console command using a fluent definition.
        """
        definition = Parser.parse(self.signature)

        self._config.set_name(definition["name"])

        for name, flags, description, default in definition["arguments"]:
            self._config.add_argument(name, flags, description, default)

        for long_name, short_name, flags, description, default in definition["options"]:
            self._config.add_option(long_name, short_name, flags, description, default)
コード例 #4
0
ファイル: test_parser.py プロジェクト: meschac38700/cleo
def test_shortcut_name_parsing():
    results = Parser.parse("command:name {--o|option}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].name
    assert "o" == results["options"][0].shortcut
    assert results["options"][0].is_flag()

    results = Parser.parse("command:name {--o|option=}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].name
    assert "o" == results["options"][0].shortcut
    assert results["options"][0].requires_value()

    results = Parser.parse("command:name {--o|option=*}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].name
    assert "o" == results["options"][0].shortcut
    assert results["options"][0].is_list()

    results = Parser.parse(
        "command:name {--o|option=* : The option description.}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].name
    assert "o" == results["options"][0].shortcut
    assert "The option description." == results["options"][0].description
    assert results["options"][0].is_list()

    results = Parser.parse("command:name "
                           "{--o|option=* : The option description.}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].name
    assert "o" == results["options"][0].shortcut
    assert "The option description." == results["options"][0].description
    assert results["options"][0].is_list()
コード例 #5
0
def test_shortcut_name_parsing():
    results = Parser.parse("command:name {--o|option}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].long_name
    assert "o" == results["options"][0].short_name
    assert Option.NO_VALUE == results["options"][0].flags

    results = Parser.parse("command:name {--o|option=}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].long_name
    assert "o" == results["options"][0].short_name
    assert Option.REQUIRED_VALUE == results["options"][0].flags

    results = Parser.parse("command:name {--o|option=*}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].long_name
    assert "o" == results["options"][0].short_name
    assert Option.MULTI_VALUED == results["options"][0].flags

    results = Parser.parse(
        "command:name {--o|option=* : The option description.}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].long_name
    assert "o" == results["options"][0].short_name
    assert "The option description." == results["options"][0].description
    assert Option.MULTI_VALUED == results["options"][0].flags

    results = Parser.parse("command:name "
                           "{--o|option=* : The option description.}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].long_name
    assert "o" == results["options"][0].short_name
    assert "The option description." == results["options"][0].description
    assert Option.MULTI_VALUED == results["options"][0].flags
コード例 #6
0
ファイル: test_parser.py プロジェクト: sdispater/cleo
def test_shortcut_name_parsing():
    results = Parser.parse("command:name {--o|option}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].long_name
    assert "o" == results["options"][0].short_name
    assert Option.NO_VALUE == results["options"][0].flags

    results = Parser.parse("command:name {--o|option=}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].long_name
    assert "o" == results["options"][0].short_name
    assert Option.REQUIRED_VALUE == results["options"][0].flags

    results = Parser.parse("command:name {--o|option=*}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].long_name
    assert "o" == results["options"][0].short_name
    assert Option.MULTI_VALUED == results["options"][0].flags

    results = Parser.parse("command:name {--o|option=* : The option description.}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].long_name
    assert "o" == results["options"][0].short_name
    assert "The option description." == results["options"][0].description
    assert Option.MULTI_VALUED == results["options"][0].flags

    results = Parser.parse("command:name " "{--o|option=* : The option description.}")

    assert "command:name" == results["name"]
    assert "option" == results["options"][0].long_name
    assert "o" == results["options"][0].short_name
    assert "The option description." == results["options"][0].description
    assert Option.MULTI_VALUED == results["options"][0].flags
コード例 #7
0
    def _configure_using_fluent_definition(self):
        """
        Configure the console command using a fluent definition.
        """
        definition = Parser.parse(self.signature)

        self._config.set_name(definition["name"])

        for name, flags, description, default in definition["arguments"]:
            self._config.add_argument(name, flags, description, default)

        for long_name, short_name, flags, description, default in definition[
                "options"]:
            self._config.add_option(long_name, short_name, flags, description,
                                    default)
コード例 #8
0
    def _parse_doc(self, doc):
        doc = doc.strip().split("\n", 1)
        if len(doc) > 1:
            self.description = doc[0].strip()
            signature = re.sub(r"\s{2,}", " ", doc[1].strip())
            definition = Parser.parse(signature)
            self.name = definition["name"]

            for argument in definition["arguments"]:
                self._definition.add_argument(argument)

            for option in definition["options"]:
                self._definition.add_option(option)
        else:
            self.description = doc[0].strip()
コード例 #9
0
ファイル: test_parser.py プロジェクト: meschac38700/cleo
def test_basic_parameter_parsing():
    results = Parser.parse("command:name")

    assert "command:name" == results["name"]

    results = Parser.parse("command:name {argument} {--option}")

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert "option" == results["options"][0].name
    assert results["options"][0].is_flag()

    results = Parser.parse("command:name {argument*} {--option=}")

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert results["arguments"][0].is_required()
    assert results["arguments"][0].is_list()
    assert "option" == results["options"][0].name
    assert results["options"][0].requires_value()

    results = Parser.parse("command:name {argument?*} {--option=*}")

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert not results["arguments"][0].is_required()
    assert results["arguments"][0].is_list()
    assert "option" == results["options"][0].name
    assert results["options"][0].is_list()

    results = Parser.parse(
        "command:name {argument?* : The argument description.}    {--option=* : The option description.}"
    )

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert "The argument description." == results["arguments"][0].description
    assert not results["arguments"][0].is_required()
    assert results["arguments"][0].is_list()
    assert "option" == results["options"][0].name
    assert "The option description." == results["options"][0].description
    assert results["options"][0].is_list()

    results = Parser.parse("command:name "
                           "{argument?* : The argument description.}    "
                           "{--option=* : The option description.}")

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert "The argument description." == results["arguments"][0].description
    assert not results["arguments"][0].is_required()
    assert results["arguments"][0].is_list()
    assert "option" == results["options"][0].name
    assert "The option description." == results["options"][0].description
    assert results["options"][0].is_list()
コード例 #10
0
def test_basic_parameter_parsing():
    results = Parser.parse("command:name")

    assert "command:name" == results["name"]

    results = Parser.parse("command:name {argument} {--option}")

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert "option" == results["options"][0].long_name
    assert Option.NO_VALUE == results["options"][0].flags

    results = Parser.parse("command:name {argument*} {--option=}")

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert Argument.MULTI_VALUED | Argument.REQUIRED == results["arguments"][
        0].flags
    assert "option" == results["options"][0].long_name
    assert Option.REQUIRED_VALUE == results["options"][0].flags

    results = Parser.parse("command:name {argument?*} {--option=*}")

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert Argument.MULTI_VALUED | Argument.OPTIONAL == results["arguments"][
        0].flags
    assert "option" == results["options"][0].long_name
    assert Option.MULTI_VALUED == results["options"][0].flags

    results = Parser.parse(
        "command:name {argument?* : The argument description.}    {--option=* : The option description.}"
    )

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert "The argument description." == results["arguments"][0].description
    assert Argument.MULTI_VALUED | Argument.OPTIONAL == results["arguments"][
        0].flags
    assert "option" == results["options"][0].long_name
    assert "The option description." == results["options"][0].description
    assert Option.MULTI_VALUED == results["options"][0].flags

    results = Parser.parse("command:name "
                           "{argument?* : The argument description.}    "
                           "{--option=* : The option description.}")

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert "The argument description." == results["arguments"][0].description
    assert Argument.MULTI_VALUED | Argument.OPTIONAL == results["arguments"][
        0].flags
    assert "option" == results["options"][0].long_name
    assert "The option description." == results["options"][0].description
    assert Option.MULTI_VALUED == results["options"][0].flags
コード例 #11
0
ファイル: test_parser.py プロジェクト: sdispater/cleo
def test_basic_parameter_parsing():
    results = Parser.parse("command:name")

    assert "command:name" == results["name"]

    results = Parser.parse("command:name {argument} {--option}")

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert "option" == results["options"][0].long_name
    assert Option.NO_VALUE == results["options"][0].flags

    results = Parser.parse("command:name {argument*} {--option=}")

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert Argument.MULTI_VALUED | Argument.REQUIRED == results["arguments"][0].flags
    assert "option" == results["options"][0].long_name
    assert Option.REQUIRED_VALUE == results["options"][0].flags

    results = Parser.parse("command:name {argument?*} {--option=*}")

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert Argument.MULTI_VALUED | Argument.OPTIONAL == results["arguments"][0].flags
    assert "option" == results["options"][0].long_name
    assert Option.MULTI_VALUED == results["options"][0].flags

    results = Parser.parse(
        "command:name {argument?* : The argument description.}    {--option=* : The option description.}"
    )

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert "The argument description." == results["arguments"][0].description
    assert Argument.MULTI_VALUED | Argument.OPTIONAL == results["arguments"][0].flags
    assert "option" == results["options"][0].long_name
    assert "The option description." == results["options"][0].description
    assert Option.MULTI_VALUED == results["options"][0].flags

    results = Parser.parse(
        "command:name "
        "{argument?* : The argument description.}    "
        "{--option=* : The option description.}"
    )

    assert "command:name" == results["name"]
    assert "argument" == results["arguments"][0].name
    assert "The argument description." == results["arguments"][0].description
    assert Argument.MULTI_VALUED | Argument.OPTIONAL == results["arguments"][0].flags
    assert "option" == results["options"][0].long_name
    assert "The option description." == results["options"][0].description
    assert Option.MULTI_VALUED == results["options"][0].flags
コード例 #12
0
    def test_basic_parameter_parsing(self):
        results = Parser.parse('command:name')

        self.assertEqual('command:name', results['name'])

        results = Parser.parse('command:name {argument} {--option}')

        self.assertEqual('command:name', results['name'])
        self.assertEqual('argument', results['arguments'][0].get_name())
        self.assertEqual('option', results['options'][0].get_name())
        self.assertFalse(results['options'][0].accept_value())

        results = Parser.parse('command:name {argument*} {--option=}')

        self.assertEqual('command:name', results['name'])
        self.assertEqual('argument', results['arguments'][0].get_name())
        self.assertTrue(results['arguments'][0].is_list())
        self.assertTrue(results['arguments'][0].is_required())
        self.assertEqual('option', results['options'][0].get_name())
        self.assertTrue(results['options'][0].accept_value())

        results = Parser.parse('command:name {argument?*} {--option=*}')

        self.assertEqual('command:name', results['name'])
        self.assertEqual('argument', results['arguments'][0].get_name())
        self.assertTrue(results['arguments'][0].is_list())
        self.assertFalse(results['arguments'][0].is_required())
        self.assertEqual('option', results['options'][0].get_name())
        self.assertTrue(results['options'][0].accept_value())
        self.assertTrue(results['options'][0].is_list())

        results = Parser.parse(
            'command:name {argument?* : The argument description.}    {--option=* : The option description.}'
        )

        self.assertEqual('command:name', results['name'])
        self.assertEqual('argument', results['arguments'][0].get_name())
        self.assertEqual('The argument description.',
                         results['arguments'][0].get_description())
        self.assertTrue(results['arguments'][0].is_list())
        self.assertFalse(results['arguments'][0].is_required())
        self.assertEqual('option', results['options'][0].get_name())
        self.assertEqual('The option description.',
                         results['options'][0].get_description())
        self.assertTrue(results['options'][0].accept_value())
        self.assertTrue(results['options'][0].is_list())

        results = Parser.parse('command:name '
                               '{argument?* : The argument description.}    '
                               '{--option=* : The option description.}')

        self.assertEqual('command:name', results['name'])
        self.assertEqual('argument', results['arguments'][0].get_name())
        self.assertEqual('The argument description.',
                         results['arguments'][0].get_description())
        self.assertTrue(results['arguments'][0].is_list())
        self.assertFalse(results['arguments'][0].is_required())
        self.assertEqual('option', results['options'][0].get_name())
        self.assertEqual('The option description.',
                         results['options'][0].get_description())
        self.assertTrue(results['options'][0].accept_value())
        self.assertTrue(results['options'][0].is_list())