mirror of
https://github.com/borgbackup/borg.git
synced 2026-04-25 08:08:33 -04:00
import from jsonargparse: SUPPRESS, REMAINDER, NameSpace
This commit is contained in:
parent
e39d06ee98
commit
393b2cbc11
4 changed files with 13 additions and 12 deletions
|
|
@ -27,7 +27,7 @@ try:
|
|||
import signal
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from jsonargparse import ArgumentParser
|
||||
from jsonargparse import ArgumentParser, Namespace, SUPPRESS
|
||||
|
||||
from ..logger import create_logger, setup_logging
|
||||
|
||||
|
|
@ -268,14 +268,14 @@ class Archiver(
|
|||
# Note: We control all inputs.
|
||||
kwargs["help"] = kwargs["help"] % kwargs
|
||||
if not is_append:
|
||||
kwargs["default"] = argparse.SUPPRESS
|
||||
kwargs["default"] = SUPPRESS
|
||||
|
||||
common_group.add_argument(*args, **kwargs)
|
||||
|
||||
common_group = parser.add_argument_group("Common options")
|
||||
self.define_common_options(add_argument)
|
||||
|
||||
def resolve(self, args: argparse.Namespace): # Namespace has "in" but otherwise is not like a dict.
|
||||
def resolve(self, args: Namespace): # Namespace has "in" but otherwise is not like a dict.
|
||||
"""
|
||||
Resolve the multiple definitions of each common option to the final value.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import argparse
|
||||
import functools
|
||||
import os
|
||||
import textwrap
|
||||
|
||||
from jsonargparse import SUPPRESS
|
||||
|
||||
import borg
|
||||
from ..archive import Archive
|
||||
from ..constants import * # NOQA
|
||||
|
|
@ -269,8 +270,8 @@ def process_epilog(epilog):
|
|||
|
||||
|
||||
def define_exclude_and_patterns(add_option, *, tag_files=False, strip_components=False):
|
||||
add_option("--pattern-roots-internal", dest="pattern_roots", action="append", default=[], help=argparse.SUPPRESS)
|
||||
add_option("--patterns-internal", dest="patterns", action="append", default=[], help=argparse.SUPPRESS)
|
||||
add_option("--pattern-roots-internal", dest="pattern_roots", action="append", default=[], help=SUPPRESS)
|
||||
add_option("--patterns-internal", dest="patterns", action="append", default=[], help=SUPPRESS)
|
||||
add_option(
|
||||
"-e",
|
||||
"--exclude",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import argparse
|
||||
import subprocess
|
||||
|
||||
from jsonargparse import ArgumentParser
|
||||
from jsonargparse import ArgumentParser, REMAINDER
|
||||
|
||||
from ._common import with_repository
|
||||
from ..cache import Cache
|
||||
|
|
@ -86,4 +86,4 @@ class LocksMixIn:
|
|||
)
|
||||
subparsers.add_subcommand("with-lock", subparser, help="run a user command with the lock held")
|
||||
subparser.add_argument("command", metavar="COMMAND", help="command to run")
|
||||
subparser.add_argument("args", metavar="ARGS", nargs=argparse.REMAINDER, help="command arguments")
|
||||
subparser.add_argument("args", metavar="ARGS", nargs=REMAINDER, help="command arguments")
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import argparse
|
||||
from jsonargparse import Namespace
|
||||
from typing import Any
|
||||
|
||||
|
||||
def flatten_namespace(ns: Any) -> argparse.Namespace:
|
||||
def flatten_namespace(ns: Any) -> Namespace:
|
||||
"""
|
||||
Recursively flattens a nested namespace into a single-level namespace.
|
||||
JSONArgparse uses nested namespaces for subcommands, whereas borg's
|
||||
internal dispatch and logic expect a flat namespace.
|
||||
"""
|
||||
flat = argparse.Namespace()
|
||||
flat = Namespace()
|
||||
|
||||
# Extract the nested path of subcommands
|
||||
subcmds = []
|
||||
|
|
@ -25,7 +25,7 @@ def flatten_namespace(ns: Any) -> argparse.Namespace:
|
|||
vars(source).items() if hasattr(source, "__dict__") else source.items() if hasattr(source, "items") else []
|
||||
)
|
||||
for k, v in items:
|
||||
if isinstance(v, argparse.Namespace) or type(v).__name__ == "Namespace":
|
||||
if isinstance(v, Namespace) or type(v).__name__ == "Namespace":
|
||||
_flatten(v, target)
|
||||
else:
|
||||
if k != "subcommand" and not hasattr(target, k):
|
||||
|
|
|
|||
Loading…
Reference in a new issue