Show More
@@ -598,13 +598,19 b' class ArgParseConfigLoader(CommandLineConfigLoader):' | |||
|
598 | 598 | def _convert_to_config(self): |
|
599 | 599 | """self.parsed_data->self.config""" |
|
600 | 600 | for k, v in vars(self.parsed_data).iteritems(): |
|
601 | self._exec_config_str(k, v) | |
|
601 | exec "self.config.%s = v"%k in locals(), globals() | |
|
602 | 602 | |
|
603 | 603 | class KVArgParseConfigLoader(ArgParseConfigLoader): |
|
604 | 604 | """A config loader that loads aliases and flags with argparse, |
|
605 | 605 | but will use KVLoader for the rest. This allows better parsing |
|
606 | 606 | of common args, such as `ipython -c 'print 5'`, but still gets |
|
607 | 607 | arbitrary config with `ipython --InteractiveShell.use_readline=False`""" |
|
608 | ||
|
609 | def _convert_to_config(self): | |
|
610 | """self.parsed_data->self.config""" | |
|
611 | for k, v in vars(self.parsed_data).iteritems(): | |
|
612 | self._exec_config_str(k, v) | |
|
613 | ||
|
608 | 614 | def _add_arguments(self, aliases=None, flags=None): |
|
609 | 615 | self.alias_flags = {} |
|
610 | 616 | # print aliases, flags |
@@ -651,10 +657,10 b' class KVArgParseConfigLoader(ArgParseConfigLoader):' | |||
|
651 | 657 | self._exec_config_str(k, v) |
|
652 | 658 | |
|
653 | 659 | for subc in subcs: |
|
654 |
self. |
|
|
660 | self._load_flag(subc) | |
|
655 | 661 | |
|
656 | 662 | if self.extra_args: |
|
657 | 663 | sub_parser = KeyValueConfigLoader() |
|
658 | 664 | sub_parser.load_config(self.extra_args) |
|
659 |
self.config. |
|
|
665 | self.config._merge(sub_parser.config) | |
|
660 | 666 | self.extra_args = sub_parser.extra_args |
@@ -70,7 +70,7 b' class TestPyFileCL(TestCase):' | |||
|
70 | 70 | self.assertEquals(config.D.C.value, 'hi there') |
|
71 | 71 | |
|
72 | 72 | class MyLoader1(ArgParseConfigLoader): |
|
73 | def _add_arguments(self): | |
|
73 | def _add_arguments(self, aliases=None, flags=None): | |
|
74 | 74 | p = self.parser |
|
75 | 75 | p.add_argument('-f', '--foo', dest='Global.foo', type=str) |
|
76 | 76 | p.add_argument('-b', dest='MyClass.bar', type=int) |
@@ -78,7 +78,7 b' class MyLoader1(ArgParseConfigLoader):' | |||
|
78 | 78 | p.add_argument('Global.bam', type=str) |
|
79 | 79 | |
|
80 | 80 | class MyLoader2(ArgParseConfigLoader): |
|
81 | def _add_arguments(self): | |
|
81 | def _add_arguments(self, aliases=None, flags=None): | |
|
82 | 82 | subparsers = self.parser.add_subparsers(dest='subparser_name') |
|
83 | 83 | subparser1 = subparsers.add_parser('1') |
|
84 | 84 | subparser1.add_argument('-x',dest='Global.x') |
General Comments 0
You need to be logged in to leave comments.
Login now