diff --git a/src/twomartens/masterthesis/cli.py b/src/twomartens/masterthesis/cli.py index 5d9278f..7534117 100644 --- a/src/twomartens/masterthesis/cli.py +++ b/src/twomartens/masterthesis/cli.py @@ -33,7 +33,7 @@ from twomartens.masterthesis import config as conf def config(args: argparse.Namespace) -> None: if args.action == "get": - print(conf.get_property(args.property)) + print(str(conf.get_property(args.property))) elif args.action == "set": conf.set_property(args.property, args.value) elif args.action == "list": diff --git a/src/twomartens/masterthesis/config.py b/src/twomartens/masterthesis/config.py index 994a56c..5a50b69 100644 --- a/src/twomartens/masterthesis/config.py +++ b/src/twomartens/masterthesis/config.py @@ -29,7 +29,7 @@ Functions: """ import configparser import os - +from typing import Union CONFIG_FILE = "tm-masterthesis-config.ini" _CONFIG_PROPS = { @@ -55,7 +55,7 @@ _CONFIG_PROPS = { } -def get_property(key: str) -> str: +def get_property(key: str) -> Union[str, float, int, bool]: parser = configparser.ConfigParser() config_file = f"{os.getcwd()}/{CONFIG_FILE}" @@ -63,7 +63,19 @@ def get_property(key: str) -> str: parser.read(config_file) section, prop = tuple(key.split(".")) - return parser.get(section, prop) + cast = _CONFIG_PROPS[section][prop][0] + + value = None + if cast is str: + value = parser.get(section, prop) + elif cast is float: + value = parser.getfloat(section, prop) + elif cast is int: + value = parser.getint(section, prop) + elif cast is bool: + value = parser.getboolean(section, prop) + + return value def set_property(key: str, value: str) -> None: