本文整理汇总了Python中invoke.parser.Parser.parse_argv方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.parse_argv方法的具体用法?Python Parser.parse_argv怎么用?Python Parser.parse_argv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类invoke.parser.Parser
的用法示例。
在下文中一共展示了Parser.parse_argv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parses_sys_argv_style_list_of_strings
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def parses_sys_argv_style_list_of_strings(self):
"parses sys.argv-style list of strings"
# Doesn't-blow-up tests FTL
mytask = Context(name="mytask")
mytask.add_arg("arg")
p = Parser(contexts=[mytask])
p.parse_argv(["mytask", "--arg", "value"])
示例2: other_tokens_afterwards_raise_parse_errors
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def other_tokens_afterwards_raise_parse_errors(self):
# NOTE: this is because of the special-casing where we supply
# the task name as the value when the flag is literally named
# "help".
task1 = Context("mytask")
init = Context(args=[Argument("help", optional=True)])
parser = Parser(initial=init, contexts=[task1])
with raises(ParseError, match=r".*foobar.*"):
parser.parse_argv(["mytask", "--help", "foobar"])
示例3: setup
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
class parsing_errors:
def setup(self):
self.p = Parser([Context(name='foo', args=[Argument('bar')])])
@raises(ParseError)
def missing_flag_values_raise_ParseError(self):
self.p.parse_argv(['foo', '--bar'])
def attaches_context_to_ParseErrors(self):
try:
self.p.parse_argv(['foo', '--bar'])
except ParseError, e:
assert e.context is not None
示例4: value_requiring_core_flags_also_work_correctly
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def value_requiring_core_flags_also_work_correctly(self):
"value-requiring core flags also work correctly"
initial = Context(args=[Argument("hide")])
task1 = Context("mytask")
parser = Parser(initial=initial, contexts=[task1])
result = parser.parse_argv(["mytask", "--hide", "both"])
assert result[0].args.hide.value == "both"
示例5: flag_values_not_parsed_as_flags
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def flag_values_not_parsed_as_flags(self):
a = Argument('foo', default=False, optional=True)
b = Argument('bar', default='')
c = Context(name='mytask', args=(a, b))
p = Parser(contexts=(c,))
r = p.parse_argv(['mytask', '--bar=--foo'])
assert not r[0].args['foo'].value
eq_(r[0].args['bar'].value, '--foo')
示例6: task_has_no_help_shows_per_task_help
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def task_has_no_help_shows_per_task_help(self):
task1 = Context('mytask')
init = Context(args=[Argument('help', optional=True)])
parser = Parser(initial=init, contexts=[task1])
result = parser.parse_argv(['mytask', '--help'])
assert len(result) == 2
assert result[0].args.help.value == 'mytask'
assert 'help' not in result[1].args
示例7: by_itself_base_case
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def by_itself_base_case(self):
task1 = Context("mytask")
init = Context(args=[Argument("help", optional=True)])
parser = Parser(initial=init, contexts=[task1])
result = parser.parse_argv(["mytask", "--help"])
assert len(result) == 2
assert result[0].args.help.value == "mytask"
assert "help" not in result[1].args
示例8: core_flags_work_normally_when_no_conflict
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def core_flags_work_normally_when_no_conflict(self):
# Initial parse context with an --echo, plus a no-args task
initial = Context(args=[self._echo()])
task1 = Context("mytask")
parser = Parser(initial=initial, contexts=[task1])
# Call with --echo in the per-task context, expect the core
# context got updated (vs an error)
result = parser.parse_argv(["mytask", "--echo"])
assert result[0].args.echo.value is True
示例9: task_has_no_h_shortflag_shows_per_task_help
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def task_has_no_h_shortflag_shows_per_task_help(self):
task1 = Context("mytask")
arg = Argument(names=("help", "h"), optional=True)
init = Context(args=[arg])
parser = Parser(initial=init, contexts=[task1])
result = parser.parse_argv(["mytask", "-h"])
assert len(result) == 2
assert result[0].args.help.value == "mytask"
assert "help" not in result[1].args
示例10: task_has_no_h_shortflag_shows_per_task_help
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def task_has_no_h_shortflag_shows_per_task_help(self):
task1 = Context('mytask')
arg = Argument(names=('help', 'h'), optional=True)
init = Context(args=[arg])
parser = Parser(initial=init, contexts=[task1])
result = parser.parse_argv(['mytask', '-h'])
eq_(len(result), 2)
eq_(result[0].args.help.value, 'mytask')
ok_('help' not in result[1].args)
示例11: setup
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
class parsing_errors:
def setup(self):
self.p = Parser([Context(name="foo", args=[Argument("bar")])])
def missing_flag_values_raise_ParseError(self):
with raises(ParseError):
self.p.parse_argv(["foo", "--bar"])
def attaches_context_to_ParseErrors(self):
try:
self.p.parse_argv(["foo", "--bar"])
except ParseError as e:
assert e.context is not None
def attached_context_is_None_outside_contexts(self):
try:
Parser().parse_argv(["wat"])
except ParseError as e:
assert e.context is None
示例12: when_conflict_per_task_args_win_out
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def when_conflict_per_task_args_win_out(self):
# Initial parse context with an --echo, plus task w/ same
initial = Context(args=[self._echo()])
task1 = Context("mytask", args=[self._echo()])
parser = Parser(initial=initial, contexts=[task1])
# Call with --echo in the per-task context, expect the task
# context got updated, and not core.
result = parser.parse_argv(["mytask", "--echo"])
assert result[0].args.echo.value is False
assert result[1].args.echo.value is True
示例13: _parse
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def _parse(argstr, parser=None, collection=None):
# TODO: this will clearly turn into the actual main cli stub sometime.
# TODO: Replace with actual objects at that time.
# Set up a parser
if parser is None:
parser = Parser()
# Naive string-to-argv: split on whitespace.
# It's probably safe to assume most tests won't be using spaces in flag
# values and stuff (e.g. "invoke --foo='biz baz'")
argv = argstr.split()
return parser.parse_argv(argv)
示例14: clones_noninitial_contexts
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def clones_noninitial_contexts(self):
a = Argument('foo')
eq_(a.value, None)
c = Context(name='mytask', args=(a,))
p = Parser(contexts=(c,))
assert p.contexts['mytask'] is c
r = p.parse_argv(['mytask', '--foo', 'val'])
assert p.contexts['mytask'] is c
c2 = r[0]
assert c2 is not c
a2 = c2.args['foo']
assert a2 is not a
eq_(a.value, None)
eq_(a2.value, 'val')
示例15: clones_initial_context
# 需要导入模块: from invoke.parser import Parser [as 别名]
# 或者: from invoke.parser.Parser import parse_argv [as 别名]
def clones_initial_context(self):
a = Argument('foo', kind=bool)
eq_(a.value, None)
c = Context(args=(a,))
p = Parser(initial=c)
assert p.initial is c
r = p.parse_argv(['--foo'])
assert p.initial is c
c2 = r[0]
assert c2 is not c
a2 = c2.args['foo']
assert a2 is not a
eq_(a.value, None)
eq_(a2.value, True)