当前位置: 首页>>代码示例>>Python>>正文


Python docopt.DocoptExit方法代码示例

本文整理汇总了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 
开发者ID:projectcalico,项目名称:k8s-exec-plugin,代码行数:21,代码来源:policy.py

示例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) 
开发者ID:ReviewNB,项目名称:treon,代码行数:19,代码来源:treon.py

示例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() 
开发者ID:leeyiw,项目名称:dnspod_ddns,代码行数:20,代码来源:dnspod_ddns.py

示例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)
            ) 
开发者ID:OSInside,项目名称:kiwi,代码行数:27,代码来源:kiwi_compat.py

示例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) 
开发者ID:QData,项目名称:deepWordBug,代码行数:7,代码来源:docopt_command.py

示例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) 
开发者ID:aliyun,项目名称:aliyun-log-cli,代码行数:43,代码来源:cli_core.py

示例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']) 
开发者ID:dcos,项目名称:dcos-launch,代码行数:9,代码来源:test_cli.py

示例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__) 
开发者ID:rachmadaniHaryono,项目名称:we-get,代码行数:5,代码来源:test_arguments.py

示例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__) 
开发者ID:rachmadaniHaryono,项目名称:we-get,代码行数:5,代码来源:test_arguments.py

示例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__) 
开发者ID:rachmadaniHaryono,项目名称:we-get,代码行数:5,代码来源:test_arguments.py

示例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__) 
开发者ID:rachmadaniHaryono,项目名称:we-get,代码行数:5,代码来源:test_arguments.py

示例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__) 
开发者ID:rachmadaniHaryono,项目名称:we-get,代码行数:5,代码来源:test_arguments.py

示例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__) 
开发者ID:rachmadaniHaryono,项目名称:we-get,代码行数:5,代码来源:test_arguments.py

示例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!') 
开发者ID:rachmadaniHaryono,项目名称:we-get,代码行数:8,代码来源:test_arguments.py

示例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!') 
开发者ID:rachmadaniHaryono,项目名称:we-get,代码行数:8,代码来源:test_arguments.py


注:本文中的docopt.DocoptExit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。