GithubHelp home page GithubHelp logo

rucub100 / clifw Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 76 KB

Yet another CLI framework for parsing command line arguments passed to programs. The API also allows you to build an interactive shell.

License: MIT License

Java 100.00%
cli-parser argument-parser shell-prompt interactive-shell fluent-api test-driven-development

clifw's Introduction

clifw

Yet another ultra lightweight CLI framework for parsing command line arguments passed to programs.
The API also allows you to build an interactive shell.

Example

The main public API CLI allows you to build a schema for the expected arguments.
This is a convenient solution that offers a modern, descriptive and fluent manner.

public static void main(String[] args) {
    CLI cli = CLI.setArgs(args) // args = new String[] { "-a" }
        .addOpt(Opt
            .useChar('a')
            .description("this is a short test option")
            .build())
        .build();
    ...
}

Once you've defined the schema, call the run method and let the framework do it's job.

try {
    cli.run();
    ...
} catch(Exception e) {
    System.err.println(e.getMessage());
}

The last step is to process the result cli.getResult() in your own business code.
For an example of an interactive shell, read the shell documentation.

General Design

The main building block is the schema which consists of different other sub building blocks and glue components.

Schema

Name Pattern Examples Description
Options [-<o>|--<option>]... -r
--recursive
-o=filename
-i name
This schema allows to define an arbitrary sequence of options. An option is either a single character with a preceding - or any word with a preceding --. An optional value can be assigned, either in the mathematical notation with the = sign or simply separated by a space. Obviously, further restrictions on the value must be made, for example it must not start with a dash or contain spaces.
Arguments [<arg>]... 1 2 3
"My Name"
Numbers or words can be used as arguments. If a single argument contains spaces, it must be enclosed in quotation marks.
Options and arguments [-<o>|--<option>]... [<arg>]... -c 3 output.txt The order is important here, the first argument may only come after the last option including its value, if any.
Commands <command> [-<o>|--<option>]... [<arg>]... checkout -b development Note that at most one command can be passed as an argument per call. However, any number of different commands can of course be defined in the API.
Shell Behaves like if you put the Commands scheme in a loop. Before entering the interactive shell, the Options and arguments schema applies.

The setArgs and useShell methods initiate the declarative definition of the schema. In the first method, a schema can be passed as an optional argument, the default value corresponds to "Options". However, a builder object is returned, which is also implemented as a fluent interface. See API section for more details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.