+ # Find all the parsers and subparsers
+ parsers = [main_parser]
+ parsers += [subparser for action in main_parser._actions
+ if isinstance(action, argparse._SubParsersAction)
+ for _, subparser in action.choices.items()]
+
+ # Collect the defaults from each parser
+ defaults = {}
+ for parser in parsers:
+ pdefs = parser.parse_known_args()[0]
+ defaults.update(vars(pdefs))
+
+ # Go through the settings and collect defaults