From 2203afc601a1a16f299bb8e3691a57e45c8230fc Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Sat, 13 Feb 2021 17:59:48 -0500 Subject: [PATCH] Exit if specified config file does not exist --- lightcards/config.py | 6 ++++-- lightcards/runner.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lightcards/config.py b/lightcards/config.py index 2b8b938..04cfdf9 100644 --- a/lightcards/config.py +++ b/lightcards/config.py @@ -27,8 +27,10 @@ def read_file(file): files.append(local_xdg) if os.path.exists(local): files.append(local) - if os.path.exists(file): - files.append(file) + + files.append(file) + if not os.path.exists(file): + raise ConfigException(f'"{file}": No such file or directory') from None for f in files: exec(Path(str(f)).read_text(), {}, config) diff --git a/lightcards/runner.py b/lightcards/runner.py index 3b8737c..852bf5b 100644 --- a/lightcards/runner.py +++ b/lightcards/runner.py @@ -20,7 +20,9 @@ def parse_args(): parser.add_argument( "-c", "--config", + metavar="path", type=str, + default="/dev/null", help="specify custom config file", ) parser.add_argument( @@ -29,7 +31,7 @@ def parse_args(): metavar="view", type=int, choices=range(1, 4), - help="specify which view to start in (default = 1)", + help="specify which view to start in", ) parser.add_argument("inp", metavar="input file", type=str, nargs=1) parser.add_argument( -- 2.39.2