Declarative syntax for System.CommandLine via attributes (a new project) #2310
calacayir
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
System.CommandLine is a very good parser but you need a lot of boilerplate code to get going and the API is hard to discover. This becomes complicated to newcomers and also you would have a lot of ugly code in your Program.cs to maintain. What if you had an easy class-based layer combined with a good parser?
DotMake Command-Line comes to the rescue!
DotMake.CommandLine is a library which provides declarative syntax for System.CommandLine via attributes for easy, fast, strongly-typed (no reflection) usage. The library includes a source generator which automagically converts your classes to CLI commands and properties to CLI options or CLI arguments.
Usage
Create a simple class like this:
In Program.cs, add this single line:
And that's it! You now have a fully working command-line app. You just specify the name of your class which represents your root command to
Cli.Run<>
method and everything is wired.If you want to go async, just use this:
You get this result:
Easy!
Beta Was this translation helpful? Give feedback.
All reactions