Warn user --glob-archives has been replaced with --match-archives

This commit is contained in:
John C. McCabe-Dansted 2026-05-18 18:35:45 +12:00
parent e998d6c4c5
commit c108b79c62
2 changed files with 47 additions and 0 deletions

View file

@ -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)

View file

@ -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):