Skip to content

Commit

Permalink
Fix for #1274, allow library to be specified in config.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Nov 13, 2023
1 parent 34f815c commit 16776f8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
13 changes: 12 additions & 1 deletion osxphotos/cli/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ def export(

# config expects --verbose to be named "verbose" not "verbose_flag"
locals_["verbose"] = verbose_flag
locals_["library"] = None # synynom for --db
del locals_["verbose_flag"]

# NOTE: because of the way ConfigOptions works, Click options must not
Expand Down Expand Up @@ -1086,6 +1087,14 @@ def export(
)
sys.exit(1)

if cfg.library and cfg.db:
# library & db are synonyms but library takes precedence over db
# warn user if both options are used
rich_click_echo(
f"[warning]:warning-emoji: both --db and --library were specified; --library will be used ({cfg.library}) ",
err=True,
)

# re-set the local vars to the corresponding config value
# this isn't elegant but avoids having to rewrite this function to use cfg.varname for every parameter
# the query options appear to be unaccessed but they are used below by query_options_from_kwargs
Expand All @@ -1109,7 +1118,9 @@ def export(
convert_to_jpeg = cfg.convert_to_jpeg
crash_after = cfg.crash_after
current_name = cfg.current_name
db = cfg.db
db = (
cfg.library or cfg.db
) # if both db and library are specified, library takes precedence
deleted = cfg.deleted
deleted_only = cfg.deleted_only
description = cfg.description
Expand Down
26 changes: 26 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7692,6 +7692,32 @@ def test_save_load_config():
assert "Writing XMP sidecar" not in result.output


def test_load_config_library():
"""Test --load-config with libary option, #1274"""

runner = CliRunner()
cwd = os.getcwd()
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
with open("test.toml", "w") as fd:
fd.write("[export]\n")
fd.write(f'library = "{os.path.join(cwd, CLI_PHOTOS_DB)}"\n')

# test load config file
result = runner.invoke(
export,
[
".",
"--verbose",
"--load-config",
"test.toml",
],
)
assert result.exit_code == 0
assert "Loaded options from file" in result.output
assert "Processed" in result.output


def test_config_only():
"""test --save-config, --config-only"""

Expand Down

0 comments on commit 16776f8

Please sign in to comment.