improve subcommand exception handling

This commit is contained in:
Sebastian Sdorra
2011-05-22 13:47:22 +02:00
parent d2eb6d141c
commit 029aed3e82
3 changed files with 28 additions and 2 deletions

View File

@@ -50,6 +50,9 @@ import java.util.ResourceBundle;
public class I18n public class I18n
{ {
/** Field description */
public static final String ERROR = "error";
/** Field description */ /** Field description */
public static final String GROUP_NOT_FOUND = "groupNotFound"; public static final String GROUP_NOT_FOUND = "groupNotFound";

View File

@@ -126,9 +126,19 @@ public abstract class SubCommand
} }
catch (CmdLineException ex) catch (CmdLineException ex)
{ {
if (logger.isWarnEnabled())
{
logger.warn("could not parse comannd line", ex);
}
// todo error handling if (!help)
logger.error("could not parse command line", ex); {
output.append(i18n.getMessage(I18n.ERROR)).append(": ");
output.println(ex.getMessage());
output.println();
}
printHelp(parser);
} }
} }
@@ -183,6 +193,18 @@ public abstract class SubCommand
return session; return session;
} }
/**
* Method description
*
*
* @param parser
*/
protected void printHelp(CmdLineParser parser)
{
parser.printUsage(output, i18n.getBundle());
System.exit(1);
}
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** Field description */

View File

@@ -29,6 +29,7 @@
VAL = value VAL = value
FILE = file FILE = file
error = Error
subCommandsTitle = SubCommands subCommandsTitle = SubCommands