Przeglądaj źródła

Don't show sub-command in borgfs help (fixes #3287)

Milkey Mouse 7 lat temu
rodzic
commit
6f2bc44588
1 zmienionych plików z 61 dodań i 56 usunięć
  1. 61 56
      src/borg/archiver.py

+ 61 - 56
src/borg/archiver.py

@@ -2266,7 +2266,67 @@ class Archiver:
         mid_common_parser.set_defaults(paths=[], patterns=[])
         mid_common_parser.set_defaults(paths=[], patterns=[])
         parser.common_options.add_common_group(mid_common_parser, '_midcommand')
         parser.common_options.add_common_group(mid_common_parser, '_midcommand')
 
 
-        subparsers = parser.add_subparsers(title='required arguments', metavar='<command>')
+        mount_epilog = process_epilog("""
+        This command mounts an archive as a FUSE filesystem. This can be useful for
+        browsing an archive or restoring individual files. Unless the ``--foreground``
+        option is given the command will run in the background until the filesystem
+        is ``umounted``.
+
+        The command ``borgfs`` provides a wrapper for ``borg mount``. This can also be
+        used in fstab entries:
+        ``/path/to/repo /mnt/point fuse.borgfs defaults,noauto 0 0``
+
+        To allow a regular user to use fstab entries, add the ``user`` option:
+        ``/path/to/repo /mnt/point fuse.borgfs defaults,noauto,user 0 0``
+
+        For mount options, see the fuse(8) manual page. Additional mount options
+        supported by borg:
+
+        - versions: when used with a repository mount, this gives a merged, versioned
+          view of the files in the archives. EXPERIMENTAL, layout may change in future.
+        - allow_damaged_files: by default damaged files (where missing chunks were
+          replaced with runs of zeros by borg check ``--repair``) are not readable and
+          return EIO (I/O error). Set this option to read such files.
+
+        The BORG_MOUNT_DATA_CACHE_ENTRIES environment variable is meant for advanced users
+        to tweak the performance. It sets the number of cached data chunks; additional
+        memory usage can be up to ~8 MiB times this number. The default is the number
+        of CPU cores.
+
+        When the daemonized process receives a signal or crashes, it does not unmount.
+        Unmounting in these cases could cause an active rsync or similar process
+        to unintentionally delete data.
+
+        When running in the foreground ^C/SIGINT unmounts cleanly, but other
+        signals or crashes do not.
+        """)
+
+        if parser.prog == 'borgfs':
+            parser.description = self.do_mount.__doc__
+            parser.epilog = mount_epilog
+            parser.formatter_class = argparse.RawDescriptionHelpFormatter
+            parser.help = 'mount repository'
+            subparser = parser
+        else:
+            subparsers = parser.add_subparsers(title='required arguments', metavar='<command>')
+            subparser = subparsers.add_parser('mount', parents=[common_parser], add_help=False,
+                                            description=self.do_mount.__doc__,
+                                            epilog=mount_epilog,
+                                            formatter_class=argparse.RawDescriptionHelpFormatter,
+                                            help='mount repository')
+        subparser.set_defaults(func=self.do_mount)
+        subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE', type=location_validator(),
+                            help='repository/archive to mount')
+        subparser.add_argument('mountpoint', metavar='MOUNTPOINT', type=str,
+                            help='where to mount filesystem')
+        subparser.add_argument('-f', '--foreground', dest='foreground',
+                            action='store_true',
+                            help='stay in foreground, do not daemonize')
+        subparser.add_argument('-o', dest='options', type=str,
+                            help='Extra mount options')
+        define_archive_filters_group(subparser)
+        if parser.prog == 'borgfs':
+            return parser
 
 
         serve_epilog = process_epilog("""
         serve_epilog = process_epilog("""
         This command starts a repository server process. This command is usually not used manually.
         This command starts a repository server process. This command is usually not used manually.
@@ -3035,57 +3095,6 @@ class Archiver:
         define_archive_filters_group(subparser)
         define_archive_filters_group(subparser)
         define_exclusion_group(subparser)
         define_exclusion_group(subparser)
 
 
-        mount_epilog = process_epilog("""
-        This command mounts an archive as a FUSE filesystem. This can be useful for
-        browsing an archive or restoring individual files. Unless the ``--foreground``
-        option is given the command will run in the background until the filesystem
-        is ``umounted``.
-
-        The command ``borgfs`` provides a wrapper for ``borg mount``. This can also be
-        used in fstab entries:
-        ``/path/to/repo /mnt/point fuse.borgfs defaults,noauto 0 0``
-
-        To allow a regular user to use fstab entries, add the ``user`` option:
-        ``/path/to/repo /mnt/point fuse.borgfs defaults,noauto,user 0 0``
-
-        For mount options, see the fuse(8) manual page. Additional mount options
-        supported by borg:
-
-        - versions: when used with a repository mount, this gives a merged, versioned
-          view of the files in the archives. EXPERIMENTAL, layout may change in future.
-        - allow_damaged_files: by default damaged files (where missing chunks were
-          replaced with runs of zeros by borg check ``--repair``) are not readable and
-          return EIO (I/O error). Set this option to read such files.
-
-        The BORG_MOUNT_DATA_CACHE_ENTRIES environment variable is meant for advanced users
-        to tweak the performance. It sets the number of cached data chunks; additional
-        memory usage can be up to ~8 MiB times this number. The default is the number
-        of CPU cores.
-
-        When the daemonized process receives a signal or crashes, it does not unmount.
-        Unmounting in these cases could cause an active rsync or similar process
-        to unintentionally delete data.
-
-        When running in the foreground ^C/SIGINT unmounts cleanly, but other
-        signals or crashes do not.
-        """)
-        subparser = subparsers.add_parser('mount', parents=[common_parser], add_help=False,
-                                          description=self.do_mount.__doc__,
-                                          epilog=mount_epilog,
-                                          formatter_class=argparse.RawDescriptionHelpFormatter,
-                                          help='mount repository')
-        subparser.set_defaults(func=self.do_mount)
-        subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE', type=location_validator(),
-                               help='repository/archive to mount')
-        subparser.add_argument('mountpoint', metavar='MOUNTPOINT', type=str,
-                               help='where to mount filesystem')
-        subparser.add_argument('-f', '--foreground', dest='foreground',
-                               action='store_true',
-                               help='stay in foreground, do not daemonize')
-        subparser.add_argument('-o', dest='options', type=str,
-                               help='Extra mount options')
-        define_archive_filters_group(subparser)
-
         umount_epilog = process_epilog("""
         umount_epilog = process_epilog("""
         This command un-mounts a FUSE filesystem that was mounted with ``borg mount``.
         This command un-mounts a FUSE filesystem that was mounted with ``borg mount``.
 
 
@@ -3827,10 +3836,6 @@ def sig_trace_handler(sig_no, stack):  # pragma: no cover
 
 
 
 
 def main():  # pragma: no cover
 def main():  # pragma: no cover
-    # provide 'borg mount' behaviour when the main script/executable is named borgfs
-    if os.path.basename(sys.argv[0]) == "borgfs":
-        sys.argv.insert(1, "mount")
-
     # Make sure stdout and stderr have errors='replace' to avoid unicode
     # Make sure stdout and stderr have errors='replace' to avoid unicode
     # issues when print()-ing unicode file names
     # issues when print()-ing unicode file names
     sys.stdout = ErrorIgnoringTextIOWrapper(sys.stdout.buffer, sys.stdout.encoding, 'replace', line_buffering=True)
     sys.stdout = ErrorIgnoringTextIOWrapper(sys.stdout.buffer, sys.stdout.encoding, 'replace', line_buffering=True)