Skip to content

Commit

Permalink
Added code to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jakenuts committed Dec 31, 2023
1 parent 9b0aed8 commit 67ffde3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
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();
```

0 comments on commit 67ffde3

Please sign in to comment.