pass argument and fetch alt config file if specified

This commit is contained in:
samuelgregorovic 2021-07-02 20:06:52 +02:00
parent 89eb3d0193
commit 6f1362e80e
2 changed files with 23 additions and 7 deletions

View file

@ -36,17 +36,33 @@ def upgrade_config(config):
)
def load_or_install_jrnl():
"""
If jrnl is already installed, loads and returns a default config object.
If alternate config is specified via --config-file flag, it will be used.
Else, perform various prompts to install jrnl.
"""
def get_default_config():
config_path = (
get_config_path()
if os.path.exists(get_config_path())
else os.path.join(os.path.expanduser("~"), ".jrnl_config")
)
return config_path
def get_alt_config(alt_config):
if os.path.exists(alt_config):
return alt_config
else:
print(
"Alternate configuration file not found at path specified.", file=sys.stderr
)
print("Exiting.", file=sys.stderr)
sys.exit(1)
def load_or_install_jrnl(alt_config):
"""
If jrnl is already installed, loads and returns a default config object.
If alternate config is specified via --config-file flag, it will be used.
Else, perform various prompts to install jrnl.
"""
config_path = get_alt_config(alt_config) if alt_config else get_default_config()
if os.path.exists(config_path):
logging.debug("Reading configuration from file %s", config_path)

View file

@ -36,7 +36,7 @@ def run(args):
# Load the config, and extract journal name
try:
config = install.load_or_install_jrnl()
config = install.load_or_install_jrnl(args.config_file)
original_config = config.copy()
# Apply config overrides