Browse Source

Merge pull request #2716 from enkore/docs/metavar

docs: format metavars more accurately
enkore 8 years ago
parent
commit
109363236a
3 changed files with 24 additions and 12 deletions
  1. 0 6
      docs/usage/extract.rst
  2. 14 3
      setup.py
  3. 10 3
      src/borg/archiver.py

+ 0 - 6
docs/usage/extract.rst

@@ -21,9 +21,3 @@ Examples
 
     # Restore a raw device (must not be active/in use/mounted at that time)
     $ borg extract --stdout /path/to/repo::my-sdx | dd of=/dev/sdx bs=10M
-
-
-.. Note::
-
-    Currently, extract always writes into the current working directory ("."),
-    so make sure you ``cd`` to the right place before calling ``borg extract``.

+ 14 - 3
setup.py

@@ -203,6 +203,17 @@ with open('README.rst', 'r') as fd:
     long_description = re.compile(r'^\.\. highlight:: \w+$', re.M).sub('', long_description)
 
 
+def format_metavar(option):
+    if option.nargs in ('*', '...'):
+        return '[%s...]' % option.metavar
+    elif option.nargs == '?':
+        return '[%s]' % option.metavar
+    elif option.nargs is None:
+        return option.metavar
+    else:
+        raise ValueError('Can\'t format metavar %s, unknown nargs %s!' % (option.metavar, option.nargs))
+
+
 class build_usage(Command):
     description = "generate usage for each command"
 
@@ -284,7 +295,7 @@ class build_usage(Command):
         for option in parser._actions:
             if option.option_strings:
                 continue
-            fp.write(' ' + option.metavar)
+            fp.write(' ' + format_metavar(option))
         fp.write('\n\n')
 
     def write_options(self, parser, fp):
@@ -645,11 +656,11 @@ class build_man(Command):
 
     def write_usage(self, write, parser):
         if any(len(o.option_strings) for o in parser._actions):
-            write(' <options> ', end='')
+            write(' [options] ', end='')
         for option in parser._actions:
             if option.option_strings:
                 continue
-            write(option.metavar, end=' ')
+            write(format_metavar(option), end=' ')
 
     def write_options(self, write, parser):
         for group in parser._action_groups:

+ 10 - 3
src/borg/archiver.py

@@ -2893,6 +2893,11 @@ class Archiver:
 
         ``--progress`` can be slower than no progress display, since it makes one additional
         pass over the archive metadata.
+
+        .. note::
+
+            Currently, extract always writes into the current working directory ("."),
+            so make sure you ``cd`` to the right place before calling ``borg extract``.
         """)
         subparser = subparsers.add_parser('extract', parents=[common_parser], add_help=False,
                                           description=self.do_extract.__doc__,
@@ -3591,9 +3596,11 @@ class Archiver:
         for its termination, release the lock and return the user command's return
         code as borg's return code.
 
-        Note: if you copy a repository with the lock held, the lock will be present in
-              the copy, obviously. Thus, before using borg on the copy, you need to
-              use "borg break-lock" on it.
+        .. note::
+
+            If you copy a repository with the lock held, the lock will be present in
+            the copy, obviously. Thus, before using borg on the copy, you need to
+            use "borg break-lock" on it.
         """)
         subparser = subparsers.add_parser('with-lock', parents=[common_parser], add_help=False,
                                           description=self.do_with_lock.__doc__,