diff options
author | Googler <noreply@google.com> | 2016-02-24 22:45:32 +0000 |
---|---|---|
committer | Philipp Wollermann <philwo@google.com> | 2016-02-25 14:14:05 +0000 |
commit | f6a387cf5816602b9f6ad3283f15e33e44a71d9d (patch) | |
tree | 59227b5655a9af074cdcb7e098e13dd7cdca8cef /src | |
parent | 029dcc7929493f9a2c72daa8720c9ff06e003483 (diff) |
Problem:
The --help option is currently broken when allow residue is false as the --help option cannot be parsed and results in exit(2) after emitting the unhelpful message:
Error parsing command line: Unrecognized option: --help
Try --help.
In this case, --help is never reached, and so cannot be used.
Solution:
In the proposed code, if any argument is --help, the --help message will be preferred over emitting parsing errors. The process will now exit(0) prior to parsing any other arguments if --help is passed.
--
MOS_MIGRATED_REVID=115495600
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/google/devtools/common/options/OptionsParser.java | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/common/options/OptionsParser.java b/src/main/java/com/google/devtools/common/options/OptionsParser.java index 5b107b78ae..275f85a927 100644 --- a/src/main/java/com/google/devtools/common/options/OptionsParser.java +++ b/src/main/java/com/google/devtools/common/options/OptionsParser.java @@ -154,13 +154,6 @@ public class OptionsParser implements OptionsProvider { * if "--help" appears anywhere within {@code args}. */ public void parseAndExitUponError(OptionPriority priority, String source, String[] args) { - try { - parse(priority, source, Arrays.asList(args)); - } catch (OptionsParsingException e) { - System.err.println("Error parsing command line: " + e.getMessage()); - System.err.println("Try --help."); - System.exit(2); - } for (String arg : args) { if (arg.equals("--help")) { System.out.println(describeOptions(Collections.<String, String>emptyMap(), @@ -168,6 +161,13 @@ public class OptionsParser implements OptionsProvider { System.exit(0); } } + try { + parse(priority, source, Arrays.asList(args)); + } catch (OptionsParsingException e) { + System.err.println("Error parsing command line: " + e.getMessage()); + System.err.println("Try --help."); + System.exit(2); + } } /** |