Giter VIP home page Giter VIP logo

commander's Introduction

Commander

Commander is a simple, extensible, and configurable command framework for C# developers.

It's based on a simple idea of giving string input to the program and returning a string containing the result of the execution of the command based on the input.

Features

  • Automatic command naming based on method name (overridable by attribute).
  • Automatic conversion and piping of string input to relevant data type(s) based on the command's method parameter.
  • Automatic usage example generation.
  • Automatic command documentation based on method attributes and the method itself.
  • Automatic input splitting based on whitespace, preserves single and double quoted strings.
  • Automatic command dispatching.
  • Includes a default help command.
  • Add custom parameter convertors.
  • Add custom input splitters.
  • Add custom help command.
  • Detailed command documentation with special character sequences.
  • Command groups and nestable commands.
  • Required and optional command parameters, with optional parameters having default value(s).
  • Organizational unit 'Cog' which is a class that contains commands and it can optionally group commands together.
  • Dead simple execution through the program Run method.
  • Error handling.

Installation

TODO

Documentation

TODO

Generated Code Docs

Applications

Commander can be used to implement command systems for games, command line tools, chat bots etc.

It accomplishes this goal by enforcing the input of a command string to the program and forcing all commands to return a string containing the result of the commands' execution.

Quickstart

Below is a simple example of how to use this framework.

/* ExampleCog.cs */
using Commander;

namespace Quickstart {
    public class ExampleCog : Commander.Cog {
        public ExampleCog(Program program) : base(program) {
            /* SETUP CODE HERE */
        }
        
        [Commander.Command(Description="Repeats the given message.")]
        [Commander.Example("@c hello")]
        [Commander.Example("@c 'hello world!'")]
        public string Echo(string message) {
            return message;
        }
        
        [Commander.Command(Description="Adds numbers together.")]
        [Commander.Example("@c 10")]
        [Commander.Example("@c 5 16")]
        public string Add(int a, int b = 10) {
            return (a + b).ToString();
        }
    }
}
/* ExampleProgram.cs */
using Commander;

namespace Quickstart {
    public class ExampleProgram : Commander.Program
    {
        public ExampleProgram() : base("ExampleProgram")
        {
            /* SETUP CODE HERE */
            
            Register(new ExampleCog(this));
        }
        
        public static void Main(string[] args) {
            var program = new ExampleProgram();
            Console.WriteLn(program.Run("ExampleProgram echo 'hello world!'"));
            Console.WriteLn(program.Run("ExampleProgram add 400 20"));
            Console.WriteLn(program.Run("ExampleProgram help"));
            Console.WriteLn(program.Run("ExampleProgram help add"));
        }
    }
}

Examples

TODO

TODO

  • [ ] Finish Unit tests.
  • [ ] Add flag parser.
  • Add argument preprocessor for commands ala discordpy ? E.g.: myFunc(string arg1, int arg2)
  • Add code comments
  • Complete unit tests (current: 85% Coverage)
  • Add code docs
  • Add examples
  • Prettify README.md
  • Add command usage info generation from metadata
  • Add special sequence parser
  • Add input splitter to program
  • Add default help command
  • This all could have gone in a project right?

commander's People

Contributors

howz1t avatar

Watchers

 avatar  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.