python命令行工具模块-click
基本用法:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 import click 2 3 4 @click.command() 5 @click.option('--n', default=1, help='Basic Value Options') 6 def dots(n): 7 click.echo('.' * n) 8 9 if __name__ == '__main__': 10 dots()
运行结果:
多参数用法:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 import click 2 3 4 @click.command() 5 @click.option('--pos', nargs=2, type=float) 6 def findme(pos): 7 click.echo('%s / %s' % pos) 8 9 if __name__ == '__main__': 10 findme()
运行结果:
多option用法:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 import click 2 3 4 @click.command() 5 @click.option('--message', '-m', multiple=True) 6 def commit(message): 7 click.echo('\n'.join(message)) 8 9 if __name__ == '__main__': 10 commit()
运行结果:
更多用法请参考官方文档,官方文档:http://click.pocoo.org/5/options/