diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index cf2162337c..294b466d6c 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -1601,7 +1601,7 @@ def parse_csl_callback( ): from beets.ui.commands.config import config_edit - return config_edit() + return config_edit(options) test_lib = bool(lib) subcommands, lib = _setup(options, lib) diff --git a/beets/ui/commands/config.py b/beets/ui/commands/config.py index 3581c66472..15d5713246 100644 --- a/beets/ui/commands/config.py +++ b/beets/ui/commands/config.py @@ -30,7 +30,10 @@ def config_func(lib, opts, args): # Open in editor. elif opts.edit: - config_edit() + # Note: This branch *should* be unreachable + # since the normal flow should be short-circuited + # by the special case in ui._raw_main + config_edit(opts) # Dump configuration. else: @@ -41,11 +44,11 @@ def config_func(lib, opts, args): print("Empty configuration") -def config_edit(): +def config_edit(cli_options): """Open a program to edit the user configuration. An empty config file is created if no existing config file exists. """ - path = config.user_config_path() + path = cli_options.config or config.user_config_path() editor = editor_command() try: if not os.path.isfile(path): diff --git a/docs/changelog.rst b/docs/changelog.rst index fbb7573f55..64f69b7922 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -29,6 +29,8 @@ Bug fixes: audio-features endpoint, the plugin logs a warning once and skips audio features for all remaining tracks in the session, avoiding unnecessary API calls and rate limit exhaustion. +- Running `beet --config config -e` now edits `` rather than + the default config path. :bug:`5652` - :doc:`plugins/lyrics`: Accepts strings for lyrics sources (previously only accepted a list of strings). :bug:`5962` diff --git a/test/ui/commands/test_config.py b/test/ui/commands/test_config.py index b68c4f0427..c1215ef43e 100644 --- a/test/ui/commands/test_config.py +++ b/test/ui/commands/test_config.py @@ -128,3 +128,11 @@ def test_edit_invalid_config_file(self): with patch("os.execlp") as execlp: self.run_command("config", "-e") execlp.assert_called_once_with("myeditor", "myeditor", self.config_path) + + def test_edit_config_with_custom_config_path(self): + os.environ["EDITOR"] = "myeditor" + with patch("os.execlp") as execlp: + self.run_command("--config", self.cli_config_path, "config", "-e") + execlp.assert_called_once_with( + "myeditor", "myeditor", self.cli_config_path + )