mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
improve subcommand exception handling
This commit is contained in:
@@ -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";
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
VAL = value
|
||||
FILE = file
|
||||
error = Error
|
||||
|
||||
subCommandsTitle = SubCommands
|
||||
|
||||
|
||||
Reference in New Issue
Block a user