Code Monkey home page Code Monkey logo

josh's Introduction

josh - Java Oriented Shell

This is a little framework to help the creation of a command line shell console in Java.

What should be configurable:

  • Where to find commands, and how to run them
    • from beans in Spring application context
    • from jars in plugins directory
    • from groovy or jython files
    • embedded in my source code
  • How to parse commands and options
  • How to display command help
    • custom formatting
  • Initialization and destruction
    • Hooks for initialization and destruction in the shell life cycle
  • Customizable
    • startup message
    • prompt
    • error messages
    • tab completion

What josh must provide:

  • A framework to glue all the components together
  • Standard implementation of common components
  • Command line editing and history

Don't depend on a lot of external libraries

  • The only required dependency is slf4j-api
  • jline2 and jcommander are optional dependencies

How to use

A simple example of a basic shell with the built in commands, and no customization.

package josh.example;

import josh.command.builtin.BuiltInCommandProvider;
import josh.shell.BasicConsoleProvider;
import josh.shell.LineParserImpl;
import josh.shell.Shell;

public class MinimalShell {

    public static void main(String[] args) {
        Shell shell = new Shell();
        shell.setLineParser(new LineParserImpl());
        shell.setCommandProvider(new BuiltInCommandProvider());
        shell.setConsoleProvider(new BasicConsoleProvider());
        System.exit(shell.runInteractive().getExitCode());
    }

}

To add you own commands you must implement the interface CommandProvider. The josh-example module has some examples that could be used as a starting point.

To use advanced line editing capabilities, instead of BasicConsoleProvider you should use JLineConsoleProvider that is already included in josh.

        JLine2ConsoleProvider provider = new JLine2ConsoleProvider();
        provider.setHistory(System.getProperty("user.home") + "/.josh/", "josh_history", 800);
        provider.setPromptColor(Ansi.Color.CYAN);
        provider.setErrorColor(Ansi.Color.RED);
        provider.addCompleter(new CommandCompleter(shell.getLineParser(), shell.getCommandProvider()));
        provider.setPrompt("> ");

        shell.setConsoleProvider(provider);

Warning

This framework was tested on Linux. If you run it on Windows and find a bug (or not!) let us know.

josh's People

Contributors

jefersonestevo avatar adzubla avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

mhcrnl

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.