-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
# Community.Extensions.Spectre.Cli.Hosting | ||
Extension methods and a bit of fancy footwork to host Spectre.Console.Cli in a HostApplicationBuilder | ||
|
||
``` | ||
var builder = Host.CreateApplicationBuilder(args); | ||
// Add a command and optionally configure it. | ||
builder.Services.AddCommand<HelloCommand>("hello", cmd => | ||
{ | ||
cmd.WithDescription("A command that says hello"); | ||
}); | ||
// Add another command and its dependent service | ||
builder.Services.AddCommand<OtherCommand>("other"); | ||
builder.Services.AddScoped(s => new SampleService("Other Service")); | ||
// | ||
// The standard call save for the commands will be pre-added & configured | ||
// | ||
builder.UseSpectreConsole<HelloCommand>(config => | ||
{ | ||
// All commands above are passed to config.AddCommand() by this point | ||
#if DEBUG | ||
config.PropagateExceptions(); | ||
config.ValidateExamples(); | ||
#endif | ||
config.SetApplicationName("hello"); | ||
config.UseBasicExceptionHandler(); | ||
}); | ||
var app = builder.Build(); | ||
await app.RunAsync(); | ||
``` |