• Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    Java
  • Created over 13 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Parse CLI command lines

FOSSA Status

CLI Parser

CLI Parser is a tiny (10k jar), super easy to use library for parsing various kinds of command line arguments or property lists. Using annotations on your fields or JavaBean properties you can specify what configuration is available. Here is an example:

public class Loader {

  @Argument
  private static Boolean hdfs = false;

  @Argument(alias = "r", description = "Regular expression to parse lines", required = true)
  private static String regex;

  @Argument(alias = "k", description = "Key column", required = true)
  private static String key;

  @Argument(alias = "p", description = "Key prefix")
  private static String prefix;

  @Argument(alias = "c", description = "Column groups", delimiter = ",")
  private static String[] columns;

  @Argument(alias = "n", description = "Column names", delimiter = ",")
  private static String[] names;

  @Argument(alias = "h", description = "Redis host")
  private static String host = "localhost";

  @Argument(alias = "p", description = "Redis port")
  private static Integer port = 6379;

  public static void main(String[] args) throws IOException {
    // unparsed will contain all unparsed arguments to the command line
    List<String> unparsed = Args.parseOrExit(Loader.class, args);
    // Loader's fields will be populated after this line or the program will exit with usage
  }
}

In this case we are configuring static fields, but you can also use the same system with instances. If you pass in a wrong command line argument you will get the usage message:

Usage: com.sampullara.cli.Example
  -hdfs [flag]
  -regex (-r) [String] Regular expression to parse lines
  -key (-k) [String] Key column
  -prefix (-p) [String] Key prefix
  -columns (-c) [String[,]] Column groups
  -names (-n) [String[,]] Column names
  -host (-h) [String] Redis host (localhost)
  -port (-p) [Integer] Redis port (6379)

That message will print out the names and aliases of the arguments, type, description and a default value for the parameter if there is one. You can add it to your code with:

<dependency>
  <groupId>com.github.spullara.cli-parser</groupId>
  <artifactId>cli-parser</artifactId>
  <version>1.1.5</version>
</dependency>

Here is the license:

Copyright 2012 Sam Pullara

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

FOSSA Status

More Repositories

1

mustache.java

Implementation of mustache.js for Java
HTML
1,817
star
2

redis-protocol

Java client and server implementation of Redis
Java
351
star
3

havrobase

Use Avro to store all your values in HBase instead of regular columns
Java
74
star
4

nbd

NDB server
Java
57
star
5

browsercrawler

Crawl websites from your browser and save them in S3
JavaScript
55
star
6

interviewcode

At Twitter I often asked a simple question, render a tweet given the text and an unordered list of its entities
Java
39
star
7

mysql-connector-java

Import of the mysql jdbc connector for optimization purposes
Java
27
star
8

findmyiphone

Find your iPhone by scraping the MobileMe site and turning it into a simple REST API
Java
21
star
9

java-future-jdk8

Java Future proposal for JDK8
Java
19
star
10

gpt-j-6b

Dockerfile and web server for running GPT-J-6B on AWS GPU instances
Python
18
star
11

teslalogger

Logs your vehicle information to a file
Java
15
star
12

onvif

Java client for onvif based IP cameras
Java
12
star
13

oauth

Fork of the OAuth Core library
Java
9
star
14

YQL-Storage-Editor

The YQL Storage Editor is an HTML/CSS/JS editor for content stored in yql.storage.
JavaScript
7
star
15

tikvclient

Java client for TiKV by Pingcap
Java
7
star
16

corpuscompression

Achieve better compression for small objects with a predefined corpus
Java
7
star
17

twickery

Push your Twitter activity (favorites, tweets, photos, follows, profile updates) to Facebook ticker
Java
7
star
18

avrocompiler

Alternative template based Avro compiler
Java
6
star
19

mustachelet

Servlet for serving Mustache based templates with backing Java code
Java
5
star
20

scala-plugin

fork of the idea scala plugin
Scala
4
star
21

urlmonitor

Monitors a URL and sends an email when it is down
Java
4
star
22

bfes

Brute force embedding search
Rust
3
star
23

lambdabenchmark

Benchmarking AWS Lambda invocations
Java
3
star
24

thepusher

Pushes values into your objects. Resistance is futile.
Java
3
star
25

photoindex

OpenCLIP photo index and search application
Python
3
star
26

mojava

More Java classes for convenience. Not huge frameworks. Just generically useful stuff.
Java
3
star
27

firebrowser

Update FireEagle using HTML5
Java
3
star
28

codegraph

Load jars into Neo4J and search them
Java
3
star
29

mustache.rs

Port of mustache.java to Rust
Rust
3
star
30

jstacker

Process Jstacks results and compare them across runs
Scala
2
star
31

buffertest

Bytes vs ChannelBuffer vs ByteBuf
Java
2
star
32

cleanuptheweb

Safari extension that replaces bad words with ****
JavaScript
2
star
33

spullara.github.com

Sam Pullara's Site
HTML
2
star
34

mqtt

Java/FDB based version of an MQTT 3.1.1 compatible server
Java
2
star
35

jorstache

Jornado & mustache.java integration project
Java
2
star
36

mustache.scala

Mustache for Scala built to be used with Twitter Scala libraries
Scala
2
star
37

redispatterns

Various patterns for using Redis implemented in Java
2
star
38

simpleconfig

Simple configuration management for applications using simpledb
Java
2
star
39

jlink-custom-runtimes

AWS Lambda custom runtime that supports Java 9, 10, 11, 12, etc. via jlink
Java
2
star
40

vals

Implement vals and lazy vals using a java agent
Java
1
star
41

locrest

Automatically exported from code.google.com/p/locrest
Java
1
star
42

bootstraplet

Build bootstrap based projects integrated with mustache using extensions
1
star
43

maptool

Java
1
star
44

echo

Echo servers
1
star
45

dropboxs3sync

Syncs a dropbox folder to an S3 bucket
JavaScript
1
star
46

avro-generated-code

Example of why the current generated code isn't any good
1
star
47

pokerengine

A reasonable but not great poker engine
Java
1
star
48

json2csv

Really simple converter from JSON to CSV format
Java
1
star
49

s3benchmark

Just some simple benchmarking for how fast you can write and read from S3
Java
1
star
50

guessyournumber

Kids game
1
star
51

jaxrsprotobuf

Example code for one my most popular blog posts from the distant past.
C++
1
star
52

consolidateddb

1
star
53

rumble

1
star
54

spellcheck

Peter Norvig's spellchecker in Java 8 streams
Java
1
star
55

2ldr

tl;dr url shortener
1
star
56

unshredder

1
star
57

fdb

Various FoundationDB utilities and data structures
Java
1
star
58

jets3t

S3 access library
1
star
59

timeflow

Analyze system-wide expected performance
1
star
60

thefeed

The Feed
Java
1
star
61

pattern

Some fixes for the OpenJDK 6/7 Pattern class
Java
1
star
62

scala-parent-pom

Scala 2.8.1 project parent pom
1
star
63

streaming

Just some experiments to understand JDK8 better
1
star
64

twittermarkovgenerator

Reads tweets from a users timeline and generates "sentences" based on the word cooccurence and distribution
Java
1
star
65

webtroller

Control web pages with natural language
JavaScript
1
star