diff --git a/src/__init__.py b/src/__init__.py index 0459e99..89fbd17 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -2,62 +2,56 @@ import sys -from config import Config +from config import Config# +import argparse + config = Config("config/settings.yaml") - +__version__ = "0.1.0" # if programm launched with argument --debug, set debug to True -if "--debug" in sys.argv: - config.debug = True -# if programm launched with argument --log, set log_debug -if "--log" in sys.argv: - config.log_debug = True - - -# arguments = argparse.ArgumentParser( -# prog="Ausleihsystem", -# description="Ein Ausleihsystem für Handbibliotheken", -# epilog="Version: {}".format(__version__), -# ) -# arguments.add_argument( -# "-d", -# "--debug", -# action="store_true", -# help="Display debug messages in terminal", -# default=False, -# required=False, -# ) -# arguments.add_argument( -# "-v", -# "--version", -# action="store_true", -# help="Display version number", -# default=False, -# required=False, -# ) -# arguments.add_argument( -# "-l", -# "--log", -# action="store_true", -# help="Log debug messages to logfile", -# default=False, -# required=False, -# ) -# arguments.add_argument( -# "--no-backup", -# action="store_true", -# help="Disable backup", -# default=False, -# required=False, -# ) - -# args = arguments.parse_args() -# # based on the arguments, set the config values -# if args.debug: +# if "--debug" in sys.argv: # config.debug = True -# if args.version: -# print(f"Version: {__version__}") -# sys.exit() -# if args.log: +# # if programm launched with argument --log, set log_debug +# if "--log" in sys.argv: # config.log_debug = True -# if args.no_backup: -# config.database.do_backup = False +valid_args = ["--debug", "--log", "--no-backup", "--ic-logging", "--version", "-h"] + +args_description = { + "--debug": "Enable debug mode", + "--log": "Enable logging", + "--no-backup": "Disable database backup", + "--ic-logging": "Enable icecream logging (not available in production)", + "--version": "Show version", + "-h": "Show help message and exit" +} + +args = sys.argv[1:] +if any(arg not in valid_args for arg in args): + print("Invalid argument present") + sys.exit() +def help(): + print("Ausleihsystem") + print("Ein Ausleihsystem für Handbibliotheken") + print("Version: {}".format(__version__)) + print("Valide Argumente:") + print("args") + print("--------") + print("usage: main.py [-h] [--debug] [--log] [--no-backup] [--ic-logging] [--version]") + print("options:") + for arg in valid_args: + print(f"{arg} : {args_description[arg]}") + +# based on the arguments, set the config values +if"-h" in args: + help() + sys.exit() +if "--debug" in args: + config.debug = True +if "--log" in args: + config.log_debug = True +if "--no-backup" in args: + config.no_backup = True +if "--ic-logging" in args: + config.ic_logging = True +if "--version" in args: + print(__version__) + sys.exit()