Example #1
0
 def test_gen_list_structure_of_scalars_docs(self):
     p = self.get_param_object('elb.CreateLoadBalancer.Listeners')
     op_doc = OperationDocument(self.session, p.operation)
     self.simplify.add_docs(op_doc, p)
     fp = six.StringIO()
     op_doc.render(fp=fp)
     rendered = fp.getvalue()
     self.assertIn('Shorthand Syntax', rendered)
     self.assertIn('--listeners', rendered)
     self.assertIn('protocol=string', rendered)
Example #2
0
 def test_gen_list_structure_of_scalars_docs(self):
     p = self.get_param_object('elb.CreateLoadBalancer.Listeners')
     op_doc = OperationDocument(self.session, p.operation)
     self.simplify.add_docs(op_doc, p)
     fp = six.StringIO()
     op_doc.render(fp=fp)
     rendered = fp.getvalue()
     self.assertIn('Shorthand Syntax', rendered)
     self.assertIn('--listeners', rendered)
     self.assertIn('protocol=string', rendered)
Example #3
0
 def test_gen_list_scalar_docs(self):
     p = self.get_param_object(
         'elb.RegisterInstancesWithLoadBalancer.Instances')
     op_doc = OperationDocument(self.session, p.operation)
     self.simplify.add_docs(op_doc, p)
     fp = six.StringIO()
     op_doc.render(fp=fp)
     rendered = fp.getvalue()
     # Key parts include:
     # Title that says it's the shorthand syntax.
     self.assertIn('Shorthand Syntax', rendered)
     # sample syntax
     self.assertIn('--instances instance_id1', rendered)
Example #4
0
 def test_gen_list_scalar_docs(self):
     p = self.get_param_object(
         'elb.RegisterInstancesWithLoadBalancer.Instances')
     op_doc = OperationDocument(self.session, p.operation)
     self.simplify.add_docs(op_doc, p)
     fp = six.StringIO()
     op_doc.render(fp=fp)
     rendered = fp.getvalue()
     # Key parts include:
     # Title that says it's the shorthand syntax.
     self.assertIn('Shorthand Syntax', rendered)
     # sample syntax
     self.assertIn('--instances instance_id1', rendered)
Example #5
0
 def test_gen_map_type_docs(self):
     p = self.get_param_object('sqs.SetQueueAttributes.Attributes')
     op_doc = OperationDocument(self.session, p.operation)
     self.simplify.add_docs(op_doc, p)
     fp = six.StringIO()
     op_doc.render(fp=fp)
     rendered = fp.getvalue()
     # Key parts include:
     # Title that says it's the shorthand syntax.
     self.assertIn('Shorthand Syntax', rendered)
     # sample syntax
     self.assertIn('key_name=string', rendered)
     # valid key names
     self.assertIn('VisibilityTimeout', rendered)
Example #6
0
 def test_gen_map_type_docs(self):
     p = self.get_param_object('sqs.SetQueueAttributes.Attributes')
     op_doc = OperationDocument(self.session, p.operation)
     self.simplify.add_docs(op_doc, p)
     fp = six.StringIO()
     op_doc.render(fp=fp)
     rendered = fp.getvalue()
     # Key parts include:
     # Title that says it's the shorthand syntax.
     self.assertIn('Shorthand Syntax', rendered)
     # sample syntax
     self.assertIn('key_name=string', rendered)
     # valid key names
     self.assertIn('VisibilityTimeout', rendered)
Example #7
0
    def __call__(self, param, value, **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 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.

        """
        parse_method = self._get_parse_method_for_param(param, value)
        if parse_method is None:
            return
        else:
            try:
                LOG.debug("Using %s for param %s", parse_method, param)
                parsed = getattr(self, parse_method)(param, value)
            except ParamSyntaxError as e:
                # Give them a helpful error message.
                doc_method = getattr(self, '_docs' + parse_method, None)
                if doc_method is None:
                    raise e
                else:
                    help_text = six.StringIO()
                    doc = OperationDocument(param.operation.session,
                                            param.operation)
                    doc_method(doc, param)
                    doc.render(fp=help_text)
                    raise ParamError(param, help_text.getvalue())
            return parsed
Example #8
0
    def __call__(self, param, value, **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 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.

        """
        parse_method = self._get_parse_method_for_param(param, value)
        if parse_method is None:
            return
        else:
            try:
                LOG.debug("Using %s for param %s", parse_method, param)
                parsed = getattr(self, parse_method)(param, value)
            except ParamSyntaxError as e:
                # Give them a helpful error message.
                doc_method = getattr(self, '_docs' + parse_method, None)
                if doc_method is None:
                    raise e
                else:
                    help_text = six.StringIO()
                    doc = OperationDocument(param.operation.session,
                                            param.operation)
                    doc_method(doc, param)
                    doc.render(fp=help_text)
                    raise ParamError(param, help_text.getvalue())
            return parsed