From b82a3b469b1e4842aa41ee9bf58f8ca9f4b06990 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Thu, 9 Dec 2021 19:33:39 +0000 Subject: [PATCH] Backport: Improve docs for borg list --format (#6080) --- src/borg/archiver.py | 40 +++++++++++++++++++++++++++++++++++----- src/borg/helpers.py | 2 +- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 7d18f0110..5c7faae6c 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -3770,16 +3770,45 @@ class Archiver: .. man NOTES - The following keys are available for ``--format``: + The FORMAT specifier syntax + +++++++++++++++++++++++++++ + + The ``--format`` option uses python's `format string syntax + `_. + + Examples: + :: + + $ borg list --format '{archive}{NL}' /path/to/repo + ArchiveFoo + ArchiveBar + ... + + # {VAR:NUMBER} - pad to NUMBER columns. + # Strings are left-aligned, numbers are right-aligned. + # Note: time columns except ``isomtime``, ``isoctime`` and ``isoatime`` cannot be padded. + $ borg list --format '{archive:36} {time} [{id}]{NL}' /path/to/repo + ArchiveFoo Thu, 2021-12-09 10:22:28 [0b8e9a312bef3f2f6e2d0fc110c196827786c15eba0188738e81697a7fa3b274] + $ borg list --format '{mode} {user:6} {group:6} {size:8} {mtime} {path}{extra}{NL}' /path/to/repo::ArchiveFoo + -rw-rw-r-- user user 1024 Thu, 2021-12-09 10:22:17 file-foo + ... + + # {VAR:NUMBER} - pad to NUMBER columns right-aligned. + $ borg list --format '{mode} {user:>6} {group:>6} {size:<8} {mtime} {path}{extra}{NL}' /path/to/repo::ArchiveFoo + -rw-rw-r-- user user 1024 Thu, 2021-12-09 10:22:17 file-foo + ... + + The following keys are always available: """) + BaseFormatter.keys_help() + textwrap.dedent(""" - Keys for listing repository archives: + Keys available only when listing archives in a repository: """) + ArchiveFormatter.keys_help() + textwrap.dedent(""" - Keys for listing archive files: + Keys available only when listing files in an archive: """) + ItemFormatter.keys_help() subparser = subparsers.add_parser('list', parents=[common_parser], add_help=False, @@ -3791,8 +3820,9 @@ class Archiver: subparser.add_argument('--short', dest='short', action='store_true', help='only print file/directory names, nothing else') subparser.add_argument('--format', '--list-format', metavar='FORMAT', dest='format', - help='specify format for file listing ' - '(default: "{mode} {user:6} {group:6} {size:8d} {mtime} {path}{extra}{NL}")') + help='specify format for file or archive listing ' + '(default for files: "{mode} {user:6} {group:6} {size:8} {mtime} {path}{extra}{NL}"; ' + 'for archives: "{archive:<36} {time} [{id}]{NL}")') subparser.add_argument('--json', action='store_true', help='Only valid for listing repository contents. Format output as JSON. ' 'The form of ``--format`` is ignored, ' diff --git a/src/borg/helpers.py b/src/borg/helpers.py index 5af7650cd..4f9b60bc6 100644 --- a/src/borg/helpers.py +++ b/src/borg/helpers.py @@ -1777,7 +1777,7 @@ class BaseFormatter: def keys_help(): return "- NEWLINE: OS dependent line separator\n" \ "- NL: alias of NEWLINE\n" \ - "- NUL: NUL character for creating print0 / xargs -0 like output, see barchive/bpath\n" \ + "- NUL: NUL character for creating print0 / xargs -0 like output, see barchive and bpath keys below\n" \ "- SPACE\n" \ "- TAB\n" \ "- CR\n" \