Skip to content

zandero/cmd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

command line parser

Command line parsing utility, that converts a given command line to a name, value Map

Example

java -jar MyApp.jar -t 10 -p raw

Will produce a setting map:

Map<String, Object> settings = new HashMap<>();
settings.put("t", 10);
settings.put("p", "raw");`

Setup

<dependency>      
     <groupId>com.zandero</groupId>      
     <artifactId>cmd</artifactId>      
     <version>1.3</version>      
</dependency>

Usage

// define command arguments
CommandOption all = new BoolOption("a")
	.longCommand("all")
	.setting("getAll");

CommandOption file = new StringOption("f")
	.longCommand("file")
	.setting("fileName");

CommandOption size = new IntOption("s")
	.longCommand("size")
	.setting("fileSize");

// create builder
CommandBuilder builder = new CommandBuilder();
builder.add(all);
builder.add(file);
builder.add(size);

// create parser
CommandLineParser parser = new CommandLineParser(builder);
// use parser to parse input arguments
String[] args = new String[]{"-a", "--file", "/this.file", "-s", "100");
    
Settings out = parser.parse(args);
    
int size = out.get("fileSize");
boolean getAll = out.get("getAll");
Stirng fileName = out.get("fileName");

Releases

No releases published

Packages

No packages published

Languages