[+] Add config file arg

This commit is contained in:
Your name 2022-12-04 22:26:41 +03:00
parent d607b3326c
commit dd5084fbe8

View file

@ -18,16 +18,14 @@ from .neofetch_util import *
from .presets import PRESETS 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 Check if the configuration exists. Return the config object if it exists. If not, call the
config creator config creator
TODO: Config path param
:return: Config object :return: Config object
""" """
if CONFIG_PATH.is_file(): if path.is_file():
try: try:
return Config.from_dict(json.loads(CONFIG_PATH.read_text('utf-8'))) return Config.from_dict(json.loads(CONFIG_PATH.read_text('utf-8')))
except KeyError: except KeyError:
@ -355,6 +353,7 @@ def run():
parser = argparse.ArgumentParser(description=color(f'{hyfetch} - neofetch with flags <3')) 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', 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('-p', '--preset', help=f'Use preset', choices=PRESETS.keys())
parser.add_argument('-m', '--mode', help=f'Color mode', choices=['8bit', 'rgb']) 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) 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()) print(get_distro_ascii())
return 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 # 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 # Param overwrite config
if args.preset: if args.preset: