CliArgsParser 2.0.0

Suggested Alternatives

CodeOfChaos.CliArgsParser

There is a newer version of this package available.
See the version list below for details.
dotnet add package CliArgsParser --version 2.0.0                
NuGet\Install-Package CliArgsParser -Version 2.0.0                
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="CliArgsParser" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CliArgsParser --version 2.0.0                
#r "nuget: CliArgsParser, 2.0.0"                
#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 CliArgsParser as a Cake Addin
#addin nuget:?package=CliArgsParser&version=2.0.0

// Install CliArgsParser as a Cake Tool
#tool nuget:?package=CliArgsParser&version=2.0.0                

CLIArgsParser

CLIArgsParser is a library built around Dependency Injection to allow you to create CLI tools with ease. This is particularly useful in scenarios where your application requires a large amount of commands, with specific arguments.

Features

Here are the key features of CLI Args Parser:

  • Command Declaration and Registration: Commands are declaratively defined within a class using the ICommandAtlas interface. This arrangement provides a well-structured, easy-to-maintain way of defining and locating command handling logic.
  • Asynchronous Command Execution: CLIArgsParser allows for asynchronous execution of commands. This can provide major performance benefits, especially when commands involve IO-bound operations. The library also exposes the ArgsParser.ParseAsyncParallel method for parallel async execution of cli tools.
  • Argument Mapping: CLIArgsParser allows property-based argument mapping. Properties of a class implementing the ICommandParameters interface can be used as the target of argument mapping from command line input. Argument mapping is further simplified through the use of the ArgValue and ArgFlag attributes which takes the argument name as a parameter.
  • Dependency Injection approach: The library is built around using DI in your workflow. ICommandAtlas classes allow constructors to fully utilize dependency injection. Yet you are not required to have a IServiceCollection, by using the CliParser.CreateStandalone() or ArgsParser.CreateStandalone() methods.

Quick Start

The following is a basic example on how to get started with CLIArgsParser:

Dependency Injected approach

using CliArgsParser;

// Define a class for mapping arguments
public class ArgsTest : ICommandParameters  {
    [ArgValue("name"), Description("Defines the name of the user")] 
    public string Name { get; set; } = "Default Name";
}

public class MyAppCommands : ICommandAtlas {
    [Command("hello"), Description("Greets everyone")]
    public void CommandHello() {
        Console.Writeline("Hello there!");    
        /* Or your command' implementation, without arguments, goes here... */
    }

    [Command<ArgsTest>("greet"), Description("Greets you specificly")]
    public void CommandGreet(ArgsTest argsTest)  {
        Console.Writeline($"Hello there and welcome, {argsTest.Name}");  
        /* Or Your command implementation goes here... */
    }
}

internal static class Program {
    public async static Task Main(string[] args) {
        IServiceCollection serviceCollection = new ServiceCollection();

        serviceCollection.AddCliArgsParser(configuration =>
            configuration
                .SetConfig(new CliArgsParserConfig(
                    generateShortNames: true
                ))
                .AddFromType<HelloAtlas>()
        );
        
        ServiceProvider provider = serviceCollection.BuildServiceProvider();
        
        var cliParser =  provider.GetRequiredService<ICliParser>();
        await cliParser.StartParsingAsync();
    }
}

Standalone Approach

using CliArgsParser;

// Define a class for mapping arguments
public class ArgsTest : ICommandParameters  {
    [ArgValue("name"), Description("Defines the name of the user")] 
    public string Name { get; set; } = "Default Name";
}

public class MyAppCommands : ICommandAtlas {
    [Command("hello"), Description("Greets everyone")]
    public void CommandHello() {
        Console.Writeline("Hello there!");    
        /* Or your command' implementation, without arguments, goes here... */
    }

    [Command<ArgsTest>("greet"), Description("Greets you specificly")]
    public void CommandGreet(ArgsTest argsTest)  {
        Console.Writeline($"Hello there and welcome, {argsTest.Name}");  
        /* Or Your command implementation goes here... */
    }
}

internal static class Program {
    public async static Task Main(string[] args) {
        ICliParser parser = CliParser.CreateStandalone(
            configuration =>
                configuration
                    .SetConfig(new CliArgsParserConfig(
                        overridable: true,
                        generateShortNames: true
                    ))
                    .AddFromType<HelloAtlas>()
        );
        await cliParser.StartParsingAsync();
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.

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
2.1.2 152 8/27/2024 2.1.2 is deprecated because it is no longer maintained.
2.1.1 90 8/27/2024 2.1.1 is deprecated because it is no longer maintained.
2.0.0 87 8/27/2024 2.0.0 is deprecated because it is no longer maintained.
1.1.3 134 6/13/2024 1.1.3 is deprecated because it is no longer maintained.
1.1.2 94 6/8/2024 1.1.2 is deprecated because it is no longer maintained.
1.1.1 123 6/6/2024 1.1.1 is deprecated because it is no longer maintained.
1.1.0 95 6/6/2024 1.1.0 is deprecated because it is no longer maintained.
1.0.5 126 5/8/2024 1.0.5 is deprecated because it is no longer maintained.
1.0.4 102 5/6/2024 1.0.4 is deprecated because it is no longer maintained.
1.0.3 103 5/6/2024 1.0.3 is deprecated because it is no longer maintained.
1.0.2 105 5/6/2024 1.0.2 is deprecated because it is no longer maintained.
1.0.1 106 5/5/2024 1.0.1 is deprecated because it is no longer maintained.
1.0.0 97 5/5/2024 1.0.0 is deprecated because it is no longer maintained.
0.6.0-preview-202404091715 90 4/9/2024 0.6.0-preview-202404091715 is deprecated because it is no longer maintained.
0.6.0-preview-202404091708 79 4/9/2024 0.6.0-preview-202404091708 is deprecated because it is no longer maintained.
0.6.0-preview-202404091651 77 4/9/2024 0.6.0-preview-202404091651 is deprecated because it is no longer maintained.
0.5.6 114 2/19/2024 0.5.6 is deprecated because it is no longer maintained.
0.4.0 114 2/14/2024 0.4.0 is deprecated because it is no longer maintained.
0.3.1 118 2/7/2024 0.3.1 is deprecated because it is no longer maintained.
0.2.0 102 2/6/2024 0.2.0 is deprecated because it is no longer maintained.
0.1.8 101 2/6/2024 0.1.8 is deprecated because it is no longer maintained.
0.1.7 99 2/6/2024 0.1.7 is deprecated because it is no longer maintained.
0.1.6 96 2/6/2024 0.1.6 is deprecated because it is no longer maintained.
0.1.5 101 2/6/2024 0.1.5 is deprecated because it is no longer maintained.
0.1.3 103 2/5/2024 0.1.3 is deprecated because it is no longer maintained.