This is a starting point for creating neatly structured .NET Core console apps
in C#, using the Microsoft.Extensions.CommandLineUtils
package to parse the
commands.
I created this working as a student with 4DVision, who create custom software for complex processes of companies and organizations.
GreetCommand
is an example of a command, see Commands/GreetCommand.cs
.
- Create a new class for your command, eg.
Commands.ListCommand
- Register the command in the
RootCommand
like this:
app.Command("list", c => ListCommand.Configure(c, options));
- Profit!
IsEnthousiastic
is an example of a global option.
- Add the property to
CommandLineOptions
- Add a call to
app.Option
orapp.Argument
inCommandLineOptions.Parse
and store the result - Store the property in
options
at the bottom ofCommandLineOptions.Parse