Chase.CLIParser 0.0.4

Suggested Alternatives

cclip.net

Additional Details

renamed package to cclip.net (C# Command Line Interface Parser for .Net)

dotnet add package Chase.CLIParser --version 0.0.4                
NuGet\Install-Package Chase.CLIParser -Version 0.0.4                
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="Chase.CLIParser" Version="0.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chase.CLIParser --version 0.0.4                
#r "nuget: Chase.CLIParser, 0.0.4"                
#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 Chase.CLIParser as a Cake Addin
#addin nuget:?package=Chase.CLIParser&version=0.0.4

// Install Chase.CLIParser as a Cake Tool
#tool nuget:?package=Chase.CLIParser&version=0.0.4                

Chase CLI Parser Documentation

Introduction

The Chase CLI Parser library is a lightweight command-line argument parsing tool for .NET applications. It simplifies the process of parsing command-line arguments and provides an easy-to-use interface for defining and handling command-line options.

This documentation will guide you through using the Chase CLI Parser library to define and parse command-line arguments in your .NET application.

Installation

Before you can start using the Chase CLI Parser library, you need to include it in your .NET project. You can do this by adding a reference to the Chase CLIParser.dll assembly in your project.

Using NuGet Package Manager

You can also install the Chase CLI Parser library using NuGet Package Manager:

Install-Package Chase-CLI-Parser

Usage

Initializing the OptionsManager

To get started with Chase CLI Parser, you first need to create an OptionsManager object to define the command-line options that your application will accept.

OptionsManager manager = new OptionsManager("Chase CLI Parser");

Adding Command-Line Options

You can add command-line options to the OptionsManager using the Add method. Each option is defined by an OptionDefinition object, which specifies its short name, long name, whether it has an argument, whether it is required, and a description.

manager.Add(new OptionDefinition()
{
    ShortName = "i",
    LongName = "input",
    HasArgument = true,
    Required = true,
    Description = "The input file."
});

manager.Add(new OptionDefinition()
{
    ShortName = "o",
    LongName = "output",
    HasArgument = true,
    Required = true,
    Description = "The output file."
});

manager.Add(new OptionDefinition()
{
    ShortName = "c",
    LongName = "continue",
    HasArgument = false,
    Required = false,
    Description = "Continue the application."
});

manager.Add(new OptionDefinition()
{
    ShortName = "cc",
    LongName = "connections",
    HasArgument = true,
    Required = false,
    Description = "The number of connections of the application."
});

Parsing Command-Line Arguments

Once you've defined your command-line options, you can use the OptionsParser to parse the command-line arguments passed to your application.

OptionsParser parser = manager.Parse(Environment.GetCommandLineArgs());

Checking for Option Presence

You can check if a specific option is present in the parsed arguments using the IsPresent method of the OptionsParser. It also allows you to retrieve the value of an option with an argument.

if (parser.IsPresent("i", out string input))
{
    Console.WriteLine($"Input file is {input}");
}

if (parser.IsPresent("o", out string output))
{
    Console.WriteLine($"Output file is {output}");
}

if (parser.IsPresent("c"))
{
    Console.WriteLine("Continue is enabled");
}
else
{
    Console.WriteLine("Continue is disabled");
}

if (parser.IsPresent("cc", out string connections))
{
    Console.WriteLine($"Connections set to {connections}");
}
else
{
    Console.WriteLine($"Connections set to 6");
}

Example

Here's an example of how you can use Chase CLI Parser in your .NET application:

using System;

class Program
{
    static void Main(string[] args)
    {
        OptionsManager manager = new OptionsManager("Chase CLI Parser");

        // Define command-line options here

        OptionsParser parser = manager.Parse(args);

        if (parser.IsPresent("i", out string input))
        {
            Console.WriteLine($"Input file is {input}");
        }

        // Check other options here

        // Your application logic goes here
    }
}

Conclusion

The Chase CLI Parser library simplifies the process of parsing command-line arguments in your .NET application. By defining and parsing options using the OptionsManager and OptionsParser, you can easily handle command-line arguments and build more user-friendly command-line interfaces for your applications.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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.
  • net7.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
0.0.4 189 9/1/2023 0.0.4 is deprecated.

fixed formatting for help screen