Commits

Anonymous committed 77fabfe Draft Merge

Merge

Comments (0)

Files changed (3)

argparse_config.src/README.rst

 in the config, just like the commandline::
 
     [default]
-    verbose:
+    verbose
 
-is the equivalent of ``--verbose``.
+is the equivalent of ``--verbose``. Either `verbose:` or `verbose` will work,
+but (watch out!) `verbose: a-value` doesn't do anything different to `verbose`.
 
 How does it work?
 -----------------

argparse_config.src/argparse_config/__init__.py

 __version__ = '0.4a4'
 
 def read_config(arg_parser, filename):
-    config_parser = ConfigParser.SafeConfigParser()
+    config_parser = ConfigParser.SafeConfigParser(allow_no_value=True)
     config_parser.read([filename])
     set_defaults(arg_parser, config_parser)
 

argparse_config.src/argparse_config/tests/__init__.py

         @functools.wraps(f)
         def wrapper(self):
             config_file = textwrap.dedent(f.__doc__.lstrip('\n'))
-            config_parser = SafeConfigParser()
+            config_parser = SafeConfigParser(allow_no_value=True)
             config_parser.readfp(StringIO(config_file))
             return f(self, config_parser)
         return wrapper
         inverted_flag: 1
         value_ignored_flag: ignored
         no_value_flag:
+        no_value_flag_without_colon
         """
         arg_parser = ArgumentParser()
         arg_parser.add_argument('--flag', action='store_const', const=True, default=False)
         arg_parser.add_argument('--unused-flag', action='store_const', const=True, default=False)
         arg_parser.add_argument('--value-ignored-flag', action='store_const', const='used', default=None)
         arg_parser.add_argument('--no-value-flag', action='store_const', const=True, default=False)
+        arg_parser.add_argument('--no-value-flag-without-colon', action='store_true')
 
         set_defaults(arg_parser, config_parser)
 
         parsed_args = arg_parser.parse_args([])
 
         self.assertEqual(parsed_args.flag, True)
-        self.assertEqual(parsed_args.inverted_flag, False, "Effect should be the same as commandline")
+        self.assertIs(parsed_args.inverted_flag, False, "Effect should be the same as commandline")
         self.assertEqual(parsed_args.value_ignored_flag, 'used', "Not what is in the config file")
         self.assertEqual(parsed_args.no_value_flag, True, "Indeed, no value in the config file is actually needed")
+        self.assertIs(parsed_args.no_value_flag_without_colon, True)
 
     @with_config_file()
     def test_store_true_false(self, config_parser):
         arg_parser.add_argument('--verbose', action='store_const', const=True)
         file_contents = textwrap.dedent("""
         [default]
-        verbose:
+        verbose
         """.lstrip('\n'))
         temp_file = tempfile.NamedTemporaryFile()
         with temp_file.file as f: