Skip to content

Instantly share code, notes, and snippets.

@seanf
Last active December 21, 2015 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanf/6362260 to your computer and use it in GitHub Desktop.
Save seanf/6362260 to your computer and use it in GitHub Desktop.
args4j test in Groovy
@Grab(group='args4j', module='args4j', version='2.0.25')
import org.kohsuke.args4j.*
import org.kohsuke.args4j.spi.*
import static org.kohsuke.args4j.ExampleMode.ALL
public class Sample {
private boolean recursive
// @Option(name="-r", usage="Recursive", handler=BooleanOptionHandler.class)
@Option(name = "--recursive", aliases=["-r"], usage="Recursive")
public void setRecursive(boolean val) {
recursive = val
}
@Option(name = "--msg-file", aliases = ['-m'], usage = "Message File(s) <msg-file>",
required = false, metaVar = "METAFILE")
private List<String> msgFiles_;
@Argument(required = false, multiValued = true, metaVar = "FILE")
private List<String> files_;
}
def sample = new Sample()
CmdLineParser parser = new CmdLineParser(sample);
//parser.parseArgument([])
//parser.parseArgument(["-r", "false"])
//println sample.recursive
//parser.parseArgument(["--msg-file", "a.txt", "--msg-file", "b.txt", "--msg-file", "c.txt"])
parser.parseArgument(["a.txt", "b.txt", "c.txt", "--msg-file", "mf.txt"])
//println sample.files_
//println sample.msgFiles_
def out = new StringWriter()
out.print("Usage: my-command")
parser.printSingleLineUsage(out, null)
out.println()
out.println("My command to do things")
out.println()
parser.printUsage(out, null)
System.err.println(out)
//parser.printExample ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment