Thursday, April 24, 2014

Use Click Package to Write Beautiful Command Application with Python

click is a Python package for creating beautiful command line interfaces in a composable way with as little amount of code as necessary. It’s the “Command Line Interface Creation Kit”. It’s highly configurable but comes with good defaults out of the box.

Install
pip install click 
Hello world Sample
import click

@click.command()
@click.option('--count', default=1, help='number of greetings')
@click.option('--name', prompt='Your name',
              help='the person to greet', required=True)
def hello(count, name):
    for x in range(count):
        print('Hello %s!' % name)

if __name__ == '__main__':
    hello()
You can find quickstart and full docs here.

No comments:

Post a Comment