mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-18 12:08:31 +02:00
pass argument and fetch alt config file if specified
This commit is contained in:
parent
89eb3d0193
commit
6f1362e80e
2 changed files with 23 additions and 7 deletions
|
@ -36,17 +36,33 @@ def upgrade_config(config):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def load_or_install_jrnl():
|
def get_default_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 = (
|
config_path = (
|
||||||
get_config_path()
|
get_config_path()
|
||||||
if os.path.exists(get_config_path())
|
if os.path.exists(get_config_path())
|
||||||
else os.path.join(os.path.expanduser("~"), ".jrnl_config")
|
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):
|
if os.path.exists(config_path):
|
||||||
logging.debug("Reading configuration from file %s", config_path)
|
logging.debug("Reading configuration from file %s", config_path)
|
||||||
|
|
|
@ -36,7 +36,7 @@ def run(args):
|
||||||
|
|
||||||
# Load the config, and extract journal name
|
# Load the config, and extract journal name
|
||||||
try:
|
try:
|
||||||
config = install.load_or_install_jrnl()
|
config = install.load_or_install_jrnl(args.config_file)
|
||||||
original_config = config.copy()
|
original_config = config.copy()
|
||||||
|
|
||||||
# Apply config overrides
|
# Apply config overrides
|
||||||
|
|
Loading…
Add table
Reference in a new issue