using Spectre.Console.Cli.Internal.Configuration;
namespace Spectre.Console.Cli;
///
/// The entry point for a command line application with a default command.
///
/// The type of the default command.
public sealed class CommandApp : ICommandApp
where TDefaultCommand : class, ICommand
{
private readonly CommandApp _app;
private readonly DefaultCommandConfigurator _defaultCommandConfigurator;
///
/// Initializes a new instance of the class.
///
/// The registrar.
public CommandApp(ITypeRegistrar? registrar = null)
{
_app = new CommandApp(registrar);
_defaultCommandConfigurator = _app.SetDefaultCommand();
}
///
/// Configures the command line application.
///
/// The configuration.
public void Configure(Action configuration)
{
_app.Configure(configuration);
}
///
/// Runs the command line application with specified arguments.
///
/// The arguments.
/// The exit code from the executed command.
public int Run(IEnumerable args)
{
return _app.Run(args);
}
///
/// Runs the command line application with specified arguments.
///
/// The arguments.
/// The exit code from the executed command.
public Task RunAsync(IEnumerable args)
{
return _app.RunAsync(args);
}
internal Configurator GetConfigurator()
{
return _app.GetConfigurator();
}
///
/// Sets the description of the default command.
///
/// The default command description.
/// The same instance so that multiple calls can be chained.
public CommandApp WithDescription(string description)
{
_defaultCommandConfigurator.WithDescription(description);
return this;
}
///
/// Sets data that will be passed to the command via the .
///
/// The data to pass to the default command.
/// The same instance so that multiple calls can be chained.
public CommandApp WithData(object data)
{
_defaultCommandConfigurator.WithData(data);
return this;
}
}