Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/zandero/cmd
- Owner: zandero
- License: apache-2.0
- Created: 2017-03-10T12:01:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-06-20T12:53:59.000Z (over 4 years ago)
- Last Synced: 2024-05-01T11:34:07.916Z (7 months ago)
- Topics: command-line, command-line-parser, parse
- Language: Java
- Size: 49.8 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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");
```