Anonymous avatar Anonymous committed 86a20cd Draft

Tests passing: only show non-defaults works (up to testing).

Comments (0)

Files changed (1)

argparse_config.src/argparse_config/__init__.py

 def set_defaults(arg_parser, config_parser):
     _walk_parser(arg_parser, SetDefaults(config_parser=config_parser))
 
-def write_defaults(arg_parser, parsed_args):
-    action = WriteDefaults(parsed_args)
+def write_defaults(arg_parser, parsed_args, only_non_defaults=False):
+    action = WriteDefaults(parsed_args, only_non_defaults=only_non_defaults)
     _walk_parser(arg_parser, action)
     return action.contents
 
 
 class WriteDefaults(object):
 
-    def __init__(self, parsed_args):
+    def __init__(self, parsed_args, only_non_defaults=False):
         self.parsed_args = parsed_args
         self._contents = []
+        self._only_non_defaults = only_non_defaults
 
     def start_section(self, section_name):
         if self._contents:
         action_name = _convert_option_string(action_name[0])
 
         action_value = getattr(self.parsed_args, action.dest, None)
+        if self._only_non_defaults and action_value == action.default:
+            action_value = None
         if action_value is not None:
             if is_store_const:
                 self._contents.append(action_name)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.