Methods Summary |
---|
public java.lang.String | nextArg()Return the next argument on the command line, whatever it is; if there are
no arguments left, return null.
if (mCurArgData != null) {
String arg = mCurArgData;
mCurArgData = null;
return arg;
} else if (mNextArg < mArgs.length) {
return mArgs[mNextArg++];
} else {
return null;
}
|
public java.lang.String | nextArgRequired()Return the next argument on the command line, whatever it is; if there are
no arguments left, throws an IllegalArgumentException to report this to the user.
String arg = nextArg();
if (arg == null) {
String prev = mArgs[mNextArg - 1];
throw new IllegalArgumentException("Argument expected after \"" + prev + "\"");
}
return arg;
|
public java.lang.String | nextOption()Return the next option on the command line -- that is an argument that
starts with '-'. If the next argument is not an option, null is returned.
if (mCurArgData != null) {
String prev = mArgs[mNextArg - 1];
throw new IllegalArgumentException("No argument expected after \"" + prev + "\"");
}
if (mNextArg >= mArgs.length) {
return null;
}
String arg = mArgs[mNextArg];
if (!arg.startsWith("-")) {
return null;
}
mNextArg++;
if (arg.equals("--")) {
return null;
}
if (arg.length() > 1 && arg.charAt(1) != '-") {
if (arg.length() > 2) {
mCurArgData = arg.substring(2);
return arg.substring(0, 2);
} else {
mCurArgData = null;
return arg;
}
}
mCurArgData = null;
return arg;
|
public abstract void | onRun()Implement the command.
|
public abstract void | onShowUsage(java.io.PrintStream out)Print help text for the command.
|
public void | run(java.lang.String[] args)Call to run the command.
if (args.length < 1) {
onShowUsage(System.out);
return;
}
mArgs = args;
mNextArg = 0;
mCurArgData = null;
try {
onRun();
} catch (IllegalArgumentException e) {
onShowUsage(System.err);
System.err.println();
System.err.println("Error: " + e.getMessage());
} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(1);
}
|
public void | showError(java.lang.String message)Convenience to show usage information to error output along
with an error message.
onShowUsage(System.err);
System.err.println();
System.err.println(message);
|
public void | showUsage()Convenience to show usage information to error output.
onShowUsage(System.err);
|