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

This commit is contained in:
Antoine Beaupré 2015-11-20 15:01:29 -05:00
parent a40729f4f3
commit a6f8436ceb
1 changed files with 14 additions and 13 deletions

View File

@ -35,6 +35,20 @@ from .remote import RepositoryServer, RemoteRepository
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:
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.
""")
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],
description=self.do_create.__doc__,
epilog=create_epilog,