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 commit_on_close: bool = True 16 log_dir: Pathier = Pathier(__file__).parent 17 intro = "Starting customshell (enter help or ? for command info)..." 18 prompt = "customshell>" 19 20 21# For help with adding custom functionality see: 22# https://github.com/matt-manes/argshell 23# https://github.com/matt-manes/databased/blob/main/src/databased/dbshell.py 24# https://github.com/matt-manes/databased/blob/main/src/databased/dbparsers.py 25 26 27def get_args() -> argparse.Namespace: 28 parser = argparse.ArgumentParser() 29 30 parser.add_argument( 31 "dbpath", 32 nargs="?", 33 type=str, 34 help=""" The database file to use. If not provided the current working directory will be scanned for database files. """, 35 ) 36 args = parser.parse_args() 37 38 return args 39 40 41def main(args: argparse.Namespace | None = None): 42 if not args: 43 args = get_args() 44 dbshell = CustomShell() 45 if args.dbpath: 46 dbshell.dbpath = Pathier(args.dbpath) 47 dbshell.cmdloop() 48 49 50if __name__ == "__main__": 51 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 commit_on_close: bool = True 17 log_dir: Pathier = Pathier(__file__).parent 18 intro = "Starting customshell (enter help or ? for command info)..." 19 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_set_commit_on_close
- 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:
28def get_args() -> argparse.Namespace: 29 parser = argparse.ArgumentParser() 30 31 parser.add_argument( 32 "dbpath", 33 nargs="?", 34 type=str, 35 help=""" The database file to use. If not provided the current working directory will be scanned for database files. """, 36 ) 37 args = parser.parse_args() 38 39 return args
def
main(args: argparse.Namespace | None = None):