radarsh / args

A reusable solution for Command Line Arguments Parsing in Java

Home Page:http://www.adarshr.com/args-engine-a-reusable-solution-for-command-line-arguments-parsing-in-java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

args

A reusable solution for Command Line Arguments Parsing in Java

Usage

// Initiate the arguments engine.
ArgsEngine engine = new ArgsEngine();

// Configure the switches/options. Use true for valued options.
engine.add("-q", "--quiet");
engine.add("-o", "--redirect-output", true);
engine.add("-h", "--help");

// Perform the parsing. The 'args' is the String[] received by main method.
engine.parse(args);

// Start fetching states of switches.
boolean quiet = engine.getBoolean("-q");

if(engine.getBoolean("-o")) {
    // For valued options, use getString.
    String redir = engine.getString("-o");
}

// Use getNonOptions to filter out all options.
String[] nonOptions = engine.getNonOptions();

About

A reusable solution for Command Line Arguments Parsing in Java

http://www.adarshr.com/args-engine-a-reusable-solution-for-command-line-arguments-parsing-in-java

License:Apache License 2.0


Languages

Language:Java 100.0%