Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[+] Add config file arg #48

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions hyfetch/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down