Exemplo n.º 1
0
    def test_returns_none_if_event_is_too_short(self):
        event_name = "foo.bar"
        service, operation = find_service_and_method_in_event_name(event_name)
        self.assertEqual(service, "bar")
        self.assertIs(operation, None)

        event_name = "foo"
        service, operation = find_service_and_method_in_event_name(event_name)
        self.assertIs(service, None)
        self.assertIs(operation, None)
Exemplo n.º 2
0
    def test_returns_none_if_event_is_too_short(self):
        event_name = "foo.bar"
        service, operation = find_service_and_method_in_event_name(event_name)
        self.assertEqual(service, "bar")
        self.assertIs(operation, None)

        event_name = "foo"
        service, operation = find_service_and_method_in_event_name(event_name)
        self.assertIs(service, None)
        self.assertIs(operation, None)
Exemplo n.º 3
0
    def __call__(self, cli_argument, value, event_name, **kwargs):
        """Attempt to parse shorthand syntax for values.

        This is intended to be hooked up as an event handler (hence the
        **kwargs).  Given ``param`` object and its string ``value``,
        figure out if we can parse it.  If we can parse it, we return
        the parsed value (typically some sort of python dict).

        :type cli_argument: :class:`awscli.arguments.BaseCLIArgument`
        :param cli_argument: The CLI argument object.

        :type param: :class:`botocore.parameters.Parameter`
        :param param: The parameter object (includes various metadata
            about the parameter).

        :type value: str
        :param value: The value for the parameter type on the command
            line, e.g ``--foo this_value``, value would be ``"this_value"``.

        :returns: If we can parse the value we return the parsed value.
            If it looks like JSON, we return None (which tells the event
            emitter to use the default ``unpack_cli_arg`` provided that
            no other event handlers can parsed the value).  If we
            run into an error parsing the value, a ``ParamError`` will
            be raised.

        """

        if not self._should_parse_as_shorthand(cli_argument, value):
            return
        else:
            command_name, operation_name = \
                find_service_and_method_in_event_name(event_name)
            return self._parse_as_shorthand(cli_argument, value, command_name,
                                            operation_name)
Exemplo n.º 4
0
    def __call__(self, cli_argument, value, event_name, **kwargs):
        """Attempt to parse shorthand syntax for values.

        This is intended to be hooked up as an event handler (hence the
        **kwargs).  Given ``param`` object and its string ``value``,
        figure out if we can parse it.  If we can parse it, we return
        the parsed value (typically some sort of python dict).

        :type cli_argument: :class:`awscli.arguments.BaseCLIArgument`
        :param cli_argument: The CLI argument object.

        :type param: :class:`botocore.parameters.Parameter`
        :param param: The parameter object (includes various metadata
            about the parameter).

        :type value: str
        :param value: The value for the parameter type on the command
            line, e.g ``--foo this_value``, value would be ``"this_value"``.

        :returns: If we can parse the value we return the parsed value.
            If it looks like JSON, we return None (which tells the event
            emitter to use the default ``unpack_cli_arg`` provided that
            no other event handlers can parsed the value).  If we
            run into an error parsing the value, a ``ParamError`` will
            be raised.

        """

        if not self._should_parse_as_shorthand(cli_argument, value):
            return
        else:
            service_id, operation_name = \
                find_service_and_method_in_event_name(event_name)
            return self._parse_as_shorthand(
                cli_argument, value, service_id, operation_name)
 def doc_option_example(self, arg_name, help_command, event_name, **kwargs):
     service_id, operation_name = \
         find_service_and_method_in_event_name(event_name)
     doc = help_command.doc
     cli_argument = help_command.arg_table[arg_name]
     if cli_argument.group_name in self._arg_groups:
         if cli_argument.group_name in self._documented_arg_groups:
             # Args with group_names (boolean args) don't
             # need to generate example syntax.
             return
     argument_model = cli_argument.argument_model
     docgen = ParamShorthandDocGen()
     if docgen.supports_shorthand(cli_argument.argument_model):
         example_shorthand_syntax = docgen.generate_shorthand_example(
             cli_argument, service_id, operation_name)
         if example_shorthand_syntax is None:
             # If the shorthand syntax returns a value of None,
             # this indicates to us that there is no example
             # needed for this param so we can immediately
             # return.
             return
         if example_shorthand_syntax:
             doc.style.new_paragraph()
             doc.write('Shorthand Syntax')
             doc.style.start_codeblock()
             for example_line in example_shorthand_syntax.splitlines():
                 doc.writeln(example_line)
             doc.style.end_codeblock()
     if argument_model is not None and argument_model.type_name == 'list' and \
             argument_model.member.type_name in SCALAR_TYPES:
         # A list of scalars is special.  While you *can* use
         # JSON ( ["foo", "bar", "baz"] ), you can also just
         # use the argparse behavior of space separated lists.
         # "foo" "bar" "baz".  In fact we don't even want to
         # document the JSON syntax in this case.
         member = argument_model.member
         doc.style.new_paragraph()
         doc.write('Syntax')
         doc.style.start_codeblock()
         example_type = self._json_example_value_name(
             member, include_enum_values=False)
         doc.write('%s %s ...' % (example_type, example_type))
         if isinstance(member, StringShape) and member.enum:
             # If we have enum values, we can tell the user
             # exactly what valid values they can provide.
             self._write_valid_enums(doc, member.enum)
         doc.style.end_codeblock()
         doc.style.new_paragraph()
     elif cli_argument.cli_type_name not in SCALAR_TYPES:
         doc.style.new_paragraph()
         doc.write('JSON Syntax')
         doc.style.start_codeblock()
         self._json_example(doc, argument_model, stack=[])
         doc.style.end_codeblock()
         doc.style.new_paragraph()
Exemplo n.º 6
0
 def doc_option_example(self, arg_name, help_command, event_name, **kwargs):
     service_name, operation_name = \
         find_service_and_method_in_event_name(event_name)
     doc = help_command.doc
     cli_argument = help_command.arg_table[arg_name]
     if cli_argument.group_name in self._arg_groups:
         if cli_argument.group_name in self._documented_arg_groups:
             # Args with group_names (boolean args) don't
             # need to generate example syntax.
             return
     argument_model = cli_argument.argument_model
     docgen = ParamShorthandDocGen()
     if docgen.supports_shorthand(cli_argument.argument_model):
         example_shorthand_syntax = docgen.generate_shorthand_example(
             cli_argument, service_name, operation_name)
         if example_shorthand_syntax is None:
             # If the shorthand syntax returns a value of None,
             # this indicates to us that there is no example
             # needed for this param so we can immediately
             # return.
             return
         if example_shorthand_syntax:
             doc.style.new_paragraph()
             doc.write('Shorthand Syntax')
             doc.style.start_codeblock()
             for example_line in example_shorthand_syntax.splitlines():
                 doc.writeln(example_line)
             doc.style.end_codeblock()
     if argument_model is not None and argument_model.type_name == 'list' and \
             argument_model.member.type_name in SCALAR_TYPES:
         # A list of scalars is special.  While you *can* use
         # JSON ( ["foo", "bar", "baz"] ), you can also just
         # use the argparse behavior of space separated lists.
         # "foo" "bar" "baz".  In fact we don't even want to
         # document the JSON syntax in this case.
         member = argument_model.member
         doc.style.new_paragraph()
         doc.write('Syntax')
         doc.style.start_codeblock()
         example_type = self._json_example_value_name(
             member, include_enum_values=False)
         doc.write('%s %s ...' % (example_type, example_type))
         if isinstance(member, StringShape) and member.enum:
             # If we have enum values, we can tell the user
             # exactly what valid values they can provide.
             self._write_valid_enums(doc, member.enum)
         doc.style.end_codeblock()
         doc.style.new_paragraph()
     elif cli_argument.cli_type_name not in SCALAR_TYPES:
         doc.style.new_paragraph()
         doc.write('JSON Syntax')
         doc.style.start_codeblock()
         self._json_example(doc, argument_model, stack=[])
         doc.style.end_codeblock()
         doc.style.new_paragraph()
Exemplo n.º 7
0
 def test_finds_service_and_operation_name(self):
     event_name = "foo.bar.baz"
     service, operation = find_service_and_method_in_event_name(event_name)
     self.assertEqual(service, "bar")
     self.assertEqual(operation, "baz")
Exemplo n.º 8
0
 def test_finds_service_and_operation_name(self):
     event_name = "foo.bar.baz"
     service, operation = find_service_and_method_in_event_name(event_name)
     self.assertEqual(service, "bar")
     self.assertEqual(operation, "baz")