"""
********
CLI
********
Command Line Interface based on click.
**************************************
Copied from http://chase-seibert.github.io/blog
/2014/03/21/python-multilevel-argparse.html.
No relation, I don't think. ;)
"""
import argparse, sys
import controller
[docs]class CLI(object):
def __init__(self, raw_args):
parser = argparse.ArgumentParser(
description="Git-like CLI tool for "
"Firetable."
)
parser.add_argument('command',
help='Subcommand to run: get, post, patch, put, or delete. '
'Run fire COMMAND -h to see the help of individual subcommands.'
)
args = parser.parse_args(raw_args[1:2])
if not hasattr(self, args.command):
print "Unrecognized command"
parser.print_help()
exit(1)
getattr(self, args.command)(raw_args)
[docs] def get(self, raw_args):
parser = argparse.ArgumentParser(
description="Download table from Airtable.", prog="fire get"
)
parser.add_argument('table', help='the table to download')
parser.add_argument('-v', '--view', nargs=1, help='the table to download')
parser.add_argument('-f', '--fields', nargs="+", help='the table to download')
parser.add_argument('-m', '--max', nargs=1, type=int, help='the table to download')
parser.add_argument('--filter', nargs=1, help='the table to download')
parser.add_argument('--sort', nargs=1, help='the table to download')
args = parser.parse_args(raw_args[2:])
print "Got args: {}".format(vars(args))
result = controller.get(
args.table,
view=args.view,
fields=args.fields,
max=args.max,
filter=args.filter,
sort=args.sort,
)
print result
[docs] def post(self):
print "Not implemented yet..."
exit(1)
[docs] def patch(self):
print "Not implemented yet..."
exit(1)
[docs] def put(self):
print "Not implemented yet..."
exit(1)
[docs] def delete(self):
print "Not implemented yet..."
exit(1)
[docs]def fire():
CLI(sys.argv)
if __name__ == "__main__":
fire()