diff --git a/src/borg/archiver/__init__.py b/src/borg/archiver/__init__.py index 16b2c6372..69bd1c961 100644 --- a/src/borg/archiver/__init__.py +++ b/src/borg/archiver/__init__.py @@ -363,6 +363,27 @@ class Archiver( ] ) + def _legacy_option_hint(self, args, parser): + command_index = self._first_toplevel_command_index(args, parser) + if command_index is None or args[command_index] != "list": + return None + + if not any(arg == "--glob-archives" or arg.startswith("--glob-archives=") for arg in args[command_index + 1 :]): + return None + + prog = self.prog or "borg" + example = shlex.join([prog, "list", "ARCHIVE", "--match-archives", "sh:my*"]) + return "\n".join( + [ + "--glob-archives is a borg1 option and is not used in borg2.", + "Use --match-archives in borg2. It defaults to exact `id:` matching, " + "so use `sh:` for borg1-style globbing.", + "Example:", + example, + f"tip: For details of accepted options run: {prog} list --help", + ] + ) + def get_args(self, argv, cmd): """Usually just returns argv, except when dealing with an SSH forced command for borg serve.""" result = self.parse_args(argv[1:]) @@ -404,6 +425,9 @@ class Archiver( legacy_hint = self._legacy_command_hint(args, parser) if legacy_hint: parser.exit(EXIT_ERROR, legacy_hint + "\n") + legacy_hint = self._legacy_option_hint(args, parser) + if legacy_hint: + parser.exit(EXIT_ERROR, legacy_hint + "\n") args = parser.parse_args(args or ["-h"]) args = flatten_namespace(args) diff --git a/src/borg/testsuite/archiver/help_cmd_test.py b/src/borg/testsuite/archiver/help_cmd_test.py index 815372ff3..230af930b 100644 --- a/src/borg/testsuite/archiver/help_cmd_test.py +++ b/src/borg/testsuite/archiver/help_cmd_test.py @@ -62,6 +62,29 @@ def test_borg1_init_shows_repo_create_hint(archiver): assert "Use `borg help` to see the list of valid commands." in output +def test_borg1_glob_archives_shows_match_archives_hint(archiver): + ret, output = exec_cmd( + "--repo", + archiver.repository_location, + "list", + "--glob-archives", + "my*", + archiver=archiver.archiver, + fork=archiver.FORK_DEFAULT, + exe=archiver.EXE, + ) + + assert ret == 2 + assert "--glob-archives is a borg1 option and is not used in borg2." in output + assert ( + "Use --match-archives in borg2. It defaults to exact `id:` matching, " + "so use `sh:` for borg1-style globbing." in output + ) + assert "Example:" in output + assert "borg list ARCHIVE --match-archives 'sh:my*'" in output + assert "tip: For details of accepted options run: borg list --help" in output + + @pytest.mark.parametrize("command, parser", list(get_all_parsers().items())) def test_help_formatting(command, parser): if isinstance(parser.epilog, RstToTextLazy):