Make AbstractCommand part of the public API
Created originally on Bitbucket by John Freeman
Let me start with a motivating example. I've got an abstraction that needs to run a few specific commands, but the way it deals with their failure or success is all the same:
if (!cmd.isSuccessful()) {
throw new RuntimeException(errorMsg + "\n"
+ cmd + "\n"
+ "returned [" + cmd.getReturnCode() + "]:\n"
+ cmd.getErrorString());
} else if (_verbose) {
System.out.println("hg " + cmd.getCommandName()
+ " executed successfully");
// TODO: Will a successful command even have an error string?
System.err.println(cmd.getErrorString());
}
Ideally, I'd like to wrap this in a helper function to which I only need to pass a String errorMsg
and an AbstractCommand cmd
. The problems are that:
-
AbstractCommand.isSuccessful
is protected. -
AbstractCommand
lacks anexecute()
(or even anexecute(String...)
) method even though it appears every one of its subclasses has one (and arguably should).
I created this issue to recommend addressing these two points, and possibly even moving AbstractCommand
out of the com.aragost.javahg.internals
package into something intended to be more user-facing.