boriswilhelms / advancedconsoleapptemplate Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.