commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Viesca Novack, Andrei" <andr...@amazon.com>
Subject [CLI] Using OptionGroups
Date Thu, 25 Oct 2012 22:47:42 GMT
Hello all,
First of all I thank you for Commons CLI, such a useful library!

Question:
I have two sets of arguments in my command line java program, I haven't been able to find
documentation on how to handle different OptionGroups, I want to have the program detect that
it got either group1, group2 or help. To make it interesting, group 1 contains required and
not required arguments.

I am using release 1.2 and here's my code so far:

Option in = OptionBuilder.hasArg().withArgName("file")
				.withLongOpt("in").withDescription("VCD file to convert.")
				.create("i");
		in.setRequired(true);

		Option out = OptionBuilder.hasArg().withArgName("file")
				.withLongOpt("out").withDescription("Output CSV file.")
				.create("o");
		out.setRequired(true);

		Option getsignals = new Option(
				"g",
				"getsignals",
				false,
				"Gets a list of signals available in a VCD file. Use in conjunction with the i option
only.");
		getsignals.setRequired(true);

		Option signals = OptionBuilder
				.hasArgs()
				.withArgName("signalList")
				.withLongOpt("signals")
				.withDescription(
						"Comma separated list of requested signals to include in the CSV.")
				.withValueSeparator(',').withType(new ArrayList<String>())
				.create("s");
		signals.setRequired(true);

		Option timeUnit = OptionBuilder
				.hasArg()
				.withLongOpt("timeUnit")
				.withDescription(
						"Time units to use. Options: 'ms','us' or 'ns'.")
				.create("t");
		timeUnit.setRequired(false);

		Option noDuplicates = new Option("n", "noDuplicates", false,
				"Set flag to remove duplicate time entries.");
		noDuplicates.setRequired(false);

		Option append = new Option("a", "append", false,
				"Set flag to append information to existing CSV.");
		append.setRequired(false);

		Option getDeltas = new Option("d", "deltas", false,
				"Set to calculate delta values between entries.");
		getDeltas.setRequired(false);

		Option help = new Option("h", "help", false,
				"Prints usage information.");
		help.setRequired(true);

		// Group for converting:
		options = new Options();
		OptionGroup groupConvert = new OptionGroup();
		groupConvert.addOption(in);
		groupConvert.addOption(out);
		groupConvert.addOption(signals);
		groupConvert.addOption(timeUnit);
		groupConvert.addOption(noDuplicates);
		groupConvert.addOption(append);
		groupConvert.addOption(getDeltas);
		groupConvert.addOption(getsignals);
		groupConvert.setRequired(true);

		// Group for viewing signals
		OptionGroup groupViewSignals = new OptionGroup();
		groupViewSignals.addOption(in);
		groupViewSignals.addOption(getsignals);
		groupViewSignals.setRequired(true);

		options.addOption(help);
		options.addOptionGroup(groupConvert);
		options.addOptionGroup(groupViewSignals);

Thanks!
Andrei Viesca

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message