[java-metadata-aggregator COMMIT] in /trunk/aggregator-cli: pom.xml src/main/java/net/shibboleth/metadata/cli/SimpleC...
noreply at shibboleth.net
noreply at shibboleth.net
Sun Sep 15 13:17:02 EDT 2013
Author: iay
Date: Sun Sep 15 13:17:02 2013
New Revision: 249
URL: http://svn.shibboleth.net/view/java-metadata-aggregator?rev=249&view=rev
Log:
MDA-68: convert command line interface to use JCommander
Modified:
trunk/aggregator-cli/pom.xml
trunk/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLineArguments.java
Modified: trunk/aggregator-cli/pom.xml
URL: http://svn.shibboleth.net/view/java-metadata-aggregator/trunk/aggregator-cli/pom.xml?rev=249&r1=248&r2=249&view=diff
==============================================================================
--- trunk/aggregator-cli/pom.xml (original)
+++ trunk/aggregator-cli/pom.xml Sun Sep 15 13:17:02 2013
@@ -27,8 +27,8 @@
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
- <groupId>jargs</groupId>
- <artifactId>jargs</artifactId>
+ <groupId>com.beust</groupId>
+ <artifactId>jcommander</artifactId>
</dependency>
<!-- Provided Dependencies -->
Modified: trunk/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLineArguments.java
URL: http://svn.shibboleth.net/view/java-metadata-aggregator/trunk/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLineArguments.java?rev=249&r1=248&r2=249&view=diff
==============================================================================
--- trunk/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLineArguments.java (original)
+++ trunk/aggregator-cli/src/main/java/net/shibboleth/metadata/cli/SimpleCommandLineArguments.java Sun Sep 15 13:17:02 2013
@@ -17,13 +17,15 @@
package net.shibboleth.metadata.cli;
-import jargs.gnu.CmdLineParser;
-import jargs.gnu.CmdLineParser.OptionException;
-
import java.io.PrintStream;
-
-import javax.annotation.Nonnull;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.annotation.Nullable;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.ParameterException;
/** Command line arguments for the {@link SimpleCommandLine} command line tool. */
public class SimpleCommandLineArguments {
@@ -31,6 +33,12 @@
// Non-option arguments
/**
+ * Command-line arguments which are not part of options.
+ */
+ @Parameter
+ private List<String> otherArgs = new ArrayList<>();
+
+ /**
* Provided input file name for the Spring configuration file.
*/
@Nullable private String inFile;
@@ -45,86 +53,48 @@
/**
* Verbose logging has been requested.
*/
+ @Parameter(names = "--verbose")
private boolean verbose;
/**
- * Option object for the <code>--verbose</code> option.
- */
- @Nonnull private final CmdLineParser.Option verboseOption;
-
- /**
* Quiet logging has been requested.
*/
+ @Parameter(names = "--quiet")
private boolean quiet;
/**
- * Option object for the <code>--quiet</code> option.
- */
- @Nonnull private final CmdLineParser.Option quietOption;
-
- /**
* Name of a specific logging configuration, if one has been requested.
*/
+ @Parameter(names = "--logConfig")
@Nullable private String logConfig;
- /**
- * Option object for the <code>--logConfig</code> option.
- */
- @Nonnull private final CmdLineParser.Option logConfigOption;
-
// Help
/**
* Help has been requested.
*/
+ @Parameter(names = "--help", help=true)
private boolean help;
-
- /**
- * Option object for the <code>--help</code> option.
- */
- @Nonnull private final CmdLineParser.Option helpOption;
-
- /**
- * The configured command line parser.
- */
- @Nonnull private final CmdLineParser cliParser;
-
- /**
- * Constructor.
- */
- public SimpleCommandLineArguments() {
- cliParser = new CmdLineParser();
-
- verboseOption = cliParser.addBooleanOption("verbose");
- quietOption = cliParser.addBooleanOption("quiet");
- logConfigOption = cliParser.addStringOption("logConfig");
- helpOption = cliParser.addBooleanOption("help");
- }
/**
* Parse an array of command-line arguments as passed to the main program.
*
* @param args array of command-line arguments to parse.
*/
- public void parseCommandLineArguments(String[] args) {
+ public void parseCommandLineArguments(final String[] args) {
try {
- cliParser.parse(args);
+ new JCommander(this, args);
- String[] otherArgs = cliParser.getRemainingArgs();
- if (otherArgs.length != 2) {
+ if (otherArgs.size() != 2) {
printHelp(System.out);
System.out.flush();
System.exit(SimpleCommandLine.RC_INIT);
}
- inFile = otherArgs[0];
- pipelineName = otherArgs[1];
-
- verbose = (Boolean) cliParser.getOptionValue(verboseOption, Boolean.FALSE);
[... 33 lines stripped ...]
More information about the commits
mailing list