CliArgumentParser 1.2.1972

Additional Details

Use Always latest version to get patches and bug fixes

There is a newer version of this package available.
See the version list below for details.
dotnet add package CliArgumentParser --version 1.2.1972                
NuGet\Install-Package CliArgumentParser -Version 1.2.1972                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CliArgumentParser" Version="1.2.1972" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CliArgumentParser --version 1.2.1972                
#r "nuget: CliArgumentParser, 1.2.1972"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

Build Status Quality Gate Status Coverage Lines of Code Bugs Vulnerabilities

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last updated
1.3.1.2545 203 4/13/2023
1.2.2182 364 12/2/2022
1.2.2171 310 12/1/2022
1.2.2088 389 11/19/2022 1.2.2088 is deprecated.
1.2.1973 385 11/2/2022 1.2.1973 is deprecated.
1.2.1972 391 11/2/2022 1.2.1972 is deprecated.
1.1.1944 396 11/2/2022 1.1.1944 is deprecated.

- Minor issues solved
- Test Coverage increased
- README file updated with usage details and samples