本文整理汇总了Python中sphinxarg.parser.parse_parser函数的典型用法代码示例。如果您正苦于以下问题:Python parse_parser函数的具体用法?Python parse_parser怎么用?Python parse_parser使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_parser函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_parse_default
def test_parse_default():
parser = argparse.ArgumentParser()
parser.add_argument("--foo", default="123")
data = parse_parser(parser)
assert data["action_groups"][0]["options"] == [{"name": ["--foo"], "default": "123", "help": ""}]
开发者ID:fidelram,项目名称:sphinx-argparse,代码行数:7,代码来源:test_parser.py
示例2: test_parse_nested
def test_parse_nested():
parser = argparse.ArgumentParser()
parser.add_argument("foo", default=False, help="foo help")
parser.add_argument("bar", default=False)
subparsers = parser.add_subparsers()
subparser = subparsers.add_parser("install", help="install help", usage="program install [args]")
subparser.add_argument("ref", type=str, help="foo1 help")
subparser.add_argument("--upgrade", action="store_true", default=False, help="foo2 help")
data = parse_parser(parser)
assert data["args"] == [
{"name": "foo", "help": "foo help", "metavar": None},
{"name": "bar", "help": "", "metavar": None},
]
assert data["children"] == [
{
"name": "install",
"help": "install help",
"usage": "usage: program install [args]",
"bare_usage": "program install [args]",
"args": [{"name": "ref", "help": "foo1 help", "metavar": None}],
"action_groups": [
{
"description": None,
"title": "optional arguments",
"options": [{"default": False, "help": "foo2 help", "name": ["--upgrade"]}],
}
],
}
]
开发者ID:fidelram,项目名称:sphinx-argparse,代码行数:34,代码来源:test_parser.py
示例3: test_parse_arg_choices
def test_parse_arg_choices():
parser = argparse.ArgumentParser()
parser.add_argument("move", choices=["rock", "paper", "scissors"])
data = parse_parser(parser)
assert data["args"] == [{"name": "move", "help": "", "choices": ["rock", "paper", "scissors"], "metavar": None}]
开发者ID:fidelram,项目名称:sphinx-argparse,代码行数:7,代码来源:test_parser.py
示例4: test_action_groups_with_subcommands
def test_action_groups_with_subcommands():
"""
This is a somewhat overly complicated example incorporating both action
groups (with optional AND positional arguments) and subcommands (again
with both optional and positional arguments)
"""
parser = argparse.ArgumentParser('foo')
subparsers = parser.add_subparsers()
parserA = subparsers.add_parser('A', help='A subparser')
parserA.add_argument('baz', type=int, help='An integer')
parserB = subparsers.add_parser('B', help='B subparser')
parserB.add_argument('--barg', choices='XYZ', help='A list of choices')
parser.add_argument('--foo', help='foo help')
parser.add_argument('foo2', metavar='foo2 metavar', help='foo2 help')
grp1 = parser.add_argument_group('bar options')
grp1.add_argument('--bar', help='bar help')
grp1.add_argument('quux', help='quux help')
grp2 = parser.add_argument_group('bla options')
grp2.add_argument('--blah', help='blah help')
grp2.add_argument('sniggly', help='sniggly help')
data = parse_parser(parser)
assert data['action_groups'] == [
{'options': [{'default': None, 'name': ['foo2 metavar'], 'help': 'foo2 help'}], 'description': None, 'title': 'Positional Arguments'},
{'options': [{'default': None, 'name': ['--foo'], 'help': 'foo help'}], 'description': None, 'title': 'Named Arguments'},
{'options': [{'default': None, 'name': ['--bar'], 'help': 'bar help'}, {'default': None, 'name': ['quux'], 'help': 'quux help'}], 'description': None, 'title': 'bar options'},
{'options': [{'default': None, 'name': ['--blah'], 'help': 'blah help'}, {'default': None, 'name': ['sniggly'], 'help': 'sniggly help'}], 'description': None, 'title': 'bla options'}
]
assert data['children'] == [
{'usage': 'usage: foo A [-h] baz', 'action_groups': [{'options': [{'default': None, 'name': ['baz'], 'help': 'An integer'}], 'description': None, 'title': 'Positional Arguments'}], 'bare_usage': 'foo A [-h] baz', 'name': 'A', 'help': 'A subparser'},
{'usage': 'usage: foo B [-h] [--barg {X,Y,Z}]', 'action_groups': [{'options': [{'default': None, 'choices': 'XYZ', 'name': ['--barg'], 'help': 'A list of choices'}], 'description': None, 'title': 'Named Arguments'}], 'bare_usage': 'foo B [-h] [--barg {X,Y,Z}]', 'name': 'B', 'help': 'B subparser'}
]
开发者ID:ribozz,项目名称:sphinx-argparse,代码行数:35,代码来源:test_parser.py
示例5: test_parse_default_skip_default
def test_parse_default_skip_default():
parser = argparse.ArgumentParser()
parser.add_argument("--foo", default="123")
data = parse_parser(parser, skip_default_values=True)
assert data["action_groups"][0]["options"] == [{"name": ["--foo"], "default": "==SUPPRESS==", "help": ""}]
开发者ID:fidelram,项目名称:sphinx-argparse,代码行数:7,代码来源:test_parser.py
示例6: test_parse_groups
def test_parse_groups():
parser = argparse.ArgumentParser()
parser.add_argument("--foo", action="store_true", default=False, help="foo help")
parser.add_argument("--bar", action="store_true", default=False)
optional = parser.add_argument_group("Group 1")
optional.add_argument("--option1", help="option #1")
optional.add_argument("--option2", help="option #2")
data = parse_parser(parser)
assert data["action_groups"] == [
{
"description": None,
"options": [
{"default": False, "help": "foo help", "name": ["--foo"]},
{"default": False, "help": "", "name": ["--bar"]},
],
"title": "optional arguments",
},
{
"description": None,
"options": [
{"default": None, "help": "option #1", "name": ["--option1"]},
{"default": None, "help": "option #2", "name": ["--option2"]},
],
"title": "Group 1",
},
]
开发者ID:fidelram,项目名称:sphinx-argparse,代码行数:27,代码来源:test_parser.py
示例7: run
def run(self):
if 'module' in self.options and 'func' in self.options:
module_name = self.options['module']
attr_name = self.options['func']
elif 'ref' in self.options:
_parts = self.options['ref'].split('.')
module_name = '.'.join(_parts[0:-1])
attr_name = _parts[-1]
else:
raise self.error(':module: and :func: should be specified, or :ref:')
mod = __import__(module_name, globals(), locals(), [attr_name])
if not hasattr(mod, attr_name):
raise self.error('Module "%s" has no attribute "%s"\nIncorrect argparse :module: or :func: values?' % (module_name, attr_name))
func = getattr(mod, attr_name)
if isinstance(func, ArgumentParser):
parser = func
else:
parser = func()
if not 'path' in self.options:
self.options['path'] = ''
path = str(self.options['path'])
parser.prog = self.options['prog']
result = parse_parser(parser,
skip_default_values='nodefault' in self.options)
result = parser_navigate(result, path)
nested_content = nodes.paragraph()
self.state.nested_parse(self.content, self.content_offset, nested_content)
nested_content = nested_content.children
items = []
# add common content between
for item in nested_content:
if not isinstance(item, nodes.definition_list):
items.append(item)
if 'description' in result:
items.append(nodes.paragraph(text=result['description']))
items.append(nodes.literal_block(text=result['usage']))
items.append(print_command_args_and_opts(
print_arg_list(result, nested_content),
print_opt_list(result, nested_content),
print_subcommand_list(result, nested_content)
))
if 'epilog' in result:
items.append(nodes.paragraph(text=result['epilog']))
return items
开发者ID:jamesra,项目名称:sphinx-argparse,代码行数:59,代码来源:ext.py
示例8: test_parse_nested_traversal
def test_parse_nested_traversal():
parser = argparse.ArgumentParser()
subparsers1 = parser.add_subparsers()
subparser1 = subparsers1.add_parser('level1')
subparsers2 = subparser1.add_subparsers()
subparser2 = subparsers2.add_parser('level2')
subparsers3 = subparser2.add_subparsers()
subparser3 = subparsers3.add_parser('level3')
subparser3.add_argument('foo', help='foo help')
subparser3.add_argument('bar')
data = parse_parser(parser)
data3 = parser_navigate(data, 'level1 level2 level3')
assert data3['action_groups'][0]['options'] == [
{
'name': ['foo'],
'help': 'foo help',
'default': None
}, {
'name': ['bar'],
'help': '',
'default': None
}
]
data2 = parser_navigate(data, 'level1 level2')
assert data2['children'] == [
{
'name': 'level3',
'help': '',
'usage': 'usage: py.test level1 level2 level3 [-h] foo bar',
'bare_usage': 'py.test level1 level2 level3 [-h] foo bar',
'action_groups': [
{
'title': 'Positional Arguments',
'description': None,
'options': [
{
'default': None,
'name': ['foo'],
'help': 'foo help'
}, {
'name': ['bar'],
'help': '',
'default': None
}
]
}
]
}
]
assert data == parser_navigate(data, '')
开发者ID:ribozz,项目名称:sphinx-argparse,代码行数:59,代码来源:test_parser.py
示例9: test_parse_nested_with_alias
def test_parse_nested_with_alias():
parser = argparse.ArgumentParser()
parser.add_argument('foo', default=False, help='foo help')
parser.add_argument('bar', default=False)
subparsers = parser.add_subparsers()
subparser = subparsers.add_parser('install', aliases=['i'], help='install help')
subparser.add_argument('ref', type=str, help='foo1 help')
subparser.add_argument('--upgrade', action='store_true', default=False, help='foo2 help')
data = parse_parser(parser)
assert data['action_groups'][0]['options'] == [
{
'name': ['foo'],
'help': 'foo help',
'default': False
}, {
'name': ['bar'],
'help': '',
'default': False
}
]
assert data['children'] == [
{
'name': 'install (i)',
'identifier': 'install',
'help': 'install help',
'usage': 'usage: py.test install [-h] [--upgrade] ref',
'bare_usage': 'py.test install [-h] [--upgrade] ref',
'action_groups': [
{
'title': 'Positional Arguments',
'description': None,
'options': [
{
'name': ['ref'],
'help': 'foo1 help',
'default': None
}
]
},
{
'description': None,
'title': 'Named Arguments',
'options': [
{
'name': ['--upgrade'],
'default': False,
'help': 'foo2 help'
}
]
}
]
}
]
开发者ID:ribozz,项目名称:sphinx-argparse,代码行数:58,代码来源:test_parser.py
示例10: test_parse_opt_choices
def test_parse_opt_choices():
parser = argparse.ArgumentParser()
parser.add_argument("--move", choices=["rock", "paper", "scissors"])
data = parse_parser(parser)
assert data["action_groups"][0]["options"] == [
{"name": ["--move"], "default": None, "help": "", "choices": ["rock", "paper", "scissors"]}
]
开发者ID:fidelram,项目名称:sphinx-argparse,代码行数:9,代码来源:test_parser.py
示例11: test_parse_positional
def test_parse_positional():
parser = argparse.ArgumentParser()
parser.add_argument("foo", default=False, help="foo help")
parser.add_argument("bar", default=False)
data = parse_parser(parser)
assert data["args"] == [
{"name": "foo", "help": "foo help", "metavar": None},
{"name": "bar", "help": "", "metavar": None},
]
开发者ID:fidelram,项目名称:sphinx-argparse,代码行数:11,代码来源:test_parser.py
示例12: test_parse_options
def test_parse_options():
parser = argparse.ArgumentParser()
parser.add_argument("--foo", action="store_true", default=False, help="foo help")
parser.add_argument("--bar", action="store_true", default=False)
data = parse_parser(parser)
assert data["action_groups"][0]["options"] == [
{"name": ["--foo"], "default": False, "help": "foo help"},
{"name": ["--bar"], "default": False, "help": ""},
]
开发者ID:fidelram,项目名称:sphinx-argparse,代码行数:11,代码来源:test_parser.py
示例13: test_parse_arg_choices
def test_parse_arg_choices():
parser = argparse.ArgumentParser()
parser.add_argument('move', choices=['rock', 'paper', 'scissors'])
data = parse_parser(parser)
assert data['args'] == [
{
'name': 'move',
'help': '',
'choices': ['rock', 'paper', 'scissors']
}
]
开发者ID:jamesra,项目名称:sphinx-argparse,代码行数:13,代码来源:test_parser.py
示例14: test_fill_in_default_prog
def test_fill_in_default_prog():
"""
Ensure that %(default)s and %(prog)s are getting properly filled in inside help=''
"""
parser = argparse.ArgumentParser(prog='test_fill_in_default_prog')
parser.add_argument('bar', default='foo', help='%(prog)s (default: %(default)s)')
data = parse_parser(parser)
assert data['action_groups'][0]['options'] == [
{
'default': '"foo"',
'name': ['bar'],
'help': 'test_fill_in_default_prog (default: "foo")'
}
]
开发者ID:ribozz,项目名称:sphinx-argparse,代码行数:15,代码来源:test_parser.py
示例15: test_parse_description
def test_parse_description():
parser = argparse.ArgumentParser(description="described", epilog="epilogged")
parser.add_argument("foo", default=False, help="foo help")
parser.add_argument("bar", default=False)
data = parse_parser(parser)
assert data["description"] == "described"
assert data["epilog"] == "epilogged"
assert data["args"] == [
{"name": "foo", "help": "foo help", "metavar": None},
{"name": "bar", "help": "", "metavar": None},
]
开发者ID:fidelram,项目名称:sphinx-argparse,代码行数:15,代码来源:test_parser.py
示例16: test_parse_positional
def test_parse_positional():
parser = argparse.ArgumentParser()
parser.add_argument('foo', default=False, help='foo help')
parser.add_argument('bar', default=False)
data = parse_parser(parser)
assert data['args'] == [
{
'name': 'foo',
'help': 'foo help'
}, {
'name': 'bar',
'help': ''
},
]
开发者ID:cottrell,项目名称:sphinx-argparse,代码行数:16,代码来源:test_parser.py
示例17: test_aliased_traversal
def test_aliased_traversal():
parser = argparse.ArgumentParser()
subparsers1 = parser.add_subparsers()
subparsers1.add_parser('level1', aliases=['l1'])
data = parse_parser(parser)
data2 = parser_navigate(data, 'level1')
assert(data2 == {
'bare_usage': 'py.test level1 [-h]',
'help': '',
'usage': 'usage: py.test level1 [-h]',
'name': 'level1 (l1)',
'identifier': 'level1'})
开发者ID:ribozz,项目名称:sphinx-argparse,代码行数:16,代码来源:test_parser.py
示例18: test_parse_positional
def test_parse_positional():
parser = argparse.ArgumentParser()
parser.add_argument('foo', default=False, help='foo help')
parser.add_argument('bar', default=False)
data = parse_parser(parser)
assert data['action_groups'][0]['options'] == [
{
'name': ['foo'],
'help': 'foo help',
'default': False
}, {
'name': ['bar'],
'help': '',
'default': False
}
]
开发者ID:ribozz,项目名称:sphinx-argparse,代码行数:18,代码来源:test_parser.py
示例19: run
def run(self):
mod = __import__(self.options['module'], globals(), locals(), self.options['module'].split('.')[-1:])
func = get_ref(mod, self.options['func'])
parser = func()
if not 'path' in self.options:
self.options['path'] = ''
path = str(self.options['path'])
parser.prog = self.options['prog']
result = parse_parser(parser,
skip_default_values='nodefault' in self.options)
result = parser_navigate(result, path)
nested_content = nodes.paragraph()
self.state.nested_parse(self.content, self.content_offset, nested_content)
nested_content = nested_content.children
items = []
# add common content between
for item in nested_content:
if not isinstance(item, nodes.definition_list):
items.append(item)
if 'description' in result:
items.append(nodes.paragraph(text=result['description']))
items.append(nodes.literal_block(text=result['usage']))
items.append(print_command_args_and_opts(
print_arg_list(result, nested_content),
print_opt_list(result, nested_content),
print_subcommand_list(result, nested_content)
))
if 'epilog' in result:
items.append(nodes.paragraph(text=result['epilog']))
return items
开发者ID:cottrell,项目名称:sphinx-argparse,代码行数:44,代码来源:ext.py
示例20: test_parse_description
def test_parse_description():
parser = argparse.ArgumentParser(description='described', epilog='epilogged')
parser.add_argument('foo', default=False, help='foo help')
parser.add_argument('bar', default=False)
data = parse_parser(parser)
assert data['description'] == 'described'
assert data['epilog'] == 'epilogged'
assert data['args'] == [
{
'name': 'foo',
'help': 'foo help'
}, {
'name': 'bar',
'help': ''
},
]
开发者ID:cottrell,项目名称:sphinx-argparse,代码行数:20,代码来源:test_parser.py
注:本文中的sphinxarg.parser.parse_parser函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论