Merge pull request #6108 from sophie-h/sophie-h/list-command-line

list: Add command_line to format keys
This commit is contained in:
TW 2022-01-22 20:16:41 +01:00 committed by GitHub
commit 5edc773488
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -1148,7 +1148,7 @@ _borg_format_keys() {
local repo_or_arch=${(Q)1}
local -a keys=( NEWLINE NL NUL SPACE TAB CR LF )
local -a repository_keys=( archive name barchive comment bcomment id start time end hostname username )
local -a repository_keys=( archive name barchive comment bcomment id start time end command_line hostname username )
local -a archive_keys=( type mode uid gid user group path bpath source linktarget flags size csize dsize dcsize
num_chunks unique_chunks mtime ctime atime isomtime isoctime isoatime blake2b blake2s md5 sha1 sha224 sha256 sha384
sha3_224 sha3_256 sha3_384 sha3_512 sha512 shake_128 shake_256 archiveid archivename extra health )

View File

@ -4,6 +4,7 @@ import json
import os
import os.path
import re
import shlex
import socket
import stat
import uuid
@ -567,13 +568,14 @@ class ArchiveFormatter(BaseFormatter):
'start': 'time (start) of creation of the archive',
'time': 'alias of "start"',
'end': 'time (end) of creation of the archive',
'command_line': 'command line which was used to create the archive',
'id': 'internal ID of the archive',
'hostname': 'hostname of host on which this archive was created',
'username': 'username of user who created this archive',
}
KEY_GROUPS = (
('archive', 'name', 'barchive', 'comment', 'bcomment', 'id'),
('start', 'time', 'end'),
('start', 'time', 'end', 'command_line'),
('hostname', 'username'),
)
@ -624,6 +626,7 @@ class ArchiveFormatter(BaseFormatter):
'comment': partial(self.get_meta, 'comment', rs=True),
'bcomment': partial(self.get_meta, 'comment', rs=False),
'end': self.get_ts_end,
'command_line': self.get_cmdline,
}
self.used_call_keys = set(self.call_keys) & self.format_keys
if self.json:
@ -664,6 +667,13 @@ class ArchiveFormatter(BaseFormatter):
value = self.archive.metadata.get(key, '')
return remove_surrogates(value) if rs else value
def get_cmdline(self):
cmdline = map(remove_surrogates, self.archive.metadata.get('cmdline', []))
if self.json:
return list(cmdline)
else:
return ' '.join(map(shlex.quote, cmdline))
def get_ts_end(self):
return self.format_time(self.archive.ts_end)