Table of Contents

Method Create

Namespace
Ploch.CommandLine.Spectre
Assembly
Ploch.CommandLine.Spectre.dll

Create(params IEnumerable<string>)

Creates a new instance of the AppBuilder class with the specified arguments.

public static AppBuilder Create(params IEnumerable<string> args)

Parameters

args IEnumerable<string>

The command-line arguments to initialize the application.

Returns

AppBuilder

A new instance of AppBuilder.

Remarks

This also installs a CancelKeyPress handler and creates the CancellationTokenSource the application cancels through. The first Ctrl+C cancels that source cooperatively, so a command honouring its CancellationToken can stop and tidy up; a second Ctrl+C takes the default path and terminates the process, so a command that ignores its token never leaves the application unkillable from the keyboard.

The source is registered in the container, so a command can resolve it to request shutdown itself.

The returned builder owns both the source it creates and the handler it installs, and releases them on Dispose(). Dispose it once the application has finished running — the cancellation token stays live for the whole run, so an earlier scope exit would release the source and the handler while the run still needs them. The handler also detaches itself once an interrupt has been handled, so an interrupted application releases the subscription without waiting for disposal.