Fix broken "--override" action in Python 3.7 and below.
This commit is contained in:
parent
79bee755ee
commit
8aa7830f0d
1 changed files with 16 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
||||||
import collections
|
import collections
|
||||||
from argparse import ArgumentParser
|
from argparse import Action, ArgumentParser
|
||||||
|
|
||||||
from borgmatic.config import collect
|
from borgmatic.config import collect
|
||||||
|
|
||||||
|
@ -102,6 +102,20 @@ def parse_global_arguments(unparsed_arguments, top_level_parser, subparsers):
|
||||||
return top_level_parser.parse_args(remaining_arguments)
|
return top_level_parser.parse_args(remaining_arguments)
|
||||||
|
|
||||||
|
|
||||||
|
class Extend_action(Action):
|
||||||
|
'''
|
||||||
|
An argparse action to support Python 3.8's "extend" action in older versions of Python.
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
|
items = getattr(namespace, self.dest, None)
|
||||||
|
|
||||||
|
if items:
|
||||||
|
items.extend(values)
|
||||||
|
else:
|
||||||
|
setattr(namespace, self.dest, list(values))
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments(*unparsed_arguments):
|
def parse_arguments(*unparsed_arguments):
|
||||||
'''
|
'''
|
||||||
Given command-line arguments with which this script was invoked, parse the arguments and return
|
Given command-line arguments with which this script was invoked, parse the arguments and return
|
||||||
|
@ -111,6 +125,7 @@ def parse_arguments(*unparsed_arguments):
|
||||||
unexpanded_config_paths = collect.get_default_config_paths(expand_home=False)
|
unexpanded_config_paths = collect.get_default_config_paths(expand_home=False)
|
||||||
|
|
||||||
global_parser = ArgumentParser(add_help=False)
|
global_parser = ArgumentParser(add_help=False)
|
||||||
|
global_parser.register('action', 'extend', Extend_action)
|
||||||
global_group = global_parser.add_argument_group('global arguments')
|
global_group = global_parser.add_argument_group('global arguments')
|
||||||
|
|
||||||
global_group.add_argument(
|
global_group.add_argument(
|
||||||
|
|
Loading…
Reference in a new issue