diff --git a/src/borg/archiver/_common.py b/src/borg/archiver/_common.py index 8daaeadcd..f1d33ec80 100644 --- a/src/borg/archiver/_common.py +++ b/src/borg/archiver/_common.py @@ -9,6 +9,7 @@ from ..cache import Cache, assert_secure from ..helpers import Error from ..helpers import SortBySpec, positive_int_validator, location_validator, Location, relative_time_marker_validator +from ..helpers import Highlander from ..helpers.nanorst import rst_to_terminal from ..manifest import Manifest, AI_HUMAN_SORT_KEYS from ..patterns import PatternMatcher @@ -246,20 +247,6 @@ def wrapper(self, args, repository, manifest, **kwargs): return wrapper -class Highlander(argparse.Action): - """make sure some option is only given once""" - - def __init__(self, *args, **kwargs): - self.__called = False - super().__init__(*args, **kwargs) - - def __call__(self, parser, namespace, values, option_string=None): - if self.__called: - raise argparse.ArgumentError(self, "There can be only one.") - self.__called = True - setattr(namespace, self.dest, values) - - # You can use :ref:`xyz` in the following usage pages. However, for plain-text view, # e.g. through "borg ... --help", define a substitution for the reference here. # It will replace the entire :ref:`foo` verbatim. diff --git a/src/borg/archiver/create_cmd.py b/src/borg/archiver/create_cmd.py index a791b091f..284a7a0c6 100644 --- a/src/borg/archiver/create_cmd.py +++ b/src/borg/archiver/create_cmd.py @@ -767,7 +767,7 @@ def build_parser_create(self, subparsers, common_parser, mid_common_parser): metavar="NAME", dest="stdin_name", default="stdin", - action=MakePathSafeAction, # MakePathSafeAction maybe should subclass from Highlander. + action=MakePathSafeAction, help="use NAME in archive for stdin data (default: %(default)r)", ) subparser.add_argument( diff --git a/src/borg/helpers/__init__.py b/src/borg/helpers/__init__.py index 7a83a44d8..7556af23a 100644 --- a/src/borg/helpers/__init__.py +++ b/src/borg/helpers/__init__.py @@ -31,7 +31,7 @@ from .parseformat import BaseFormatter, ArchiveFormatter, ItemFormatter, file_status from .parseformat import swidth_slice, ellipsis_truncate from .parseformat import BorgJsonEncoder, basic_json_data, json_print, json_dump, prepare_dump_dict -from .parseformat import MakePathSafeAction +from .parseformat import Highlander, MakePathSafeAction from .process import daemonize, daemonizing from .process import signal_handler, raising_signal_handler, sig_int, ignore_sigint, SigHup, SigTerm from .process import popen_with_error_handling, is_terminal, prepare_subprocess_env, create_filter_process diff --git a/src/borg/helpers/parseformat.py b/src/borg/helpers/parseformat.py index ede705477..e69e514bb 100644 --- a/src/borg/helpers/parseformat.py +++ b/src/borg/helpers/parseformat.py @@ -1149,7 +1149,21 @@ def decode(d): return decode(d) -class MakePathSafeAction(argparse.Action): +class Highlander(argparse.Action): + """make sure some option is only given once""" + + def __init__(self, *args, **kwargs): + self.__called = False + super().__init__(*args, **kwargs) + + def __call__(self, parser, namespace, values, option_string=None): + if self.__called: + raise argparse.ArgumentError(self, "There can be only one.") + self.__called = True + setattr(namespace, self.dest, values) + + +class MakePathSafeAction(Highlander): def __call__(self, parser, namespace, path, option_string=None): try: sanitized_path = make_path_safe(path)