cli: initial import for import/export
This commit is contained in:
parent
dc59921498
commit
0c349091e7
3 changed files with 143 additions and 13 deletions
29
app/cli/__main__.py
Normal file
29
app/cli/__main__.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
from os.path import basename
|
||||
|
||||
from app.cli.db import DbCliHandler
|
||||
|
||||
|
||||
def parse_args(argv):
|
||||
if basename(argv[0]) == "__main__.py":
|
||||
argv[0] = "bypass"
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-v", "--verbose", help="increase logging verbosity", action="store_true")
|
||||
subparsers = parser.add_subparsers(title="command", help="command to run")
|
||||
DbCliHandler.add_subparser_to(subparsers)
|
||||
args = parser.parse_args(argv[1:])
|
||||
if "cls" in args:
|
||||
command = args.cls(args)
|
||||
command.run()
|
||||
else:
|
||||
parser.print_help()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
verbose = "-v" in sys.argv or "--verbose" in sys.argv
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG if verbose else logging.INFO)
|
||||
logging.debug("Arguments: %s", sys.argv)
|
||||
parse_args(sys.argv)
|
Loading…
Add table
Add a link
Reference in a new issue