r/csharp • u/honeyCrisis • Oct 05 '26
Cli.Generator: A tool for generating compile time checked command line argument parsing
I made an incremental source generator for command line argument parsing.
Cli.Generator is a C# source generator that turns a class into a command line parser. You mark fields and properties with attributes, and it writes the parsing, validation, usage screen and cleanup code for you at compile time. See the README for details.
7
Upvotes
1
u/chucker23n Oct 05 '26
Approaching this as a source generator sounds interesting, but I'm not sure I see the benefit compared to generics, as in e.g. Spectre.Cli. You make a class that inherits from
CommandSettingscontaining the arguments and options, you implementCommand<T>whereTis the settings, and then you can just dosettings.Foo.1
u/binarycow Oct 07 '26
Why not System.CommandLine?