Ploch.CommandLine.UseCases
1.0.51
dotnet add package Ploch.CommandLine.UseCases --version 1.0.51
NuGet\Install-Package Ploch.CommandLine.UseCases -Version 1.0.51
<PackageReference Include="Ploch.CommandLine.UseCases" Version="1.0.51" />
<PackageVersion Include="Ploch.CommandLine.UseCases" Version="1.0.51" />
<PackageReference Include="Ploch.CommandLine.UseCases" />
paket add Ploch.CommandLine.UseCases --version 1.0.51
#r "nuget: Ploch.CommandLine.UseCases, 1.0.51"
#:package Ploch.CommandLine.UseCases@1.0.51
#addin nuget:?package=Ploch.CommandLine.UseCases&version=1.0.51
#tool nuget:?package=Ploch.CommandLine.UseCases&version=1.0.51
Ploch.CommandLine.UseCases
Use-case abstractions for command-line applications built with
Ploch.CommandLine.Spectre. Keep the work in a
use case: IUseCase<TRequest, TResponse> is the general abstraction, and
IResultUseCase<TRequest, TResponse> is the variant whose response is an
Ardalis.Result.
UseCaseAsyncCommand runs an IResultUseCase from a command: it turns the command settings into a
request, runs the use case, reports a failed result's errors and validation errors, and maps the result
to an exit code. On success it prints a completion message; override ProcessSuccessResponse to render
the response value itself.
Installation
dotnet add package Ploch.CommandLine.UseCases
Example
using Ardalis.Result;
using Ploch.CommandLine.Spectre.Commands;
using Ploch.CommandLine.Spectre.Output;
using Ploch.CommandLine.UseCases;
using Spectre.Console.Cli;
public record GreetRequest(string Name);
public class GreetUseCase : IResultUseCase<GreetRequest, string>
{
public Task<Result<string>> ExecuteAsync(GreetRequest request, CancellationToken cancellationToken = default) =>
Task.FromResult(Result.Success($"Hello, {request.Name}!"));
}
public class GreetSettings : CommandSettings
{
[CommandOption("-n|--name")]
public string Name { get; set; } = "world";
}
public class GreetCommand(IOutput output,
GreetUseCase useCase,
CommandArgumentsRootProcessor settingsProcessor,
ICommandSettingsValidator<GreetSettings> validator,
IExceptionHandler exceptionHandler)
: UseCaseAsyncCommand<GreetSettings, GreetUseCase, GreetRequest, string>(output, useCase, settingsProcessor, validator, exceptionHandler)
{
protected override GreetRequest CreateRequest(GreetSettings settings) => new(settings.Name);
}
Register the use case in the container and the command with ConfigureCommandApp, exactly as for any
other command.
Documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Ardalis.Result (>= 10.1.0)
- Ploch.CommandLine.Spectre (>= 1.0.51)
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 |
|---|---|---|
| 1.0.51 | 76 | 10/30/2026 |