Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zandero/cmd

Command line parser
https://github.com/zandero/cmd

command-line command-line-parser parse

Last synced: 4 days ago
JSON representation

Command line parser

Awesome Lists containing this project

README

        

# 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:
```java
Map settings = new HashMap<>();
settings.put("t", 10);
settings.put("p", "raw");`
```

## Setup
```xml

com.zandero
cmd
1.3

```

## Usage

```java
// 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);

```

```java
// 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");
```