diff --git a/src/borg/archiver/list_cmd.py b/src/borg/archiver/list_cmd.py index 98abd18c3e..b7c1cfac4c 100644 --- a/src/borg/archiver/list_cmd.py +++ b/src/borg/archiver/list_cmd.py @@ -6,7 +6,7 @@ from ..archive import Archive from ..cache import Cache from ..constants import * # NOQA -from ..helpers import ItemFormatter, BaseFormatter, archivename_validator, PathSpec +from ..helpers import ItemFormatter, BaseFormatter, archivename_validator, PathSpec, set_ec from ..helpers.argparsing import ArgumentParser from ..manifest import Manifest @@ -19,6 +19,14 @@ class ListMixIn: @with_repository(compatibility=(Manifest.Operation.READ,)) def do_list(self, args, repository, manifest): """List archive contents.""" + if args.name is None: + print( + "Error: borg list requires an archive NAME.\n" + "To list the archives in a repository, use: borg repo-list", + file=sys.stderr, + ) + set_ec(EXIT_ERROR) + return # omitting args.pattern_roots here, restricting to paths only by cli args.paths: matcher = build_matcher(args.patterns, args.paths) if args.format is not None: @@ -126,7 +134,9 @@ def build_parser_list(self, subparsers, common_parser, mid_common_parser): subparser.add_argument( "--depth", metavar="N", dest="depth", type=int, help="only list files up to the specified directory depth" ) - subparser.add_argument("name", metavar="NAME", type=archivename_validator, help="specify the archive name") + subparser.add_argument( + "name", metavar="NAME", nargs="?", default=None, type=archivename_validator, help="specify the archive name" + ) subparser.add_argument( "paths", metavar="PATH", nargs="*", type=PathSpec, help="paths to list; patterns are supported" ) diff --git a/src/borg/testsuite/archiver/list_cmd_test.py b/src/borg/testsuite/archiver/list_cmd_test.py index f9bb56e58a..3ce3796ed0 100644 --- a/src/borg/testsuite/archiver/list_cmd_test.py +++ b/src/borg/testsuite/archiver/list_cmd_test.py @@ -259,3 +259,11 @@ def test_fingerprint(archivers, request): # Even unmodified files should have different fingerprints because conditions_hash changed assert fingerprints1["input/file2"] != fingerprints5["input/file2"] + + +def test_list_without_archive_name_shows_helpful_error(archivers, request): + archiver = request.getfixturevalue(archivers) + cmd(archiver, "repo-create", RK_ENCRYPTION) + output = cmd(archiver, "list", exit_code=2) + assert "borg list requires an archive NAME" in output + assert "borg repo-list" in output