Author: simonetripodi
Date: Thu Apr 21 11:13:18 2011
New Revision: 1095657
URL: http://svn.apache.org/viewvc?rev=1095657&view=rev
Log:
trailing spaces
Modified:
commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/DefaultParser.java
Modified:
commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/DefaultParser.java
URL:
http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/DefaultParser.java?rev=1095657&r1=1095656&r2=1095657&view=diff
==============================================================================
---
commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/DefaultParser.java
(original)
+++
commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/DefaultParser.java
Thu Apr 21 11:13:18 2011
@@ -30,11 +30,11 @@ import java.util.Properties;
* @since 1.3
*/
public class DefaultParser implements CommandLineParser
-{
+{
protected CommandLine cmd;
protected Options options;
- /**
+ /**
* Flag indicating how unrecognized tokens are handled. <tt>true</tt> to
stop
* the parsing and add the remaining tokens to the args list.
* <tt>false</tt> to throw an exception.
@@ -43,16 +43,16 @@ public class DefaultParser implements Co
/** The token currently processed. */
protected String currentToken;
-
+
/** The last option parsed. */
protected Option currentOption;
-
+
/** Flag indicating if tokens should no longer be analysed and simply
added as arguments of the command line. */
protected boolean skipParsing;
-
+
/** The required options and groups expected to be found when parsing the
command line. */
protected List expectedOpts;
-
+
public CommandLine parse(Options options, String[] arguments) throws
ParseException
{
return parse(options, arguments, null);
@@ -101,13 +101,13 @@ public class DefaultParser implements Co
skipParsing = false;
currentOption = null;
expectedOpts = new ArrayList(options.getRequiredOptions());
-
+
// clear the data from the groups
for (OptionGroup group : options.getOptionGroups())
{
group.setSelected(null);
}
-
+
cmd = new CommandLine();
if (arguments != null)
@@ -117,15 +117,15 @@ public class DefaultParser implements Co
handleToken(argument);
}
}
-
+
// check the arguments of the last option
checkRequiredArgs();
-
+
// add the default options
handleProperties(properties);
-
+
checkRequiredOptions();
-
+
return cmd;
}
@@ -140,26 +140,26 @@ public class DefaultParser implements Co
{
return;
}
-
+
for (Enumeration e = properties.propertyNames(); e.hasMoreElements();)
{
String option = e.nextElement().toString();
-
+
Option opt = options.getOption(option);
if (opt == null)
{
throw new UnrecognizedOptionException("Default option wasn't
defined", option);
}
-
+
// if the option is part of a group, check if another option of
the group has been selected
OptionGroup group = options.getOptionGroup(opt);
boolean selected = group != null && group.getSelected() != null;
-
+
if (!cmd.hasOption(option) && !selected)
{
// get the value from the properties
String value = properties.getProperty(option);
-
+
if (opt.hasArg())
{
if (opt.getValues() == null || opt.getValues().length == 0)
@@ -174,7 +174,7 @@ public class DefaultParser implements Co
// if the value is not yes, true or 1 then don't add the
option to the CommandLine
continue;
}
-
+
handleOption(opt);
currentOption = null;
}
@@ -189,7 +189,7 @@ public class DefaultParser implements Co
* are not present.
*/
private void checkRequiredOptions() throws MissingOptionException
- {
+ {
// if there are required options that have not been processsed
if (!expectedOpts.isEmpty())
{
@@ -211,14 +211,14 @@ public class DefaultParser implements Co
/**
* Handle any command line token.
- *
+ *
* @param token the command line token to handle
* @throws ParseException
*/
private void handleToken(String token) throws ParseException
{
currentToken = token;
-
+
if (skipParsing)
{
cmd.addArg(token);
@@ -243,7 +243,7 @@ public class DefaultParser implements Co
{
handleUnknownToken(token);
}
-
+
if (currentOption != null && !currentOption.acceptsArg())
{
currentOption = null;
@@ -252,7 +252,7 @@ public class DefaultParser implements Co
/**
* Returns true is the token is a valid argument.
- *
+ *
* @param token
*/
private boolean isArgument(String token)
@@ -262,7 +262,7 @@ public class DefaultParser implements Co
/**
* Check if the token is a negative number.
- *
+ *
* @param token
*/
private boolean isNegativeNumber(String token)
@@ -280,7 +280,7 @@ public class DefaultParser implements Co
/**
* Tells if the token looks like an option.
- *
+ *
* @param token
*/
private boolean isOption(String token)
@@ -301,7 +301,7 @@ public class DefaultParser implements Co
/**
* Tells if the token looks like a long option.
- *
+ *
* @param token
*/
private boolean isLongOption(String token)
@@ -313,7 +313,7 @@ public class DefaultParser implements Co
int pos = token.indexOf("=");
String t = pos == -1 ? token : token.substring(0, pos);
-
+
if (!options.getMatchingOptions(t).isEmpty())
{
// long or partial long options (--L, -L, --L=V, -L=V, --l, --l=V)
@@ -334,7 +334,7 @@ public class DefaultParser implements Co
* to the arguments of the command line. If the stopAtNonOption flag
* is set, this stops the parsing and the remaining tokens are added
* as-is in the arguments of the command line.
- *
+ *
* @param token the command line token to handle
*/
private void handleUnknownToken(String token) throws ParseException
@@ -343,7 +343,7 @@ public class DefaultParser implements Co
{
throw new UnrecognizedOptionException("Unrecognized option: " +
token, token);
}
-
+
cmd.addArg(token);
if (stopAtNonOption)
{
@@ -353,12 +353,12 @@ public class DefaultParser implements Co
/**
* Handles the following tokens:
- *
+ *
* --L
* --L=V
* --L V
* --l
- *
+ *
* @param token the command line token to handle
*/
private void handleLongOption(String token) throws ParseException
@@ -369,13 +369,13 @@ public class DefaultParser implements Co
}
else
{
- handleLongOptionWithEqual(token);
+ handleLongOptionWithEqual(token);
}
}
/**
* Handles the following tokens:
- *
+ *
* --L
* -L
* --l
@@ -402,12 +402,12 @@ public class DefaultParser implements Co
/**
* Handles the following tokens:
- *
+ *
* --L=V
* -L=V
* --l=V
* -l=V
- *
+ *
* @param token the command line token to handle
*/
private void handleLongOptionWithEqual(String token) throws ParseException
@@ -415,9 +415,9 @@ public class DefaultParser implements Co
int pos = token.indexOf('=');
String value = token.substring(pos + 1);
-
+
String opt = token.substring(0, pos);
-
+
List<String> matchingOpts = options.getMatchingOptions(opt);
if (matchingOpts.isEmpty())
{
@@ -430,7 +430,7 @@ public class DefaultParser implements Co
else
{
Option option = options.getOption(matchingOpts.get(0));
-
+
if (option.acceptsArg())
{
handleOption(option);
@@ -446,7 +446,7 @@ public class DefaultParser implements Co
/**
* Handles the following tokens:
- *
+ *
* -S
* -SV
* -S V
@@ -454,21 +454,21 @@ public class DefaultParser implements Co
* -S1S2
* -S1S2 V
* -SV1=V2
- *
+ *
* -L
* -LV
* -L V
* -L=V
* -l
- *
+ *
* @param token the command line token to handle
*/
private void handleShortAndLongOption(String token) throws ParseException
{
String t = Util.stripLeadingHyphens(token);
-
+
int pos = t.indexOf('=');
-
+
if (t.length() == 1)
{
// -S
@@ -497,7 +497,7 @@ public class DefaultParser implements Co
{
// look for a long prefix (-Xmx512m)
String opt = getLongPrefix(t);
-
+
if (opt != null && options.getOption(opt).acceptsArg())
{
handleOption(options.getOption(opt));
@@ -523,7 +523,7 @@ public class DefaultParser implements Co
// equal sign found (-xxx=yyy)
String opt = t.substring(0, pos);
String value = t.substring(pos + 1);
-
+
if (opt.length() == 1)
{
// -S=V
@@ -557,13 +557,13 @@ public class DefaultParser implements Co
/**
* Search for a prefix that is the long name of an option (-Xmx512m)
- *
+ *
* @param token
*/
private String getLongPrefix(String token)
{
String t = Util.stripLeadingHyphens(token);
-
+
int i;
String opt = null;
for (i = t.length() - 2; i > 1; i--)
@@ -586,7 +586,7 @@ public class DefaultParser implements Co
{
String opt = token.substring(0, 1);
Option option = options.getOption(opt);
-
+
return option != null && (option.getArgs() >= 2 || option.getArgs() ==
Option.UNLIMITED_VALUES);
}
@@ -594,16 +594,16 @@ public class DefaultParser implements Co
{
// check the previous option before handling the next one
checkRequiredArgs();
-
+
option = option.clone();
-
+
updateRequiredOptions(option);
-
+
cmd.addOption(option);
-
+
if (option.hasArg())
{
- currentOption = option;
+ currentOption = option;
}
else
{
@@ -613,7 +613,7 @@ public class DefaultParser implements Co
/**
* Removes the option or its group from the list of expected elements.
- *
+ *
* @param option
*/
private void updateRequiredOptions(Option option) throws
AlreadySelectedException
@@ -671,7 +671,7 @@ public class DefaultParser implements Co
if (options.hasOption(ch))
{
handleOption(options.getOption(ch));
-
+
if (currentOption != null && (token.length() != (i + 1)))
{
// add the trail as an argument of the option
@@ -680,7 +680,7 @@ public class DefaultParser implements Co
}
}
else
- {
+ {
handleUnknownToken(stopAtNonOption && i > 1 ?
token.substring(i) : token);
break;
}