{"id":127312,"date":"2020-06-07T04:30:20","date_gmt":"2020-06-06T20:30:20","guid":{"rendered":"http:\/\/4563.org\/?p=127312"},"modified":"2020-06-07T04:30:20","modified_gmt":"2020-06-06T20:30:20","slug":"python-click-%e5%ad%90%e5%91%bd%e4%bb%a4%e6%80%8e%e4%b9%88%e5%85%b1%e7%94%a8%e7%88%b6%e7%ba%a7%e9%80%89%e9%a1%b9","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=127312","title":{"rendered":"Python click \u5b50\u547d\u4ee4\u600e\u4e48\u5171\u7528\u7236\u7ea7\u9009\u9879"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python click \u5b50\u547d\u4ee4\u600e\u4e48\u5171\u7528\u7236\u7ea7\u9009\u9879               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fangwenxue <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>import logging  import click  DEFAULT_FORMATTER = '%(asctime)s[%(filename)s:%(lineno)d][%(levelname)s]:%(message)s' logging.basicConfig(format=DEFAULT_FORMATTER, level=logging.INFO)   @click.group(invoke_without_command=True) @click.option('--limit', type=int, default=5) @click.option('--chunk-size', type=int, default=5) @click.option('-vvv', is_flag=True) @click.option('--debug', envvar='DEBUG', default=False, help='debug mode') @click.pass_context def cli(ctx, **kwargs):     if kwargs.get('debug'):         logging.basicConfig(format=DEFAULT_FORMATTER, level=logging.DEBUG)      ctx.obj = kwargs     if ctx.invoked_subcommand is None:         ctx.invoke('index')   @cli.command() @click.option('-a') @click.pass_context def index(ctx, **kwargs):     kwargs.update(ctx.obj)     print(kwargs)   @cli.command() @click.option('-b') @click.pass_context def test(ctx, **kwargs):     kwargs.update(ctx.obj)     print(kwargs)   if __name__ == '__main__':     cli()           python3 test.py -vvv test \u8fd9\u6837\u662f\u53ef\u4ee5\u7684  python3 test.py test -vvv   \u8fd9\u6837\u63d0\u793a\u627e\u4e0d\u5230\u9009\u9879 \u600e\u6837\u652f\u6301\u8fd9\u79cd\u547d\u4ee4  <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2076251\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ipwx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5199\u4e2a\u81ea\u5b9a\u4e49\u7684 decorator\uff0c\u5305\u88c5\u4e00\u4e0b\u4f60\u7684 child command\uff0c\u628a\u4f20\u8fdb\u6765\u7684\u901a\u7528\u53c2\u6570\u90fd\u5904\u7406\u597d\uff0c\u518d\u4e22\u7ed9\u5b50\u547d\u4ee4\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python click \u5b50\u547d\u4ee4\u600e&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/127312"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=127312"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/127312\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=127312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=127312"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=127312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}