CodeOfChaos.CliArgsParser.Generators
3.0.3-preview.6
See the version list below for details.
dotnet add package CodeOfChaos.CliArgsParser.Generators --version 3.0.3-preview.6
NuGet\Install-Package CodeOfChaos.CliArgsParser.Generators -Version 3.0.3-preview.6
<PackageReference Include="CodeOfChaos.CliArgsParser.Generators" Version="3.0.3-preview.6"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add CodeOfChaos.CliArgsParser.Generators --version 3.0.3-preview.6
#r "nuget: CodeOfChaos.CliArgsParser.Generators, 3.0.3-preview.6"
// Install CodeOfChaos.CliArgsParser.Generators as a Cake Addin #addin nuget:?package=CodeOfChaos.CliArgsParser.Generators&version=3.0.3-preview.6&prerelease // Install CodeOfChaos.CliArgsParser.Generators as a Cake Tool #tool nuget:?package=CodeOfChaos.CliArgsParser.Generators&version=3.0.3-preview.6&prerelease
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.
dotnet add package CliArgsParser --version 2.2.7
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
andArgFlag
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 aIServiceCollection
, by using theCliParser.CreateStandalone()
orArgsParser.CreateStandalone()
methods.
F.A.Q:
"I tried to create a atlas with async commands, but they did not execute when called"
This is due to the parser trying to execute the commands as non-async, because the parser was most likely called without using the async methods. To resolve this, always run the parsers through their async methods.
Quick Start
The following section is a basic example on how to get started with CliArgsParser. For in-code examples, they can be found in the repo under examples : https://github.com/code-of-chaos/CliArgsParser-cs/tree/core/examples
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 {
Overridable = true,
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 | 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 | 70 | 12/23/2024 |
4.2.0 | 73 | 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 | 38 | 12/17/2024 |
3.0.3-preview.4 | 46 | 12/17/2024 |