GithubHelp home page GithubHelp logo

bubdm / argumentsparser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from olegd/argumentsparser

0.0 0.0 0.0 4.08 MB

A better way to route command line arguments to methods that should handle them

C# 100.00%

argumentsparser's Introduction

Arguments Parser

Arguments parser helps wire command line arguments to the methods that should handle them.

Example:

You are designing a program that should support merge command, should take an argument named branchName and an optional force flag

This is how you are picturing it beeing called:

coolutil.exe merge myNewBranch force


public class CommandHandler
{
    [Command]
    public void Merge(string branchName, bool force)
    {         
    }
}

static void Main(string[] args)
{
    var router = new Router();
    router.Route(args);
}

ArgumentsParser assumes a convention that Handler Methods are names after commands: if console application takes merge as a first argument, by convention, argument parser will try to find handler method named Merge (case insensitive)

You can override this convention by providing a Name argument to the CommandAttribute:

public class CommandHandler
{
    [Command(Name="merge")]
    public void AnyMethodName(string branchName, bool force)
    {         
    }
}

Dependency Injection support

Arguments parser supports Common Service Locator:

Call DependencyResolver.SetRosolver with your favourite dependency injection repository and ArgumentParser will inject the dependencies from the ServiceLocator, when constructing handler objects:

DependencyResolver.SetResolver(new StructureMapServiceLocator());

Alternativelly, you can implement IDependencyResolver interface to provide mapping for dependency resoltion to any dependency injection framework and register it with DependencyResolver:

public class StructureMapDependencyResolver : IDependencyResolver
{
    public object GetService(Type serviceType)
    {
        return ObjectFactory.GetInstance(serviceType);
    }
}

 DependencyResolver.SetResolver(new StructureMapDependencyResolver());

=======

argumentsparser's People

Contributors

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