mirror of
https://github.com/borgbackup/borg.git
synced 2026-06-11 01:41:57 -04:00
use jsonargparse's PositiveInt
This commit is contained in:
parent
678df16bad
commit
cf6fd0769d
4 changed files with 6 additions and 13 deletions
|
|
@ -7,9 +7,9 @@ from ..archive import Archive
|
|||
from ..constants import * # NOQA
|
||||
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 SortBySpec, location_validator, Location, relative_time_marker_validator
|
||||
from ..helpers import Highlander, octal_int
|
||||
from ..helpers.argparsing import SUPPRESS
|
||||
from ..helpers.argparsing import SUPPRESS, PositiveInt
|
||||
from ..helpers.nanorst import rst_to_terminal
|
||||
from ..manifest import Manifest, AI_HUMAN_SORT_KEYS
|
||||
from ..patterns import PatternMatcher
|
||||
|
|
@ -375,7 +375,7 @@ def define_archive_filters_group(
|
|||
"--first",
|
||||
metavar="N",
|
||||
dest="first",
|
||||
type=positive_int_validator,
|
||||
type=PositiveInt,
|
||||
action=Highlander,
|
||||
help="consider the first N archives after other filters are applied",
|
||||
)
|
||||
|
|
@ -383,7 +383,7 @@ def define_archive_filters_group(
|
|||
"--last",
|
||||
metavar="N",
|
||||
dest="last",
|
||||
type=positive_int_validator,
|
||||
type=PositiveInt,
|
||||
action=Highlander,
|
||||
help="consider the last N archives after other filters are applied",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ from .misc import sysinfo, log_multi, consume
|
|||
from .misc import ChunkIteratorFileWrapper, open_item, chunkit, iter_separated, ErrorIgnoringTextIOWrapper
|
||||
from .parseformat import octal_int, bin_to_hex, hex_to_bin, safe_encode, safe_decode
|
||||
from .parseformat import text_to_json, binary_to_json, remove_surrogates, join_cmd
|
||||
from .parseformat import eval_escapes, decode_dict, positive_int_validator, interval
|
||||
from .parseformat import eval_escapes, decode_dict, interval
|
||||
from .parseformat import (
|
||||
PathSpec,
|
||||
FilesystemPathSpec,
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ from argparse import Action, ArgumentError, ArgumentTypeError, RawDescriptionHel
|
|||
from jsonargparse import ArgumentParser as _ArgumentParser # we subclass that to add custom behavior
|
||||
from jsonargparse import Namespace, SUPPRESS, REMAINDER # noqa: F401
|
||||
from jsonargparse.typing import register_type # noqa: F401
|
||||
from jsonargparse.typing import PositiveInt # noqa: F401
|
||||
|
||||
# borg completion uses these private symbols, so we need to import them:
|
||||
from jsonargparse._actions import _ActionSubCommands # noqa: F401
|
||||
|
|
|
|||
|
|
@ -128,14 +128,6 @@ def decode_dict(d, keys, encoding="utf-8", errors="surrogateescape"):
|
|||
return d
|
||||
|
||||
|
||||
def positive_int_validator(value):
|
||||
"""argparse type for positive integers, N > 0."""
|
||||
int_value = int(value)
|
||||
if int_value <= 0:
|
||||
raise ArgumentTypeError("A positive integer is required: %s" % value)
|
||||
return int_value
|
||||
|
||||
|
||||
def interval(s):
|
||||
"""Convert a string representing a valid interval to a number of seconds."""
|
||||
if isinstance(s, int):
|
||||
|
|
|
|||
Loading…
Reference in a new issue