コード例 #1
0
ファイル: clidoc.py プロジェクト: xtrusia/charms.reactive
    def generate(self, more_content=None, real_modname=None,
                 check_module=False, all_members=False):
        if not self.parse_name():
            # need a module to import
            self.directive.warn(
                'don\'t know which module to import for autodocumenting '
                '%r (try placing a "module" or "currentmodule" directive '
                'in the document, or giving an explicit module name)'
                % self.name)
            return

        # now, import the module and get object to document
        if not self.import_object():
            return

        if not (type(self.object).__name__ == 'function' and
                self.object.__module__ == 'charms.reactive.cli'):
            return super(CLIDoc, self).generate(more_content, real_modname, check_module, all_members)

        parser = argparse.ArgumentParser()
        parser.prog = 'charms.reactive {}'.format(self.object_name)
        for args, kwargs in describe_arguments(self.object):
            parser.add_argument(*args, **kwargs)

        usage = parser.format_usage()
        usage = re.sub('usage: (\S+) (\S+) (.*)', r'\1 **\2** `\3`', usage)
        self.add_line(usage, '<clidoc>')
        self.add_line('', '<clidoc>')
        self.indent += '    '
        self.add_content(more_content)
コード例 #2
0
 def test_keyword_splat_missing(self):
     """Double-splat arguments can't be represented in the current version
     of commandant."""
     args = cli.describe_arguments(lambda x, y=3, *z, **missing: False)
     for opts, _ in args:
         # opts should be ('varname',) at this point
         self.assertTrue(len(opts) == 1)
         self.assertNotIn('missing', opts)
コード例 #3
0
 def test_varargs(self):
     """Function has a splat-operator parameter to catch an arbitrary number
     of positional parameters."""
     argparams = tuple(cli.describe_arguments(lambda x, y=3, *z: False))
     self.assertEqual(3, len(argparams))
     for argspec in ((('x', ), {}), (('--y', ), {
             "default": 3
     }), (('z', ), {
             "nargs": "*"
     })):
         self.assertIn(argspec, argparams)
コード例 #4
0
 def test_keyword_arguments(self):
     """Function has optional parameters with default values."""
     argparams = tuple(
         cli.describe_arguments(lambda x, y=3, z="bar": False))
     self.assertEqual(3, len(argparams))
     for argspec in ((('x', ), {}), (('--y', ), {
             "default": 3
     }), (('--z', ), {
             "default": "bar"
     })):
         self.assertIn(argspec, argparams)
コード例 #5
0
 def test_positional_arguments(self):
     """Finite number of order-dependent required arguments."""
     argparams = tuple(cli.describe_arguments(lambda x, y, z: False))
     self.assertEqual(3, len(argparams))
     for argspec in ((('x', ), {}), (('y', ), {}), (('z', ), {})):
         self.assertIn(argspec, argparams)