浏览代码

ItemFormatter: group keys in help output

Marian Beermann 9 年之前
父节点
当前提交
343d84b427
共有 2 个文件被更改,包括 53 次插入32 次删除
  1. 26 10
      borg/helpers.py
  2. 27 22
      docs/usage/list.rst.inc

+ 26 - 10
borg/helpers.py

@@ -1128,16 +1128,27 @@ class ItemFormatter:
         'NL': os.linesep,
         'NL': os.linesep,
     }
     }
     KEY_DESCRIPTIONS = {
     KEY_DESCRIPTIONS = {
-        'NEWLINE': 'OS dependent line separator',
-        'NL': 'alias of NEWLINE',
-        'NUL': 'NUL character for creating print0 / xargs -0 like ouput, see bpath',
-        'csize': 'compressed size',
         'bpath': 'verbatim POSIX path, can contain any character except NUL',
         'bpath': 'verbatim POSIX path, can contain any character except NUL',
         'path': 'path interpreted as text (might be missing non-text characters, see bpath)',
         'path': 'path interpreted as text (might be missing non-text characters, see bpath)',
         'source': 'link target for links (identical to linktarget)',
         'source': 'link target for links (identical to linktarget)',
+        'extra': 'prepends {source} with " -> " for soft links and " link to " for hard links',
+
+        'csize': 'compressed size',
         'num_chunks': 'number of chunks in this file',
         'num_chunks': 'number of chunks in this file',
         'unique_chunks': 'number of unique chunks in this file',
         'unique_chunks': 'number of unique chunks in this file',
+
+        'NEWLINE': 'OS dependent line separator',
+        'NL': 'alias of NEWLINE',
+        'NUL': 'NUL character for creating print0 / xargs -0 like ouput, see bpath',
     }
     }
+    KEY_GROUPS = (
+        ('type', 'mode', 'uid', 'gid', 'user', 'group', 'path', 'bpath', 'source', 'linktarget'),
+        ('size', 'csize', 'num_chunks', 'unique_chunks'),
+        ('mtime', 'ctime', 'atime', 'isomtime', 'isoctime', 'isoatime'),
+        tuple(sorted(hashlib.algorithms_guaranteed)),
+        ('archiveid', 'archivename', 'extra'),
+        ('NEWLINE', 'NL', 'NUL', 'SPACE', 'TAB', 'CR', 'LF'),
+    )
 
 
     @classmethod
     @classmethod
     def available_keys(cls):
     def available_keys(cls):
@@ -1152,16 +1163,21 @@ class ItemFormatter:
         keys = []
         keys = []
         keys.extend(formatter.call_keys.keys())
         keys.extend(formatter.call_keys.keys())
         keys.extend(formatter.get_item_data(fake_item).keys())
         keys.extend(formatter.get_item_data(fake_item).keys())
-        return sorted(keys, key=lambda s: (s.isupper(), s))
+        return keys
 
 
     @classmethod
     @classmethod
     def keys_help(cls):
     def keys_help(cls):
         help = []
         help = []
-        for key in cls.available_keys():
-            text = " - " + key
-            if key in cls.KEY_DESCRIPTIONS:
-                text += ": " + cls.KEY_DESCRIPTIONS[key]
-            help.append(text)
+        keys = cls.available_keys()
+        for group in cls.KEY_GROUPS:
+            for key in group:
+                keys.remove(key)
+                text = " - " + key
+                if key in cls.KEY_DESCRIPTIONS:
+                    text += ": " + cls.KEY_DESCRIPTIONS[key]
+                help.append(text)
+            help.append("")
+        assert not keys, str(keys)
         return "\n".join(help)
         return "\n".join(help)
 
 
     def __init__(self, archive, format):
     def __init__(self, archive, format):

+ 27 - 22
docs/usage/list.rst.inc

@@ -51,39 +51,44 @@ See the "borg help patterns" command for more help on exclude patterns.
 
 
 The following keys are available for --format when listing files:
 The following keys are available for --format when listing files:
 
 
- - archiveid
- - archivename
- - atime
+ - type
+ - mode
+ - uid
+ - gid
+ - user
+ - group
+ - path: path interpreted as text (might be missing non-text characters, see bpath)
  - bpath: verbatim POSIX path, can contain any character except NUL
  - bpath: verbatim POSIX path, can contain any character except NUL
+ - source: link target for links (identical to linktarget)
+ - linktarget
+
+ - size
  - csize: compressed size
  - csize: compressed size
+ - num_chunks: number of chunks in this file
+ - unique_chunks: number of unique chunks in this file
+
+ - mtime
  - ctime
  - ctime
- - extra
- - gid
- - group
- - isoatime
- - isoctime
+ - atime
  - isomtime
  - isomtime
- - linktarget
+ - isoctime
+ - isoatime
+
  - md5
  - md5
- - mode
- - mtime
- - num_chunks: number of chunks in this file
- - path: path interpreted as text (might be missing non-text characters, see bpath)
  - sha1
  - sha1
  - sha224
  - sha224
  - sha256
  - sha256
  - sha384
  - sha384
  - sha512
  - sha512
- - size
- - source: link target for links (identical to linktarget)
- - type
- - uid
- - unique_chunks: number of unique chunks in this file
- - user
- - CR
- - LF
+
+ - archiveid
+ - archivename
+ - extra: prepends {source} with " -> " for soft links and " link to " for hard links
+
  - NEWLINE: OS dependent line separator
  - NEWLINE: OS dependent line separator
  - NL: alias of NEWLINE
  - NL: alias of NEWLINE
  - NUL: NUL character for creating print0 / xargs -0 like ouput, see bpath
  - NUL: NUL character for creating print0 / xargs -0 like ouput, see bpath
  - SPACE
  - SPACE
- - TAB
+ - TAB
+ - CR
+ - LF