CliArgumentParser 1.2.1972
Use Always latest version to get patches and bug fixes
See the version list below for details.
dotnet add package CliArgumentParser --version 1.2.1972
NuGet\Install-Package CliArgumentParser -Version 1.2.1972
<PackageReference Include="CliArgumentParser" Version="1.2.1972" />
paket add CliArgumentParser --version 1.2.1972
#r "nuget: CliArgumentParser, 1.2.1972"
// Install CliArgumentParser as a Cake Addin #addin nuget:?package=CliArgumentParser&version=1.2.1972 // Install CliArgumentParser as a Cake Tool #tool nuget:?package=CliArgumentParser&version=1.2.1972
CLIArgumentsParser
Library to easily manage and parse CLI arguments
Current Version: <b>Stable - 1.1.1944</b>: branch MASTER
To install it, use proper command:
dotnet add package CliArgumentParser --version 1.1.1944
Main Features
- define a model of usage for your CLI applications
- Automatic parse and validation of your arguments against the defined model
- Add examples of usage
- Print automatic helper on CLI usage
How to define an Usage Model
To define you model, create a class inheriting from CliCommand one.
class ScanCommand : CliCommand
{
public ScanCommand() : base("scan", "Scan the target folder tree")
{}
}
Remember to:
- define the method SetDefaultValues to fill rpoper option dictionary
- define the properties of command, with decorators (see the paragraph)
- define examples
Option Definition
All properties you add should map an option of the verb, such:
[Option(OPT_FOLDER, "Root folder to scan", isMandatory: true)]
public string Folder
{
get { return this.GetArgumentValue<ScanCommand, string>(x => x.Folder); }
set { this.AddOrUpdateArgument<ScanCommand, string>(x => x.Folder, value); }
}
Then, remember to parse the string argument:
public override void ParseArgument(string[] tokens)
{
// take the expecetd value
if (tokens.Length == 1)
{
throw new NotImplementedException();
}
else
{
// validate option
switch (tokens[0])
{
case OPT_FOLDER:
case OPT_FILENAME_SEARCH_PATTERN:
case OPT_FILECONTENT_SEARCH_PATTERN:
this.UpdateArgumentValue(tokens[0], tokens[1]);
break;
case OPT_TO:
this.PersistedTo = tokens[1].Trim().ToUpperInvariant();
break;
default:
throw new WrongOptionUsageException(this.Verb, tokens[0]);
}
}
}
How to define examples
Each command shold contain a list of example, to understand how to use it. So far, you have to complete the abstract method:
public override List<CliCommandExample> Examples()
{
return new List<CliCommandExample>()
{
new CliCommandExample("Scan the target folder to search *.csproj Files, containing the text \"NugetPackages\" and save a CSV files with output",
ScanCommand.AsExampleFor(@"C:\Temp\MyFolder", ".csproj", @"\NugetPackages\", "CSV"))
};
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Minor issues solved
- Test Coverage increased
- README file updated with usage details and samples