Last active
October 16, 2015 15:32
-
-
Save DenisCarriere/5062ec064b5f430defa9 to your computer and use it in GitHub Desktop.
How to start your first Command Line Interface with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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