cli.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:stream2segment 作者: rizac 项目源码 文件源码
def set_help_from_yaml(cls, ctx, param, value):
        """
        When attaching this function as `callback` argument to an Option (`click.Option`),
        it will set
        an automatic help for all Options of the same command, which do not have an `help`
        specified and are found in the default config file for downloading
        (currently `download.yaml`).
        The Option having as callback this function must also have `is_eager=True`.
        Example:
        Assuming opt1, opt2, opt3 are variables of the config yaml file, and opt4 not, this
        sets the default help for opt1 and opt2:
\@click.Option('--opt1', ..., callback=set_help_from_yaml, is_eager=True,...)
    \@click.Option('--opt2'...)
    \@click.Option('--opt3'..., help='my custom help do not set the config help')
    \@click.Option('--opt4'...)
    ...
    ```
    """
    cfg_doc = cls.DEFAULTDOC
    for option in (opt for opt in ctx.command.params if opt.param_type_name == 'option'):
        if option.help is None:
            option.help = cfg_doc.get(option.name, None)

    return value

```

评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号