Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/borg/archiver/list_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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"
)
Expand Down
8 changes: 8 additions & 0 deletions src/borg/testsuite/archiver/list_cmd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading