All Projects → gab-studios → gab-cmdline

gab-studios / gab-cmdline

Licence: Apache-2.0 license
A GABStudios Java library to help with command line parsing.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to gab-cmdline

google streetview
A command line tool and module for Google Street View Image API
Stars: ✭ 77 (+541.67%)
Mutual labels:  command, line
colortest
Quickly show all your terminal colors
Stars: ✭ 66 (+450%)
Mutual labels:  command, line
SimpleCLI
Command Line Interface Library for Arduino
Stars: ✭ 197 (+1541.67%)
Mutual labels:  command, line
ucollage
An extensible command line image viewer inspired by vim
Stars: ✭ 161 (+1241.67%)
Mutual labels:  command, line
Gql
Very simple CLI for many GraphQL schemas in the cloud. Provides autocompletion for GraphQL queries
Stars: ✭ 101 (+741.67%)
Mutual labels:  command, line
Simplecli
Command Line Interface Library for Arduino
Stars: ✭ 135 (+1025%)
Mutual labels:  command, line
unosolo
Work-in-progress Rust application that converts C++ header-only libraries to single self-contained headers.
Stars: ✭ 26 (+116.67%)
Mutual labels:  command, line
Habitctl
Minimalist command line tool you can use to track and examine your habits.
Stars: ✭ 277 (+2208.33%)
Mutual labels:  command, line
Python
Python cheatsheet
Stars: ✭ 25 (+108.33%)
Mutual labels:  command, line
Bash Argsparse
An high level argument parsing library for bash
Stars: ✭ 128 (+966.67%)
Mutual labels:  command, line
Neodoc
Beautiful, hand-crafted commandline interfaces for node.js
Stars: ✭ 221 (+1741.67%)
Mutual labels:  command, line
regl-line
Flat 2D and 3D line rending with Regl for WebGL
Stars: ✭ 44 (+266.67%)
Mutual labels:  line
line-bot-sdk
🍥 Haskell向けLINE Messaging API SDK
Stars: ✭ 31 (+158.33%)
Mutual labels:  line
line
Development repository for the line cookbook
Stars: ✭ 96 (+700%)
Mutual labels:  line
gw
A Wrapper of a command to watch any changes in filesystem
Stars: ✭ 16 (+33.33%)
Mutual labels:  command
line-example-bot-tiny-php
Line Bot 基礎範例程式碼教學 (PHP) - 輕量版 LINEBotTiny.php
Stars: ✭ 58 (+383.33%)
Mutual labels:  line
RustPlus-Discord-Bot
This is an NodeJS Discord Bot that uses the rustplus.js to interact with Smart Devices in the PC game Rust.
Stars: ✭ 23 (+91.67%)
Mutual labels:  command
command-flow
A flexible command framework and dispatcher which removes lots of boilerplate code used in commands. While it is used generally on Bukkit it is platform agnostic
Stars: ✭ 103 (+758.33%)
Mutual labels:  command
fzf-marker
The terminal command tweak from @pindexis/marker
Stars: ✭ 22 (+83.33%)
Mutual labels:  command
LINE-FreshBot
LINE Bot
Stars: ✭ 23 (+91.67%)
Mutual labels:  line

GAB-CmdLine

The GAB Social Command Line Parser for Java. The purpose of this project is to analyze and examine how I would create a command line parser for Java. Comments are welcome. Thank you.

Required

This project requires the following:

* Java 8 or 11
* Maven

Maven Dependency

<dependency>
   <groupId>com.gabstudios</groupId>
   <artifactId>gab-cmdline</artifactId>
   <version>1.0.0-SNAPSHOT</version>
</dependency>

<dependency>
   <groupId>com.gabstudios</groupId>
   <artifactId>gab-collection</artifactId>
   <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
   <groupId>com.gabstudios</groupId>
   <artifactId>gab-logging</artifactId>
   <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
   <groupId>com.gabstudios</groupId>
   <artifactId>gab-validate</artifactId>
   <version>1.0.0</version>
</dependency>

Build

Use Maven to build - mvn package.

Usage

In order to parse the command line, you need to define what the commands are by calling Cmdline.defineCommand("xxx");

CmdLine.defineCommand("-help, #print this message")

The string used in the defineCommand() method, contains tokens that must use one of these symbols in order for it to be recognized as that type:

# = The description of the command. There may be zero to one defined.

! = A required value for the command name. There can be zero to many defined.

? = An optional value for the command name. There can be zero to many defined.

: = The regex value to match on for any values that are defined. There can be zero to one defined.

... = A value ends with ... and is a list for the command name. There can be zero to one defined. This can be used with the ! and ? symbols

If a token does not start with one of these tokens, then it is considered a command name. There can be one to many names that represent a single command, such as: 'f', 'file', 'filename' or '-f', '--file', '--filename'.

Example

myApp [commands] [option1 [option2 [option3] ...]]
  Commands: 
  -help                  print this message
  -version               print the version information and exit
  -quiet                 be extra quiet
  -verbose               be extra verbose
  -debug                 print debugging information
  -logfile <file>        use given file for log
  -logger <classname>    the class which is to perform logging
  -listener <classname>  add an instance of class as a project listener
  -D<property>=<value>   use value for given property
  -find <file>           search for file towards the root of the
                         filesystem and use it
// define a listener implementation of the CommandListener interface.
private class CmdLineListener implements CommandListener
{
    @Override
    public void handle(final Command command)
    {
        System.out.println( command );
    }
}
// create an instance of the listener.
final CmdLineListener listener = new CmdLineListener();

// define/declare the commands the parser should parse.
// command names can start with any character that is not reserved.  reserved are !?#:
// the commands listed below use the - (dash) to denote a command, but this is not required.
CmdLine.defineCommand("-help, #print this message")
       .defineCommand("-version, #print the version information and exit")
       .defineCommand("-quiet, #be extra quiet")
       .defineCommand("-verbose, #be extra verbose")
       .defineCommand("-debug, #print debugging information")
       .defineCommand("-logfile, !logFile, #use given file for log")
       .defineCommand("-logger, !logClass, #the class which is to perform logging")
       .defineCommand("-listener, !listenerClass, #add an instance of class as a project listener")
       .defineCommand("-find, !buildFile, #search for file towards the root of the file system and use it");

Note:  The format of "-D<property>=<value>" is automatically supported and doesnt need to be defined.  
If a -D<property>=<value> is seen on the command line, it is parsed and set 
in the System properties.  In addition, a command is created and sent to the listener.

// parse the command line args and pass matching commands to the listener for processing.
final List<command> = CmdLine.parse( args, listener );

Click for more examples.

More Documentation

Check the project wiki.

Copyright

[Copyright 2016 Gregory Brown]

License

This codebase is licensed under the Apache v2.0 License.

Feedback

Comments and feedback are greatly appreciated!!!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].