Mercurial > hg > sqlex
changeset 4:b440206930ac
stub table optional positional argument
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 01 Apr 2017 09:28:49 -0700 |
parents | 5f1e1ac96aa7 |
children | 3a7f515571dc |
files | sqlex/main.py |
diffstat | 1 files changed, 9 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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()