Error message cleanup.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@630 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2009-05-07 19:31:32 +00:00
parent c241d386a7
commit a3d8febbf2
2 changed files with 12 additions and 7 deletions

View File

@ -232,8 +232,9 @@ public abstract class CommandLineProgram {
System.exit(result);
}
catch (ParseException e) {
logger.fatal("Unable to pass command line arguments: " + e.getMessage() );
clp.parser.printHelp( clp.getRunningInstructions() );
// Rethrow the exception to exit with an error.
throw e;
}
catch (Exception e) {
// we catch all exceptions here. if it makes it to this level, we're in trouble. Let's bail!

View File

@ -430,8 +430,12 @@ class MissingArgumentException extends ParseException {
private static String formatArguments( Collection<ArgumentDefinition> missingArguments ) {
StringBuilder sb = new StringBuilder();
for( ArgumentDefinition missingArgument: missingArguments )
sb.append( String.format("Argument with name '%s' is missing.%n", missingArgument.fullName) );
for( ArgumentDefinition missingArgument: missingArguments ) {
if( missingArgument.shortName != null )
sb.append( String.format("%nArgument with name '--%s' (-%s) is missing.", missingArgument.fullName, missingArgument.shortName) );
else
sb.append( String.format("%nArgument with name '--%s' is missing.", missingArgument.fullName) );
}
return sb.toString();
}
}
@ -447,7 +451,7 @@ class InvalidArgumentException extends ParseException {
private static String formatArguments( Collection<ArgumentMatch> invalidArguments ) {
StringBuilder sb = new StringBuilder();
for( ArgumentMatch invalidArgument: invalidArguments )
sb.append( String.format("Argument with name '%s' isn't defined.%n", invalidArgument.label) );
sb.append( String.format("%nArgument with name '%s' isn't defined.", invalidArgument.label) );
return sb.toString();
}
}
@ -464,7 +468,7 @@ class InvalidArgumentValueException extends ParseException {
StringBuilder sb = new StringBuilder();
for( int index: invalidValues.indices.keySet() )
for( String value: invalidValues.indices.get(index) )
sb.append( String.format("Invalid argument value '%s' at position %d.%n", value, index) );
sb.append( String.format("%nInvalid argument value '%s' at position %d.", value, index) );
return sb.toString();
}
}
@ -480,7 +484,7 @@ class TooManyValuesForArgumentException extends ParseException {
private static String formatArguments( Collection<ArgumentMatch> arguments ) {
StringBuilder sb = new StringBuilder();
for( ArgumentMatch argument: arguments )
sb.append( String.format("Argument '%s' has to many values: %s", argument.label, Arrays.deepToString(argument.values().toArray())) );
sb.append( String.format("%nArgument '%s' has to many values: %s.", argument.label, Arrays.deepToString(argument.values().toArray())) );
return sb.toString();
}
}
@ -496,7 +500,7 @@ class ArgumentsAreMutuallyExclusiveException extends ParseException {
private static String formatArguments( Collection<Pair<ArgumentMatch,ArgumentMatch>> arguments ) {
StringBuilder sb = new StringBuilder();
for( Pair<ArgumentMatch,ArgumentMatch> argument: arguments )
sb.append( String.format("Arguments '%s' and '%s' are mutually exclusive.", argument.first.definition.fullName, argument.second.definition.fullName ) );
sb.append( String.format("%nArguments '%s' and '%s' are mutually exclusive.", argument.first.definition.fullName, argument.second.definition.fullName ) );
return sb.toString();
}