# HG changeset patch # User Jeff Hammel # Date 1491064129 25200 # Node ID b440206930ac1a33b1eb6255360cc83fd1b119d3 # Parent 5f1e1ac96aa7b94e30f7d2c98f2db1dd39106eaa stub table optional positional argument diff -r 5f1e1ac96aa7 -r b440206930ac sqlex/main.py --- a/sqlex/main.py Sat Apr 01 09:19:22 2017 -0700 +++ b/sqlex/main.py Sat Apr 01 09:28:49 2017 -0700 @@ -31,6 +31,8 @@ argparse.ArgumentParser.__init__(self, **kwargs) self.add_argument('db', help="sqlite `.db` file") + self.add_argument('table', nargs='?', + help="table to operate on") self.add_argument('--tables', '--list-tables', dest='list_tables', action='store_true', default=False, help="list tables and exit") @@ -62,9 +64,15 @@ db = SQLEx(options.db) if options.list_tables: + # list tables and return + # if `table` argument is provided, exit 1 + # if not available. Otherwise exit 0 tables = db.tables() print ('\n'.join(tables)) - return + retval = 0 + if options.table: + retval = int(options.table not in tables) + return retval if __name__ == '__main__': main()