click 版本升级7.0踩过的坑

click 版本升级7.0踩过哪些坑?

  1. click 版本6.7升级至7.0以上,包名由 click 变更为 Click
  2. click 的 Options 和 Parameters 规则变更为如下:
  • For an option with ('-f', '--foo-bar'), the parameter name is foo_bar.
  • For an option with ('-x',), the parameter is x.
  • For an option with ('-f', '--filename', 'dest'), the parameter name is dest.
  • For an option with ('--CamelCaseOption',), the parameter is camelcaseoption.
  • For an arguments with (foogle), the parameter name is foogle. To provide a different human readable name for use in help text, see the section about Truncating Help Texts.

click 版本升级7.0及以上,当 option 为 '--foo_far' 时,命令行运行会把参数变更为 '--foo-bar',即 '—' 变 '-'。

click 版本升级后示例

# test.py 脚本命令如下:

@click.command()

@click.option('-lld', '--last-login-days', default=30, help='Days from user\'s last login day.')

@click.option('-gd', '--gap-days', default=3, help='Days between 2 wake-up user.')

@click.option('-env', default='test', help='test or production')

def get_something(last_login_days, gap_days, kill_days, env):
    
    print("last_login_days:{}".format(last_login_days))
    
    print("gap_days:{}".format(gap_days))
    
    print("env:{}".format(env))

   
if__name__ == '__main__':
    get_something()


# 执行脚本语句如下:

python test.py -lld 100 -gd 30 -env test

# Output:

# last_login_days:100

# gap_days:10

# kill_days:15

# env:test

参考资料:

posted @ 2018-10-24 17:57  深圳-随风  阅读(728)  评论(0编辑  收藏  举报