gerrit approve: Cleanup invalid patch set error handling

We have to set the metaVar in the @Argument annotation in order to
get a decent error message out of args4j when the user has not put
a value for the required argument.

We also now format the error message when an id is invalid in a
way that is more consistent with the existing args4j formatting.

Change-Id: I50417c96ffde09dc1f88e4b8dba8ce45a0cfd1bd
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-08-28 16:57:43 -07:00
parent 1b998a9c19
commit 09fac3dcc8
2 changed files with 5 additions and 4 deletions

View File

@@ -57,7 +57,7 @@ public class ApproveCommand extends BaseCommand {
private static final int CMD_ERR = 3;
@Argument(index = 0, required = true, usage = "Patch set to approve")
@Argument(index = 0, required = true, metaVar = "CHANGE,PATCHSET", usage = "Patch set to approve")
private PatchSet.Id patchSetId;
@Option(name = "--message", aliases = "-m", usage = "Message to put on change/patchset", metaVar = "MESSAGE")

View File

@@ -36,12 +36,13 @@ public class PatchSetIdHandler extends OptionHandler<PatchSet.Id> {
@Override
public final int parseArguments(final Parameters params)
throws CmdLineException {
final String idString = params.getParameter(0);
final String token = params.getParameter(0);
final PatchSet.Id id;
try {
id = PatchSet.Id.parse(idString);
id = PatchSet.Id.parse(token);
} catch (IllegalArgumentException e) {
throw new CmdLineException(owner, "Invalid patch set: " + idString);
throw new CmdLineException(owner, "\"" + token
+ "\" is not a valid patch set");
}
setter.addValue(id);