diff options
author | Cedric Beust <cedric@beust.com> | 2012-08-16 10:33:26 -0700 |
---|---|---|
committer | Cedric Beust <cedric@beust.com> | 2012-08-16 10:33:26 -0700 |
commit | 8a4c3d11d8d74628fbe55dce61771810a841723e (patch) | |
tree | 2982e4ca111f5b9a547a14766f0cff50e9c1ea77 /src/main | |
parent | 80b44a9210ee3fe50e64eb4bdcaad03288ea9f08 (diff) | |
download | platform_external_jcommander-8a4c3d11d8d74628fbe55dce61771810a841723e.tar.gz platform_external_jcommander-8a4c3d11d8d74628fbe55dce61771810a841723e.tar.bz2 platform_external_jcommander-8a4c3d11d8d74628fbe55dce61771810a841723e.zip |
Don't throw an exception if running in "no validation" mode.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/beust/jcommander/JCommander.java | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/main/java/com/beust/jcommander/JCommander.java b/src/main/java/com/beust/jcommander/JCommander.java index 30b9b4a..8965f3b 100644 --- a/src/main/java/com/beust/jcommander/JCommander.java +++ b/src/main/java/com/beust/jcommander/JCommander.java @@ -273,7 +273,7 @@ public class JCommander { if (m_descriptions == null) createDescriptions(); initializeDefaultValues(); - parseValues(expandArgs(args)); + parseValues(expandArgs(args), validate); if (validate) validateOptions(); } @@ -666,7 +666,7 @@ public class JCommander { /** * Main method that parses the values and initializes the fields accordingly. */ - private void parseValues(String[] args) { + private void parseValues(String[] args, boolean validate) { // This boolean becomes true if we encounter a command, which indicates we need // to stop parsing (the parsing of the command will be done in a sub JCommander // object) @@ -756,15 +756,18 @@ public class JCommander { // // Command parsing // - if (jc == null) throw new MissingCommandException("Expected a command, got " + arg); - m_parsedCommand = jc.m_programName.m_name; - m_parsedAlias = arg; //preserve the original form - - // Found a valid command, ask it to parse the remainder of the arguments. - // Setting the boolean commandParsed to true will force the current - // loop to end. - jc.parse(subArray(args, i + 1)); - commandParsed = true; + if (jc == null && validate) { + throw new MissingCommandException("Expected a command, got " + arg); + } else if (jc != null){ + m_parsedCommand = jc.m_programName.m_name; + m_parsedAlias = arg; //preserve the original form + + // Found a valid command, ask it to parse the remainder of the arguments. + // Setting the boolean commandParsed to true will force the current + // loop to end. + jc.parse(subArray(args, i + 1)); + commandParsed = true; + } } } } |