Giter Club home page Giter Club logo

lagopuscommandsystem's Introduction

Lagopus Command System Library

Powerful command parsing system!

This is NOT a command line argument parsing library. Rather, this library is designed to help parse commands that are inputted by the user during the runtime of an application. Useful for things like server consoles or the likes.

This library was written to be usable in any project. As a result of that, There's a little bit more you have to do on your side, so it's not plug and play. However, you also get a large amount of control over how the command system works.

Simple code example

First you need a class that the command system will manage. This can be anything you want.

interface ICommand
{
    void execute(String[] preArgs, String[] args);
}

Now for the actual use of the library.

public class SimpleCommandSystem
{
    private CommandSystem<ICommand> cs = new CommandSystem<>();

    public SimpleCommandSystem()
    {
        cs.registerCommand("test", (preArgs, args) -> {System.out.println("test complete!");});
    }

    public void onCommand(String input)
    {
        CommandResult<ICommand> result = cs.getCommand(input);
        if(result.command == null) System.out.println("Unknown command!");

        result.command.execute(result.preArgs, result.args);
    }
}

When onCommand("test") is called, the command system will match "test" to the corresponding command (in our case, it just simply prints "test complete!"). Of course, our command syntaxes and syntax trees can be much more complex.

syntax parsing

The command system takes the corresponding command syntax and parses it to make it easier for you to make complex command trees. Some examples are listed below:

a b c -> the user command would be matched to someone inputting "a b c"

a b|c d -> this matches the input to both inputs "a b d" and "a c d"

a b|{c d} -> this matches the input to both "a b" and "a c d"

a * c -> this matches input "a * c", where * can be anything. Wildcard inputs are put in the preArgs array.

There are more examples in the unit tests.

lagopuscommandsystem's People

Contributors

mrzoraman avatar

Watchers

 avatar  avatar  avatar

lagopuscommandsystem's Issues

Error with commands

BasicCommandSystem bcs = new BasicCommandSystem();
bcs.registerCommand("add tag by name", new AddTagByNameCommand(this));
bcs.registerCommand("add tag by id", new AddTagByIdCommand(this));

"add tag by id" does not work. "id" seems to be passed as a param to the "add tag by name" command.

Command system seems too eager

if I register the command "help" and just type "h", it matches up to "help", for instance. I dunno, maybe this is a feature?

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.