[+] Add config file arg
This commit is contained in:
parent
d607b3326c
commit
dd5084fbe8
1 changed files with 12 additions and 5 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue