databased.customshell
1import argparse 2 3from argshell import ArgShellParser, Namespace, with_parser 4from pathier import Pathier 5 6from databased import Databased, dbparsers 7from databased.dbshell import DBShell 8 9 10class CustomShell(DBShell): 11 _dbpath: Pathier = None # Replace None with a path to a database file to set a default database # type: ignore 12 connection_timeout: float = 10 13 detect_types: bool = True 14 enforce_foreign_keys: bool = True 15 intro = "Starting customshell (enter help or ? for command info)..." 16 prompt = "customshell>" 17 18 19# For help with adding custom functionality see: 20# https://github.com/matt-manes/argshell 21# https://github.com/matt-manes/databased/blob/main/src/databased/dbshell.py 22# https://github.com/matt-manes/databased/blob/main/src/databased/dbparsers.py 23 24 25def get_args() -> argparse.Namespace: 26 parser = argparse.ArgumentParser() 27 28 parser.add_argument( 29 "dbpath", 30 nargs="?", 31 type=str, 32 help=""" The database file to use. If not provided the current working directory will be scanned for database files. """, 33 ) 34 args = parser.parse_args() 35 36 return args 37 38 39def main(args: argparse.Namespace | None = None): 40 if not args: 41 args = get_args() 42 dbshell = CustomShell() 43 if args.dbpath: 44 dbshell.dbpath = Pathier(args.dbpath) 45 dbshell.cmdloop() 46 47 48if __name__ == "__main__": 49 main(get_args())
11class CustomShell(DBShell): 12 _dbpath: Pathier = None # Replace None with a path to a database file to set a default database # type: ignore 13 connection_timeout: float = 10 14 detect_types: bool = True 15 enforce_foreign_keys: bool = True 16 intro = "Starting customshell (enter help or ? for command info)..." 17 prompt = "customshell>"
Subclass this to create custom ArgShells.
Inherited Members
- cmd.Cmd
- Cmd
- precmd
- postcmd
- postloop
- parseline
- onecmd
- completedefault
- completenames
- complete
- get_names
- complete_help
- print_topics
- columnize
- databased.dbshell.DBShell
- default
- display
- do_add_column
- do_add_table
- do_backup
- do_count
- do_customize
- do_dbpath
- do_delete
- do_describe
- do_drop_column
- do_drop_table
- do_dump
- do_flush_log
- do_help
- do_new_db
- do_properties
- do_query
- do_rename_column
- do_rename_table
- do_restore
- do_scan
- do_schema
- do_script
- do_select
- do_set_connection_timeout
- do_set_detect_types
- do_set_enforce_foreign_keys
- do_size
- do_tables
- do_update
- do_use
- do_vacuum
- do_views
- preloop
- argshell.argshell.ArgShell
- do_quit
- do_sys
- cmdloop
- emptyline
def
get_args() -> argparse.Namespace:
26def get_args() -> argparse.Namespace: 27 parser = argparse.ArgumentParser() 28 29 parser.add_argument( 30 "dbpath", 31 nargs="?", 32 type=str, 33 help=""" The database file to use. If not provided the current working directory will be scanned for database files. """, 34 ) 35 args = parser.parse_args() 36 37 return args
def
main(args: argparse.Namespace | None = None):