Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B8F35DFFE for ; Thu, 25 Oct 2012 22:51:57 +0000 (UTC) Received: (qmail 98522 invoked by uid 500); 25 Oct 2012 22:51:56 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 98439 invoked by uid 500); 25 Oct 2012 22:51:56 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Delivered-To: moderator for user@commons.apache.org Received: (qmail 92800 invoked by uid 99); 25 Oct 2012 22:49:03 -0000 X-ASF-Spam-Status: No, hits=-13.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_HI,SPF_PASS,USER_IN_DEF_SPF_WL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of andrein@amazon.com designates 72.21.198.25 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=andrein@amazon.com; q=dns/txt; s=amazon201209; t=1351205336; x=1382741336; h=from:to:date:subject:message-id: content-transfer-encoding:mime-version; bh=NsFeVyM7ZwDVB4ldAIjP33ejsDeaowZ4LTQbbxP4DWE=; b=UOExgBIRvCHjT00XGgHTj1X8NOL2ykd8qh3KTuQ48NAaNAOQ+IT8LVud Q0gLyf7N2JsF1qTNiYlLTDuYz7jJiEUsxXMJaNyip8ujHy9O/pOpVmcqk yJ+Ci/SeHZONhJpSvp+o/a3qvxlBU0WndtvX6nQB6F9d69oARSZzcJduy 8=; X-IronPort-AV: E=Sophos;i="4.80,650,1344211200"; d="scan'208";a="817018349" From: "Viesca Novack, Andrei" To: "user@commons.apache.org" Date: Thu, 25 Oct 2012 15:47:42 -0700 Subject: [CLI] Using OptionGroups Thread-Topic: [CLI] Using OptionGroups Thread-Index: Ac2zAirL8wOZ2WceTZmKjXF+0xyRCA== Message-ID: <4DCD805AB39A134F81773353E78D0BFC105EF8514D@EX-SEA32-A.ant.amazon.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org 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 bee= n able to find documentation on how to handle different OptionGroups, I wan= t 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 =3D OptionBuilder.hasArg().withArgName("file") .withLongOpt("in").withDescription("VCD file to convert.") .create("i"); in.setRequired(true); Option out =3D OptionBuilder.hasArg().withArgName("file") .withLongOpt("out").withDescription("Output CSV file.") .create("o"); out.setRequired(true); Option getsignals =3D new Option( "g", "getsignals", false, "Gets a list of signals available in a VCD file. Use in conjunction wit= h the i option only."); getsignals.setRequired(true); Option signals =3D OptionBuilder .hasArgs() .withArgName("signalList") .withLongOpt("signals") .withDescription( "Comma separated list of requested signals to include in the CSV.") .withValueSeparator(',').withType(new ArrayList()) .create("s"); signals.setRequired(true); Option timeUnit =3D OptionBuilder .hasArg() .withLongOpt("timeUnit") .withDescription( "Time units to use. Options: 'ms','us' or 'ns'.") .create("t"); timeUnit.setRequired(false); Option noDuplicates =3D new Option("n", "noDuplicates", false, "Set flag to remove duplicate time entries."); noDuplicates.setRequired(false); Option append =3D new Option("a", "append", false, "Set flag to append information to existing CSV."); append.setRequired(false); Option getDeltas =3D new Option("d", "deltas", false, "Set to calculate delta values between entries."); getDeltas.setRequired(false); Option help =3D new Option("h", "help", false, "Prints usage information."); help.setRequired(true); // Group for converting: options =3D new Options(); OptionGroup groupConvert =3D 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 =3D 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