-
Notifications
You must be signed in to change notification settings - Fork 11
Home
This is GoCommando, a simple .NET console application library.
It is meant to ease the burden when you want to build console applications that accept commands, where the acceptable set of parameters vary depending on the chosen commands.
A good and popular example of this style of console application is the NuGet command line, which is generally invoked with this pattern:
nuget <command>
where <command>
can be lots of things, and then - depending on which command you have chosen - you will be able to supply additional arguments to that command, like e.g.
nuget pack *.nuspec -OutputDirectory C:\Temp
- Create a new "Console Application"
Install-Package GoCommand -ProjectName <your-console-application>
- In your
Main
method:Go.Run();
(that's it!)
If you run the application now, it will fail with a message saying that there has to be at least one command available. You can now add commands to the program by doing this:
- Add a new class
- Decorate that class with the
CommandAttribute
, e.g. like so:[Command("whatever")]
- Make that class implement
ICommand
If your command needs additional arguments, you add them as properties to the class with the [Parameter(..)]
attribute on them.
That's it 👍 😁