Giter Club home page Giter Club logo

jasily.framework.consoleengine's Introduction

Jasily.Framework.ConsoleEngine

a engine/frame for console application

how to use

write a simple console application enter:

namespace xxx
{
    class Program
    {
        static void Main(string[] args)
        {
            var engine = new JasilyConsoleEngine();
            engine.MapperManager.RegistAssembly(Assembly.GetExecutingAssembly());
            using (var session = engine.StartSession())
            {
                while (true)
                {
                    var line = Console.ReadLine() ?? string.Empty;
                    if (line.ToLower() == "exit") return;
                    session.Execute(line);
                }
            }
        }
    }
}

then write a command class:

namespace xxx
{
    [Command("test")]
    public class Command : ICommand
    {
        public void Execute(Session session, CommandLine line)
        {
            session.WriteLine("hello world!");
        }
    }
}

or a command method:

namespace xxx
{
    public class Command // command method don't need interface ICommand
    {
        [Command("test")]
        public void Execute(Session session, CommandLine line)
        {
            session.WriteLine("hello world!");
        }
    }
}

you also can see my demos:

detail

command

class command

class command must implement interface ICommand, it is the command enter point.

class command parameter should be perperty with [PropertyParameter].

method command

method command parameter was method parameter.

if method command parameter without [MethodParameter], it is name will auto fill as parameter name.

you can add or not add build-in parameter Session & CommandLine:

public void Test(Session session, CommandLine line) { .. } // work fine
public void Test(CommandLine line) { .. } // work fine
public void Test(Session session) { .. } // work fine
public void Test() } // work fine

it will be auto fill on execute if type match.

parameter

parameter convert

all parameter input was string, it can convert to another type using converter.

build-in converter was:

  • int, double, decimal
  • bool
  • enum
  • nullable

you can implement you own IConverter<T> and regist it like:

engine.MapperManager.RegistConverter(new BooleanConverter());
  • method command will ignore Type Session and CommandLine, they will auto fill.

alias & desciption

all alias will work for command and help.

desciption will work for help.

you can add alias & desciption for command or parameter, like:

// class command
[Command("test")][Alias("t")][Desciption("docs")]
public class Command : ICommand { ... }

// class parameter
[PropertyParameter("user")][Alias("u")][Desciption("docs")]
public string UserName { get; set;

// method command
[Command("test")][Alias("t")][Desciption("docs")]
public void Feed(
    [MethodParameter("id")][Alias("i")][Desciption("id of subscription")] // method parameter
    int id, Session session, CommandLine line)
{
    Console.WriteLine(subscriptionId);
}

jasily.framework.consoleengine's People

Contributors

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