CodeOfChaos.CliArgsParser.Generators
4.2.1
dotnet add package CodeOfChaos.CliArgsParser.Generators --version 4.2.1
NuGet\Install-Package CodeOfChaos.CliArgsParser.Generators -Version 4.2.1
<PackageReference Include="CodeOfChaos.CliArgsParser.Generators" Version="4.2.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add CodeOfChaos.CliArgsParser.Generators --version 4.2.1
#r "nuget: CodeOfChaos.CliArgsParser.Generators, 4.2.1"
// Install CodeOfChaos.CliArgsParser.Generators as a Cake Addin #addin nuget:?package=CodeOfChaos.CliArgsParser.Generators&version=4.2.1 // Install CodeOfChaos.CliArgsParser.Generators as a Cake Tool #tool nuget:?package=CodeOfChaos.CliArgsParser.Generators&version=4.2.1
CodeOfChaos.CliArgsParser
Overview
CodeOfChaos.CliArgsParser is a library designed to simplify the process of creating command-line applications in .NET projects. It provides developers with attributes, structures, and tools to quickly define, parse, and execute CLI commands with minimal boilerplate code. The library is focused on flexibility, clarity, and ease of use, utilizing C#'s powerful features like attributes and partial classes.
Features
- Easy Command Definition: Define commands using attributes like
[CliArgsCommand]
and[CliArgsParameter]
directly in your application. - Automatic Parsing: Command-line arguments are parsed and mapped to parameters automatically.
- Description Metadata: Add meaningful descriptions to commands and parameters using
[CliArgsDescription]
for better documentation. - Support for Flags and Complex Types: Easily handle flags, strings, arrays, and even optional/default values.
- Asynchronous Execution: Built-in support for asynchronous methods to handle complex operations.
Getting Started
To use CodeOfChaos.CliArgsParser in your project, follow these steps:
1. Install the Library
Add the library to your project via NuGet:
dotnet add package CodeOfChaos.CliArgsParser
2. Define a Command
Commands are defined as partial classes and annotated with metadata. For example:
[CliArgsCommand("example")]
[CliArgsDescription("This is a test command")]
public partial class ExampleCommand : ICommand<ExampleCommandParameters> {
public async Task ExecuteAsync(ExampleCommandParameters parameters) {
Console.WriteLine($"Running example command with TestValue: {parameters.TestValue}");
if (parameters.Verbose) {
Console.WriteLine("Verbose mode enabled.");
}
await Task.Delay(100); // Simulating async work
}
}
3. Define Parameters
Parameters for a command are defined using partial structs with annotated attributes:
public readonly partial struct ExampleCommandParameters : IParameters
{
[CliArgsParameter("test", "t")]
[CliArgsDescription("A required test parameter")]
public required string TestValue { get; init; }
[CliArgsParameter("verbose", "v", ParameterType.Flag)]
[CliArgsDescription("Enable verbose logging")]
public bool Verbose { get; init; }
[CliArgsParameter("optional-parameter", "o")]
[CliArgsDescription("An optional parameter")]
public string? OptionalValue { get; init; } = "default";
}
4. Register and Run Commands
Typically, this is performed in your Program.cs
or entry point:
using CodeOfChaos.CliArgsParser;
CliArgsParser parser = CliArgsBuilder.CreateFromConfig(
config => {
config.AddCommand<ExampleCommand>();
}
).Build();
await parser.ParseAsync(args);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.Common (>= 4.12.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.12.0)
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 |
---|---|---|
4.2.1 | 69 | 12/23/2024 |
4.2.0 | 72 | 12/22/2024 |
4.1.0 | 76 | 12/22/2024 |
4.0.0 | 73 | 12/22/2024 |
4.0.0-preview.8 | 38 | 12/22/2024 |
3.0.3-preview.8 | 45 | 12/21/2024 |
3.0.3-preview.7 | 41 | 12/21/2024 |
3.0.3-preview.6 | 39 | 12/18/2024 |
3.0.3-preview.5 | 37 | 12/17/2024 |
3.0.3-preview.4 | 45 | 12/17/2024 |