CLArgs - A dotnet command-line parser
Documentation
CLArgs is a full featured, easy to use command-line parser for dotnet applications.
Reference the CLArgs NuGet Package in your console project
and modify your void Main()
method like this:
That is all you have to do to get support for
Application.exe [Verbs] [Options] [Targets]
Verbs - represent different actions / commands your application can execute.
Options - represent the options / parameters which a Command (verb) may need to run.
Targets - represent addition information, like a list of files.
Commander
The Commander will look for Command implementations (classes annotated with [Command( <CommandName=Veb>)]
and it will execute the Command that matches the Verb provided in that command-line.
Imagine > YourApp.exe ConverToUTC --option1
. The provided Verb is ConverToUTC
and Commander will look for a class annotated with [Command( "ConverToUTC"].
Command
Commands represent the functionality of your application. Your Console application can have one or many Commands, even distributed in many Assemblies. The Verb(s) - provided in command-line during run-time - define which Command will finally be executed.
Note: If you don't provide a Verb in the command-line Commander executes the first Command it can find (see Command Resolution). This is perfectly fine for apps which have only one single functionality - as normal console apps have only one single
void main()
.
Normally a Command takes the code that you would have implemented in your Main
method. However, a Command does not deal with string[] args
anymore, it executes with Command Parameters.
Check out the first example on GitHub 'ConvertToUTC'.
Plug-In Concept
It is important to notice, that you can extend your application at any time by simply adding new Commands. Commands are atomic and they have no dependency on the environment where they are running. Just implement another Command class and give it a name (a Verb). Add the Command's Assembly to your application bin folder. And you're done! With the very next start of your console application your application supports another Command/Verb (see Command Resolution).
What's next
Last updated