We're going to be using jcommander for parsing of the commands.

http://jcommander.org/
This commit is contained in:
graywolf336 2013-12-18 13:29:42 -06:00
parent afccd42c24
commit 3b77efa93f
3 changed files with 67 additions and 0 deletions

26
pom.xml
View File

@ -67,6 +67,12 @@
<type>jar</type>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.30</version>
</dependency>
<!-- Start of Test Dependencies -->
<dependency>
<groupId>junit</groupId>
@ -147,6 +153,26 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.beust:jcommander</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>

View File

@ -0,0 +1,21 @@
package test.java.com.graywolf336.jail;
import junit.framework.Assert;
import org.junit.Test;
import com.beust.jcommander.JCommander;
import test.java.com.graywolf336.jail.util.JCommanderExample;
public class TestJCommander {
@Test
public void testIt() {
JCommanderExample jce = new JCommanderExample();
String[] args = { "-log", "2", "-groups", "unit" };
new JCommander(jce, args);
Assert.assertEquals(jce.verbose.intValue(), 2);
Assert.assertEquals(jce.groups.toLowerCase(), "unit");
}
}

View File

@ -0,0 +1,20 @@
package test.java.com.graywolf336.jail.util;
import java.util.ArrayList;
import java.util.List;
import com.beust.jcommander.Parameter;
public class JCommanderExample {
@Parameter
public List<String> parameters = new ArrayList<String>();
@Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
public Integer verbose = 1;
@Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
public String groups;
@Parameter(names = "-debug", description = "Debug mode")
public boolean debug = false;
}