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
{
/** Field description */
public static final String ERROR = "error";
/** Field description */
public static final String GROUP_NOT_FOUND = "groupNotFound";

View File

@@ -126,9 +126,19 @@ public abstract class SubCommand
}
catch (CmdLineException ex)
{
if (logger.isWarnEnabled())
{
logger.warn("could not parse comannd line", ex);
}
// todo error handling
logger.error("could not parse command line", ex);
if (!help)
{
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;
}
/**
* Method description
*
*
* @param parser
*/
protected void printHelp(CmdLineParser parser)
{
parser.printUsage(output, i18n.getBundle());
System.exit(1);
}
//~--- fields ---------------------------------------------------------------
/** Field description */