Commits

anatoly techtonik  committed 332fe1b

Add hints about valid choices to error messages from option parser

  • Participants
  • Parent commits 95a5127

Comments (0)

Files changed (2)

File src/CHANGES.txt

   From Anatoly Techtonik:
     - Added ability to run scripts/scons.py directly from source checkout
     - Hide deprecated --debug={dtree,stree,tree} from --help output
+    - Error messages from option parser now include hints about valid choices
 
   From Juan Lang:
     - Fix WiX Tool to use .wixobj rather than .wxiobj for compiler output

File src/engine/SCons/Script/SConsOptions.py

     preserve_unknown_options = False
 
     def error(self, msg):
+        # overriden OptionValueError exception handler
         self.print_usage(sys.stderr)
-        sys.stderr.write("SCons error: %s\n" % msg)
+        sys.stderr.write("SCons Error: %s\n" % msg)
         sys.exit(2)
 
     def _process_long_opt(self, rargs, values):
                   action="store_true",
                   help="Print build actions for files from CacheDir.")
 
+    def opt_invalid(group, value, options):
+        errmsg  = "`%s' is not a valid %s option type, try:\n" % (value, group)
+        return errmsg + "    %s" % ", ".join(options)
+
     config_options = ["auto", "force" ,"cache"]
 
     def opt_config(option, opt, value, parser, c_options=config_options):
         if not value in c_options:
-            raise OptionValueError("Warning:  %s is not a valid config type" % value)
+            raise OptionValueError(opt_invalid('config', value, c_options))
         setattr(parser.values, option.dest, value)
     opt_config_help = "Controls Configure subsystem: %s." \
                       % ", ".join(config_options)
             t = (SCons.Warnings.DeprecatedDebugOptionsWarning, w)
             parser.values.delayed_warnings.append(t)
         else:
-            raise OptionValueError("Warning:  %s is not a valid debug type" % value)
+            raise OptionValueError(opt_invalid('debug', value, debug_options))
     opt_debug_help = "Print various types of debugging information: %s." \
                      % ", ".join(debug_options)
     op.add_option('--debug',
         try:
             diskcheck_value = diskcheck_convert(value)
         except ValueError, e:
-            raise OptionValueError("Warning: `%s' is not a valid diskcheck type" % e)
+            raise OptionValueError("`%s' is not a valid diskcheck type" % e)
         setattr(parser.values, option.dest, diskcheck_value)
 
     op.add_option('--diskcheck',
 
     def opt_duplicate(option, opt, value, parser):
         if not value in SCons.Node.FS.Valid_Duplicates:
-            raise OptionValueError("`%s' is not a valid duplication style." % value)
+            raise OptionValueError(opt_invalid('duplication', value,
+                                              SCons.Node.FS.Valid_Duplicates))
         setattr(parser.values, option.dest, value)
         # Set the duplicate style right away so it can affect linking
         # of SConscript files.
             elif o == 'status':
                 tp.status = True
             else:
-                raise OptionValueError("Warning:  %s is not a valid --tree option" % o)
+                raise OptionValueError(opt_invalid('--tree', o, tree_options))
         parser.values.tree_printers.append(tp)
 
     opt_tree_help = "Print a dependency tree in various formats: %s." \