CommandLineParser80 1.0.0
CommandLineParser80
CommandLineParser and associated test app, unit tests and packages.
Publishing
Build the project. From the repository root, push the .nupkg file to the NuGet server.
dotnet nuget push -s https://nuget.pillidar.com/v3/index.json .\source\CommandLineParser80\bin\debug\CommandLineParser80.1.0.0.nupkg -k <security_key_goes_here>
Usage
Input
You'll need an ICommandLineProvider to provide input. The normal provider for an application is the EnvironmentCommandLineProvider class. The normal provider for unit tests is the ListCommandLineProvider.
The provided ICommandLineProvider implementations are:
- EnvironmentCommandLineProvider
- MainArgsCommandLineProvider
- ListCommandLineProvider
Parsers
There are different ICommandLineParsers available. The one you choose usually depends on your operating system or your command line shell.
- WindowsCmdTokenParser - a token parser that handles DOS/Windows (CMD)-style command lines.
- LinuxTokenParser - a token parser that handles Linux-style command lines.
- PowerShellTokenParser - a token parser that handles PowerShell-style command lines.
- UniversalTokenParser - a hybrid parser that handles some CMD and Linux-style aspects.
WindowsCmdTokenParser
This parser handles these kinds of parameters:
/switch
/switch:value
/switch=value
-switch
-switch:value
-switch=value
--switch
--switch:value
--switch=value
paramvalue
LinuxTokenParser
This parser handles these kinds of parameters:
-s (shorthand parameter)
-abcd (flags a, b, c, and d)
--switch (long-form parameter, such as an equivalent to -s)
-switch=value
--switch=value
paramvalue
PowerShellTokenParser
This parser handles these kinds of parameters:
-switch
-switch:value
-switch=value
paramvalue
UniversalTokenParser
This parser handles these kinds of parameters:
-switch
--switch
paramvalue
Tokens
Parsers accept an array of parameters. There is no mechanism in this library to tokenize a command line because .NET always provides the command lines pre-tokenized for you. If you want this functionality, use this in combination with a tokenizing library.
When a parser parses an array of parameters, it produces a list of CommandLineToken objects.
The CommandLineToken class has these concepts:
- Switch - A single parameter whose existence indicates that a value is "on" and whose absence indicates "off". Switches can also be name/value pairs when specified as a colon-delimited token.
- Parameter - A single value. This may be treated as a switch by the application, but not by this library. A parameter may be treated by the application as a key or a value in a key/value pair.
The
The CommandLineToken Class
To Do
The WindowsTokenParser should be broken out into a CmdTokenParser and a PowerShellTokenParser. It makes no sense to cram both into a single parser.
The LinuxTokenParser does not support flags. That should be fixed.
No packages depend on CommandLineParser80.
.NET 8.0
- No dependencies.