Merge "Fix subparsers add_parser() regression"
This commit is contained in:
commit
eae8b3108d
@ -1469,8 +1469,8 @@ class _CachedArgumentParser(argparse.ArgumentParser):
|
||||
order.
|
||||
"""
|
||||
|
||||
def __init__(self, prog=None, usage=None):
|
||||
super(_CachedArgumentParser, self).__init__(prog, usage)
|
||||
def __init__(self, prog=None, usage=None, **kwargs):
|
||||
super(_CachedArgumentParser, self).__init__(prog, usage, **kwargs)
|
||||
self._args_cache = {}
|
||||
|
||||
def add_parser_argument(self, container, *args, **kwargs):
|
||||
|
@ -14,6 +14,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
@ -2627,6 +2628,21 @@ class SubCommandTestCase(BaseTestCase):
|
||||
self.assertEqual(self.conf.cmd.name, 'a')
|
||||
self.assertEqual(self.conf.cmd.bar, 10)
|
||||
|
||||
def test_sub_command_with_parent(self):
|
||||
def add_parsers(subparsers):
|
||||
parent = argparse.ArgumentParser(add_help=False)
|
||||
parent.add_argument('bar', type=int)
|
||||
subparsers.add_parser('a', parents=[parent])
|
||||
|
||||
self.conf.register_cli_opt(
|
||||
cfg.SubCommandOpt('cmd', handler=add_parsers))
|
||||
self.assertTrue(hasattr(self.conf, 'cmd'))
|
||||
self.conf(['a', '10'])
|
||||
self.assertTrue(hasattr(self.conf.cmd, 'name'))
|
||||
self.assertTrue(hasattr(self.conf.cmd, 'bar'))
|
||||
self.assertEqual(self.conf.cmd.name, 'a')
|
||||
self.assertEqual(self.conf.cmd.bar, 10)
|
||||
|
||||
def test_sub_command_with_dest(self):
|
||||
def add_parsers(subparsers):
|
||||
subparsers.add_parser('a')
|
||||
|
Loading…
x
Reference in New Issue
Block a user