mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-07-01 10:28:16 +08:00
Add possibility to set description and/or data for the default command (#1091)
This commit is contained in:
@ -25,11 +25,12 @@ internal sealed class Configurator : IUnsafeConfigurator, IConfigurator, IConfig
|
||||
Examples.Add(args);
|
||||
}
|
||||
|
||||
public void SetDefaultCommand<TDefaultCommand>()
|
||||
public ConfiguredCommand SetDefaultCommand<TDefaultCommand>()
|
||||
where TDefaultCommand : class, ICommand
|
||||
{
|
||||
DefaultCommand = ConfiguredCommand.FromType<TDefaultCommand>(
|
||||
CliConstants.DefaultCommandName, isDefaultCommand: true);
|
||||
return DefaultCommand;
|
||||
}
|
||||
|
||||
public ICommandConfigurator AddCommand<TCommand>(string name)
|
||||
|
@ -0,0 +1,36 @@
|
||||
namespace Spectre.Console.Cli.Internal.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Fluent configurator for the default command.
|
||||
/// </summary>
|
||||
public sealed class DefaultCommandConfigurator
|
||||
{
|
||||
private readonly ConfiguredCommand _defaultCommand;
|
||||
|
||||
internal DefaultCommandConfigurator(ConfiguredCommand defaultCommand)
|
||||
{
|
||||
_defaultCommand = defaultCommand;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the description of the default command.
|
||||
/// </summary>
|
||||
/// <param name="description">The default command description.</param>
|
||||
/// <returns>The same <see cref="DefaultCommandConfigurator"/> instance so that multiple calls can be chained.</returns>
|
||||
public DefaultCommandConfigurator WithDescription(string description)
|
||||
{
|
||||
_defaultCommand.Description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets data that will be passed to the command via the <see cref="CommandContext"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to pass to the default command.</param>
|
||||
/// <returns>The same <see cref="DefaultCommandConfigurator"/> instance so that multiple calls can be chained.</returns>
|
||||
public DefaultCommandConfigurator WithData(object data)
|
||||
{
|
||||
_defaultCommand.Data = data;
|
||||
return this;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user