Wolfe.FluentCli
0.10.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Wolfe.FluentCli --version 0.10.0
NuGet\Install-Package Wolfe.FluentCli -Version 0.10.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="Wolfe.FluentCli" Version="0.10.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Wolfe.FluentCli --version 0.10.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Wolfe.FluentCli, 0.10.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 Wolfe.FluentCli as a Cake Addin #addin nuget:?package=Wolfe.FluentCli&version=0.10.0 // Install Wolfe.FluentCli as a Cake Tool #tool nuget:?package=Wolfe.FluentCli&version=0.10.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Wolfe.FluentCli
A .NET 5 Fluent API for creating command line interfaces.
Usage
Building the CLI
var cli = FluentCliBuilder.Create()
// The handler that runs when no command is specified.
.WithDefaultCommand<DefaultCommandHandler>()
.AddCommand<HelloCommandHandler>("hello", command => command
// Options are bound automatically based on property names in snake case.
.WithOptions<HelloCommandOptions>()
// Commands can be nested infinitely
.AddCommand<FooCommandHandler>("foo")
)
.Build();
Defining Handlers
// Implement ICommandHandler when you don't have any options.
public class DefaultCommandHandler : ICommandHandler
{
public Task Execute()
{
Console.WriteLine($"Default Handler");
return Task.CompletedTask;
}
}
public class HelloCommandOptions
{
public string FirstName { get; set; }
}
// Implement ICommandHandler<TOptions> when you have configuration.
public class HelloCommandHandler : ICommandHandler<HelloCommandOptions>
{
public Task Execute(HelloCommandOptions options)
{
Console.WriteLine($"Hello {options.FirstName}!");
return Task.CompletedTask;
}
}
public class FooCommandHandler : ICommandHandler
{
public Task Execute()
{
Console.WriteLine("Foo");
return Task.CompletedTask;
}
}
Executing Commands
// Executes the default command handler
await cli.Execute("");
// Executes the hello command, setting HelloCommandOptions.FirstName to 'Tom'
await cli.Execute("hello --first-name Tom");
// Executes the foo subcommand.
await cli.Execute("hello foo");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.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.