rework args to fix argparse bug
This commit is contained in:
104
src/__init__.py
104
src/__init__.py
@@ -2,62 +2,56 @@
|
|||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from config import Config
|
from config import Config#
|
||||||
|
import argparse
|
||||||
|
|
||||||
config = Config("config/settings.yaml")
|
config = Config("config/settings.yaml")
|
||||||
|
__version__ = "0.1.0"
|
||||||
# if programm launched with argument --debug, set debug to True
|
# if programm launched with argument --debug, set debug to True
|
||||||
if "--debug" in sys.argv:
|
# 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:
|
|
||||||
# config.debug = True
|
# config.debug = True
|
||||||
# if args.version:
|
# # if programm launched with argument --log, set log_debug
|
||||||
# print(f"Version: {__version__}")
|
# if "--log" in sys.argv:
|
||||||
# sys.exit()
|
|
||||||
# if args.log:
|
|
||||||
# config.log_debug = True
|
# config.log_debug = True
|
||||||
# if args.no_backup:
|
valid_args = ["--debug", "--log", "--no-backup", "--ic-logging", "--version", "-h"]
|
||||||
# config.database.do_backup = False
|
|
||||||
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user