Add basic argument parsing in main

master
Lertsenem 2020-07-07 01:54:42 +02:00
parent f4116f46cb
commit 6da2b5e27c
1 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,93 @@
from .version import VERSION_NAME
import argparse
import logging
import sys
# =============================================================================
def main():
# -------------------------------------------------------------------------
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(
dest = "command",
help = "commands",
)
parser.add_argument( "--proxy", "-p",
default = None,
help = "the proxy to use" )
parser.add_argument( "--token", "-t",
default = None,
help = "the auhentication token to use" )
# -------------------------------------------------------------------------
top8_parser = subparsers.add_parser(
"top8",
)
top8_parser.add_argument(
"tournament",
default = None,
help = "The tournament slug or id",
)
top8_parser.add_argument(
"--template", "-T",
default = "default",
help = "The local result template to use",
)
top8_parser.add_argument(
"--lkrz-file", "-f",
default = None,
help = "The lkrz file in which the results are stored ; if it " \
"does not exist, one will be created from the smashgg data",
)
# -------------------------------------------------------------------------
parser.add_argument( "--verbose", "-v",
default = 0,
action = "count",
help = "increase verbosity" )
parser.add_argument( "--version", "-V",
default = False,
action = "store_true",
help = "show version number" )
# -------------------------------------------------------------------------
args = parser.parse_args()
# Set log level
# -------------------------------------------------------------------------
log = logging.getLogger(NAME)
log.setLevel(logging.DEBUG)
log_handler_console = logging.StreamHandler()
log_handler_console.setLevel(logging.WARNING)
if(args.verbose >= 2):
log_handler_console.setLevel(logging.DEBUG)
elif(args.verbose >=1):
log_handler_console.setLevel(logging.INFO)
else:
log_handler_console.setLevel(logging.WARNING)
log_formatter_console = logging.Formatter("%(name)s:%(levelname)s: %(message)s")
log_handler_console.setFormatter(log_formatter_console)
log.addHandler(log_handler_console)
# Print version if required
# -------------------------------------------------------------------------
if args.version:
print(VERSION_NAME)
sys.exit(0)
# =============================================================================
if __name__ == '__main__':
main()