本文整理汇总了Python中docopt.DocoptExit方法的典型用法代码示例。如果您正苦于以下问题:Python docopt.DocoptExit方法的具体用法?Python docopt.DocoptExit怎么用?Python docopt.DocoptExit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docopt
的用法示例。
在下文中一共展示了docopt.DocoptExit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_line
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def parse_line(self, policy):
"""
Takes a single line of policy as defined in the annotations of a
pod and returns the equivalent libcalico Rule object.
:param policy: Policy string from annotations.
:return: A Rule object which represent the given policy.
"""
_log.info("Parsing policy line: '%s'", policy)
splits = policy.split()
try:
args = docopt.docopt(__doc__, argv=splits)
except docopt.DocoptExit:
raise ValueError("Failed to parse policy: %s", policy)
# Generate a rule object from the arguments.
rule = self._generate_rule(args)
return rule
示例2: main
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def main():
try:
arguments = docopt(__doc__, version=__version__)
except DocoptExit:
sys.exit(__doc__)
setup_logging(arguments)
LOG.info('Executing treon version %s', __version__)
thread_count = arguments['--threads'] or DEFAULT_THREAD_COUNT
notebooks = get_notebooks_to_test(arguments)
tasks = [Task(notebook) for notebook in notebooks]
print_test_collection(notebooks)
trigger_tasks(tasks, thread_count)
has_failed = print_test_result(tasks)
if has_failed:
sys.exit(-1)
示例3: main
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def main():
try:
arguments = docopt.docopt(__doc__)
except docopt.DocoptExit:
print __doc__.strip()
return
app = App(arguments)
action = arguments['-d']
if action != None:
if action in ['start', 'stop', 'restart']:
sys.argv[1] = action
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()
else:
print __doc__.strip()
return
else:
app.run()
示例4: __init__
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def __init__(self):
try:
self.compat_args = docopt(
__doc__, options_first=True
)
except DocoptExit as e:
message_header = '\n'.join(
[
'The provided legacy kiwi commandline is invalid',
'or not supported. Plase check the following usage',
'information if you just mistyped the call:'
]
)
message_footer = '\n'.join(
[
'In case of a correct legacy kiwi command but not',
'supported by kiwicompat, please contact us via the',
'github issue system at:\n',
'https://github.com/OSInside/kiwi/issues'
]
)
raise NotImplementedError(
'%s\n\n%s\n\n%s' %
(message_header, format(e), message_footer)
)
示例5: docopt_full_help
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def docopt_full_help(docstring, *args, **kwargs):
try:
return docopt(docstring, *args, **kwargs)
except DocoptExit:
raise SystemExit(docstring)
示例6: docopt_ex
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def docopt_ex(doc, usage, method_param_usage, hlp=True, ver=None):
argv = sys.argv[1:]
# support customized help
if len(argv) <= 0 or "--help" in argv[0]:
print(usage)
return
first_cmd = argv[0]
try:
return docopt(doc, help=hlp, version=ver)
except DocoptExit as ex:
# show customized error
if first_cmd == "configure":
print("Invalid parameters.\n")
print("Usage:\n" + MORE_DOCOPT_CMD)
return
elif first_cmd == "log" and len(argv) > 1:
second_cmd = argv[1]
header_printed = False
for cmd in doc.split("\n"):
if "aliyunlog log " + second_cmd + " " in cmd:
if not header_printed:
print("Invalid parameters.\n")
print("Usage:")
header_printed = True
print(cmd)
if header_printed and second_cmd in method_param_usage:
print("\nOptions:")
print(method_param_usage[second_cmd])
print(GLOBAL_OPTIONS_STR)
else:
print("Unknown subcommand.")
print(usage)
else:
print("Unknown command.\n")
print(usage)
示例7: test_noop
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def test_noop():
"""Ensure docopt exit (displays usage)
"""
with pytest.raises(DocoptExit):
main([])
with pytest.raises(DocoptExit):
main(['foobar'])
示例8: test_required_argument_search
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def test_required_argument_search(self):
sys.argv = ['prog_name', '--search']
self.assertRaises(docopt.DocoptExit, docopt.docopt, __doc__)
示例9: test_required_argument_target
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def test_required_argument_target(self):
sys.argv = ['prog_name', '--target']
self.assertRaises(docopt.DocoptExit, docopt.docopt, __doc__)
示例10: test_required_argument_filter
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def test_required_argument_filter(self):
sys.argv = ['prog_name', '--filter']
self.assertRaises(docopt.DocoptExit, docopt.docopt, __doc__)
示例11: test_required_argument_results
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def test_required_argument_results(self):
sys.argv = ['prog_name', '--results']
self.assertRaises(docopt.DocoptExit, docopt.docopt, __doc__)
示例12: test_required_argument_quality
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def test_required_argument_quality(self):
sys.argv = ['prog_name', '--quality']
self.assertRaises(docopt.DocoptExit, docopt.docopt, __doc__)
示例13: test_required_argument_sort_type
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def test_required_argument_sort_type(self):
sys.argv = ['prog_name', '--sort-type']
self.assertRaises(docopt.DocoptExit, docopt.docopt, __doc__)
示例14: test_no_required_argument_list
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def test_no_required_argument_list(self):
sys.argv = ['prog_name', '--list']
try:
docopt.docopt(__doc__)
except docopt.DocoptExit:
self.fail('--list required argument!')
示例15: test_no_required_argument_links
# 需要导入模块: import docopt [as 别名]
# 或者: from docopt import DocoptExit [as 别名]
def test_no_required_argument_links(self):
sys.argv = ['prog_name', '--links']
try:
docopt.docopt(__doc__)
except docopt.DocoptExit:
self.fail('--links required argument!')