Skip to content

Instantly share code, notes, and snippets.

@DenisCarriere
Last active October 16, 2015 15:32
Show Gist options
  • Save DenisCarriere/5062ec064b5f430defa9 to your computer and use it in GitHub Desktop.
Save DenisCarriere/5062ec064b5f430defa9 to your computer and use it in GitHub Desktop.
How to start your first Command Line Interface with Python
#!/usr/bin/python
# encoding: utf8
import click
import logging
@click.command()
@click.argument('infile', nargs=-1)
@click.option('--out', '-o')
@click.option('--debug', is_flag=True)
def cli(infile, **kwargs):
if kwargs['debug']:
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
if infile:
logging.info(' '.join(infile))
else:
click.echo(
'Please include an input file path:\n'
'api filepath/example.kml --out filepath/example-edit.kml'
)
if __name__ == '__main__':
cli()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment