diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 386410a090..b478b2443a 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -1839,7 +1839,7 @@ def _raw_main(args, lib=None): ): from beets.ui.commands import config_edit - return config_edit() + return config_edit(options) test_lib = bool(lib) subcommands, plugins, lib = _setup(options, lib) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 99aa04f0ac..66faa0b6ec 100755 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -2351,7 +2351,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: @@ -2362,11 +2365,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 = util.editor_command() try: if not os.path.isfile(path): diff --git a/docs/changelog.rst b/docs/changelog.rst index 88d87e32f0..401640f618 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -49,6 +49,9 @@ Bug fixes: * :ref:`query-sort`: Fix a bug that would raise an exception when sorting on a non-string field that is not populated in all items. :bug:`5512` +* Running `beet --config config -e` now edits `` rather than + the default config path. + :bug:`5652` * :doc:`plugins/lastgenre`: Fix track-level genre handling. Now when an album-level genre is set already, single tracks don't fall back to the album's genre and request their own last.fm genre. Also log messages regarding what's been diff --git a/test/test_config_command.py b/test/test_config_command.py index b68c4f0427..c81b143ec4 100644 --- a/test/test_config_command.py +++ b/test/test_config_command.py @@ -128,3 +128,15 @@ 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): + alt_config_path = os.path.join( + self.temp_dir.decode(), "alt_config.yaml" + ) + with open(self.config_path, "w") as file: + file.write("option: alt value\n") + + os.environ["EDITOR"] = "myeditor" + with patch("os.execlp") as execlp: + self.run_command("--config", alt_config_path, "config", "-e") + execlp.assert_called_once_with("myeditor", "myeditor", alt_config_path)