@@ -95,6 +95,16 @@ def get(self, name, default=None):
9595 else :
9696 return default
9797
98+ def get_matching (self , regexs , only_enabled ):
99+ """Get all symbols matching one of the regexs."""
100+ if not regexs :
101+ return
102+ regex = re .compile ('|' .join (regexs ))
103+ for setting in self .settings .values ():
104+ if regex .search (setting .name ):
105+ if setting .active or not only_enabled :
106+ yield setting .name
107+
98108 def __setitem__ (self , name , value ):
99109 """If name is known, set its value.
100110
@@ -353,6 +363,7 @@ def add_adapter(self, name, function, description):
353363 subparser .set_defaults (adapter = function )
354364
355365 def _common_parser_options (self , default_file_path ):
366+ # pylint: disable=too-many-branches
356367 """Common parser options for config manipulation tool."""
357368
358369 self .parser .add_argument (
@@ -392,12 +403,22 @@ def _common_parser_options(self, default_file_path):
392403 'unset-all' ,
393404 help = """Comment out all #define whose name contains a match for REGEX.""" )
394405 parser_unset_all .add_argument ('regexs' , metavar = 'REGEX' , nargs = '*' )
406+ parser_get_all = self .subparsers .add_parser (
407+ 'get-all' ,
408+ help = """Get all #define whose name contains a match for REGEX.""" )
409+ parser_get_all .add_argument ('regexs' , metavar = 'REGEX' , nargs = '*' )
410+ parser_get_all_enabled = self .subparsers .add_parser (
411+ 'get-all-enabled' ,
412+ help = """Get all enabled #define whose name contains a match for REGEX.""" )
413+ parser_get_all_enabled .add_argument ('regexs' , metavar = 'REGEX' , nargs = '*' )
414+
395415
396416 def custom_parser_options (self ):
397417 """Adds custom options for the parser. Designed for overridden by descendant."""
398418 pass
399419
400420 def main (self ):
421+ # pylint: disable=too-many-branches
401422 """Common main fuction for config manipulation tool."""
402423
403424 args = self .args
@@ -412,6 +433,12 @@ def main(self):
412433 if value :
413434 sys .stdout .write (value + '\n ' )
414435 return 0 if args .symbol in config else 1
436+ elif args .command == 'get-all' :
437+ match_list = config .get_matching (args .regexs , False )
438+ sys .stdout .write ("\n " .join (match_list ))
439+ elif args .command == 'get-all-enabled' :
440+ match_list = config .get_matching (args .regexs , True )
441+ sys .stdout .write ("\n " .join (match_list ))
415442 elif args .command == 'set' :
416443 if not args .force and args .symbol not in config .settings :
417444 sys .stderr .write (
0 commit comments