From dd5084fbe87a20750f0901be1cb886cb7bbdc99f Mon Sep 17 00:00:00 2001 From: Your name Date: Sun, 4 Dec 2022 22:26:41 +0300 Subject: [PATCH] [+] Add config file arg --- hyfetch/main.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/hyfetch/main.py b/hyfetch/main.py index f0136ac9..73c6c661 100755 --- a/hyfetch/main.py +++ b/hyfetch/main.py @@ -18,16 +18,14 @@ from .neofetch_util import * from .presets import PRESETS -def check_config() -> Config: +def check_config(path) -> Config: """ Check if the configuration exists. Return the config object if it exists. If not, call the config creator - TODO: Config path param - :return: Config object """ - if CONFIG_PATH.is_file(): + if path.is_file(): try: return Config.from_dict(json.loads(CONFIG_PATH.read_text('utf-8'))) except KeyError: @@ -355,6 +353,7 @@ def run(): parser = argparse.ArgumentParser(description=color(f'{hyfetch} - neofetch with flags <3')) parser.add_argument('-c', '--config', action='store_true', help=color(f'Configure {hyfetch}')) + parser.add_argument('-C', '--config-file', dest='config_file', default=CONFIG_PATH, help=f'Use another config file') parser.add_argument('-p', '--preset', help=f'Use preset', choices=PRESETS.keys()) parser.add_argument('-m', '--mode', help=f'Color mode', choices=['8bit', 'rgb']) parser.add_argument('--c-scale', dest='scale', help=f'Lighten colors by a multiplier', type=float) @@ -387,8 +386,16 @@ def run(): print(get_distro_ascii()) return + # Check if user provided alternative config path + if not args.config_file == CONFIG_PATH: + args.config_file = Path(os.path.abspath(args.config_file)) + + # If provided file does not exist use default config + if not args.config_file.is_file(): + args.config_file = CONFIG_PATH + # Load config or create config - config = create_config() if args.config else check_config() + config = create_config() if args.config else check_config(args.config_file) # Param overwrite config if args.preset: