commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <ggreg...@seagullsw.com>
Subject [CLI] Missing constructor on class Option
Date Sun, 06 Apr 2003 00:10:42 GMT
In my CLI usage, I have options that take parameters, for example:

private Options getOptions() {
	if (this.options == null) {
		this.options = new Options();
		options.addOption("help", false, "Prints this message.");
		Option option =
			new Option(
				COMM_SHORT_OPTION,
				COMM_LONG_OPTION,
				true,
				"Specifies the communication configuration
file.");
		option.setArgName("file");
		options.addOption(option);
	}
	return options;
}

Note that in order for the following to work properly:

public void printHelp() {
	new HelpFormatter().printHelp("StopServer", this.getOptions(),
true);
}

The following is required:

option.setArgName("file");

My issue is with the very awkward code needed to set this up. IMO, I should
be able to say:

	options.addOption(new Option(
				COMM_SHORT_OPTION,
				COMM_LONG_OPTION,
				true,
				"file",
				"Specifies the communication configuration
file."));

or:
	options.addOption(COMM_SHORT_OPTION,
				COMM_LONG_OPTION,
				true,
				"file",
				"Specifies the communication configuration
file.");

Oddly, the constructor:

Option(java.lang.String opt, java.lang.String longOpt, boolean hasArg,
java.lang.String description)

let's you say that an option has an argument but does not allow you to
document it. If you consider that a constructor should allow for an object
to be built in a useable way, then we have a missing constructor, as the
object is not built properly for use with HelpFormatter. 

I think we need to at least have the "missing" Option constructor while the
additional addOption method is debatable.

Perhaps the current constructor "boolean hasArg" above should be deprecated
in favor of a "boolean hasArg, String argName" constructor?

I have looked at OptionBuilder and appreciate the Smalltalk-like cascading
method call style it allows for but still consider the lack of the
constructor an issue.

I am available to implement and commit these 1 or 2 additions, depending on
this forum's feedback.

Thank you,
Gary

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message