Skip to content

tarikguney/command-core

Repository files navigation

Build Project Coverage Status NuGet version (CommandCore.Library) GitHub

A simple command-line parsing framework that helps create CLI apps using the MVC pattern.

There are many command line parsing libraries out there, but most of them are unnecessarily complicated. Command Core library is built using a well-understood desing pattern: MVC. It cleanly separates the building blocks and makes the CLI development a scalable, extensible, and more importantly simpler endeavor.

Check out WIKI to get started!

Check out the WIKI page to learn more on how to get started with CommandCore!

Release Changelog

Check out this page to see what's changed with every new release: https://github.com/tarikguney/command-core/wiki/Changelog

Quick Look

If you are familar with MVC pattern in any framework, you will find CommandCore very familiar with them. Look at below to see how a simple command like the one below can be represented in your .NET application:

helloworld.exe add --firstname tarik --lastname guney --haslicense -a 33 --id 1 2 3
[VerbName("add", Description="Allows to add a new person to the database.")]
[VerbName("add-person")]
public class Add : VerbBase<AddOptions>
{
    public VerbView Run(){
        return AddView(Options);
    }
}

public class AddView : VerbViewBase<AddOptions>
{
    public override void RenderResponse(){
        Console.WriteLine(
             $"FirstName: {_options!.FirstName}\n" +
             $"Last Name: {_options!.LastName}\n" +
             $"Has License: {_options!.HasLicense}\n" +
             $"Age: {_options.Age}\n" +
             $"Ids: {_options.Ids.Select(a => a.ToString()).Aggregate((a, b) => a + "," + b)}");
    }
}

public class AddOptions : VerbOptionsBase
{
    [OptionName("firstname")]
    [OptionName("fn"), Alias="f")]
    public string FirstName {get;set;}
    
    [OptionName("lastname")]
    public string LastName {get;set;}

    [OptionName("haslicense")]
    public bool? HasLicense {get;set;}
    
    [OptionName("age", Alias="a")]
    public int Age {get;set;}

    [OptionName("id")]
    public List<int> Ids { get; set; }

}

Integrated IoC Container for Dependency Injection

CommandCore comes with an in-house IoC container named CommandCore.LightIoC, and it allows you to register your own services and inject them to the verb classes. Check out this page for more information: Dependency Injection with LightIoC Container

Roadmap

  1. Add routing mechanism, similar to Asp.NET Core MVC. Routing mechanism will help verbs to be routed to a desired class pattern for more complicated scenarios.
  2. Add a middleware, which is similar to Asp.NET Core MVC request/response middleware features, which allows the developers to inject logic between a command is routed to its handling verb (controller).
  3. Caching for faster type lookup. Currently, the entire assembly needs to be scanned for the types that match the verb. A caching mechanism can store away the detected types for faster retrival next time.

Developed

by Tarik Guney with .NET Core 3.x.