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
|
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";
|
||||||
|
|
||||||
|
|||||||
@@ -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 */
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
VAL = value
|
VAL = value
|
||||||
FILE = file
|
FILE = file
|
||||||
|
error = Error
|
||||||
|
|
||||||
subCommandsTitle = SubCommands
|
subCommandsTitle = SubCommands
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user