Giter Site home page Giter Site logo

cli-tool's Introduction

Release FOSSA Status

CLI Tool

A library for building a simple CLI for terminal Java applications. Don't expect a full fledged terminal emulator. Do expect a (hopefully) simple and intuitive way to build a basic CLI.

The code is a little unpolished still, but I'll try to tidy it up and improve the documentation a bit.

Javadoc hosted by Jitpack can be found here

Importing

The library is hosted on Jitpack. Gradle example:

allprojects {
  repositories {
    jcenter()
    maven { url "https://jitpack.io" }
  }
}
dependencies {
  compile 'no.iskra:CLITool:2.0+'
}

Usage

Methods with the @Cmd(name = "commandname") annotation can be run as commands in the created CLI. All methods you want to call from the CLI must reside in the same class. As for now, they all need to accept the parameters List<String> params, List<String> flags, Map<String, String> args, nothing more, nothing less. They also need to return a String, which should contain a human readable result of the operation.

The parameter List<String> flags is, for now, ignored. This feature will be implemented soon.

Example:

// App.java

public static void main(String[] args) {
  CLI<App> cli = new CLI<App>(new App());
  cli.cli();
}

@Cmd(name = "hello")
String helloWorldExampleCommand(List<String> params, List<String> flags, Map<String, String> args) {
  return "Hello, World!";
}

The CLI would now accept the command 'hello', to which it would respond with the output of helloWorldExampleCommand.

CLI.parse(String in) is public and can be used to parse input without starting the CLI for whatever reason, like passing command line arguments from 'main', or implementing your own user input method.

The CLI will accept any input after the command. Single words will be interpreted as a param. --key=value and --key2="value 2" will be passed as key, value pairs in args. Flags are not yet used, so -f will simply be ignored. The parameter is included for future backwards compatibility.

License

FOSSA Status

cli-tool's People

Contributors

fossabot avatar jlangvand avatar

Watchers

 avatar

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.