Giter VIP home page Giter VIP logo

advancedconsoleapptemplate's People

Contributors

boriswilhelms avatar

Stargazers

 avatar

Watchers

 avatar  avatar

advancedconsoleapptemplate's Issues

thoughts ... parsing the command line.

I stumbled accross your blog post whilst googling the console logger.

Great blog, great idea.

I have followed your template but I have a question on handling command line arguments.

Right now I use the nuget package CommandLineParser which works well for NON DI console apps.

I was pondering the best way use the CommandLineParser with DI and I was wondering if its a problem you have already solved.

This is my first run at the code, tbh, I dont like it, it would be nice if the command line parser could direct the program at the right class, a little bit like MVC routes.

eg, you do

Console1.exe dothinga

this routes to dothinga class

and

Console1.exe dootherthing

this could route to the dootherthing class

This is my first version of the code, no routing just loads the params via IOptions interface

private static void AppyArguments(IServiceCollection services, string[] args)
{
    var result = Parser.Default.ParseArguments<CreateFolderOptions>(args);
    result.MapResult(
        sourceOptions =>
        {
            services.Configure<FileshareConfigurationOptions>((o) =>
            {
                o.DestRootPath = sourceOptions.BaseFolder;
                o.SourcePath = sourceOptions.ExcelSpreadSheet;
            });
            return 0;
        },
        errs => 1); // when the parse fails, this gets fired.
}

To be honest, maybe routing to an entire class may be to much, maybe just route to the right method on Program, you could use reflection to determine the correct method eg

...
class Program
{
public VerbA( OptionsForVerbA options)
public VerbB( OptionsForVerbB options)
}
..

it would be easy to reflect the class and find the method that lets you pass OptionForVerbA as a parameter.

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.