Prechádzať zdrojové kódy

move toggle action to beginning of class so it can be reused

Antoine Beaupré 10 rokov pred
rodič
commit
a6f8436ceb
1 zmenil súbory, kde vykonal 14 pridanie a 13 odobranie
  1. 14 13
      borg/archiver.py

+ 14 - 13
borg/archiver.py

@@ -35,6 +35,20 @@ from .remote import RepositoryServer, RemoteRepository
 has_lchflags = hasattr(os, 'lchflags')
 has_lchflags = hasattr(os, 'lchflags')
 
 
 
 
+class ToggleAction(argparse.Action):
+    """argparse action to handle "toggle" flags easily
+
+    toggle flags are in the form of ``--foo``, ``--no-foo``.
+
+    the ``--no-foo`` argument still needs to be passed to the
+    ``add_argument()`` call, but it simplifies the ``--no``
+    detection.
+    """
+    def __call__(self, parser, ns, values, option):
+        """set the given flag to true unless ``--no`` is passed"""
+        setattr(ns, self.dest, not option.startswith('--no-'))
+
+
 class Archiver:
 class Archiver:
 
 
     def __init__(self, verbose=False):
     def __init__(self, verbose=False):
@@ -764,19 +778,6 @@ class Archiver:
         See the output of the "borg help patterns" command for more help on exclude patterns.
         See the output of the "borg help patterns" command for more help on exclude patterns.
         """)
         """)
 
 
-        class ToggleAction(argparse.Action):
-            """argparse action to handle "toggle" flags easily
-
-            toggle flags are in the form of ``--foo``, ``--no-foo``.
-
-            the ``--no-foo`` argument still needs to be passed to the
-            ``add_argument()`` call, but it simplifies the ``--no``
-            detection.
-            """
-            def __call__(self, parser, ns, values, option):
-                """set the given flag to true unless ``--no`` is passed"""
-                setattr(ns, self.dest, not option.startswith('--no-'))
-
         subparser = subparsers.add_parser('create', parents=[common_parser],
         subparser = subparsers.add_parser('create', parents=[common_parser],
                                           description=self.do_create.__doc__,
                                           description=self.do_create.__doc__,
                                           epilog=create_epilog,
                                           epilog=create_epilog,