Rename WithCommand* to AddCommand* on CliApplicationBuilder

This commit is contained in:
Alexey Golub
2019-08-18 17:21:25 +03:00
parent 45c2b9c4e0
commit 04415cbfc1
8 changed files with 24 additions and 24 deletions

View File

@@ -11,7 +11,7 @@ namespace CliFx.Benchmarks
private static readonly string[] Arguments = { "--str", "hello world", "-i", "13", "-b" };
[Benchmark(Description = "CliFx", Baseline = true)]
public Task<int> ExecuteWithCliFx() => new CliApplicationBuilder().WithCommand(typeof(CliFxCommand)).Build().RunAsync(Arguments);
public Task<int> ExecuteWithCliFx() => new CliApplicationBuilder().AddCommand(typeof(CliFxCommand)).Build().RunAsync(Arguments);
[Benchmark(Description = "System.CommandLine")]
public Task<int> ExecuteWithSystemCommandLine() => new SystemCommandLineCommand().ExecuteAsync(Arguments);

View File

@@ -24,7 +24,7 @@ namespace CliFx.Demo
var serviceProvider = services.BuildServiceProvider();
return new CliApplicationBuilder()
.WithCommandsFromThisAssembly()
.AddCommandsFromThisAssembly()
.UseCommandFactory(type => (ICommand) serviceProvider.GetRequiredService(type))
.Build()
.RunAsync(args);

View File

@@ -12,7 +12,7 @@ namespace CliFx.Tests.Dummy
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
return new CliApplicationBuilder()
.WithCommandsFromThisAssembly()
.AddCommandsFromThisAssembly()
.UseDescription("Dummy program used for E2E tests.")
.Build()
.RunAsync(args);

View File

@@ -204,7 +204,7 @@ namespace CliFx.Tests
public async Task RunAsync_Test(IReadOnlyList<Type> commandTypes, IReadOnlyList<string> commandLineArguments)
{
// Arrange
var application = new CliApplicationBuilder().WithCommands(commandTypes).Build();
var application = new CliApplicationBuilder().AddCommands(commandTypes).Build();
// Act
var exitCodeValue = await application.RunAsync(commandLineArguments);
@@ -218,7 +218,7 @@ namespace CliFx.Tests
public async Task RunAsync_Negative_Test(IReadOnlyList<Type> commandTypes, IReadOnlyList<string> commandLineArguments)
{
// Arrange
var application = new CliApplicationBuilder().WithCommands(commandTypes).Build();
var application = new CliApplicationBuilder().AddCommands(commandTypes).Build();
// Act
var exitCodeValue = await application.RunAsync(commandLineArguments);

View File

@@ -24,7 +24,7 @@ namespace CliFx
private ICommandFactory _commandFactory;
/// <inheritdoc />
public ICliApplicationBuilder WithCommand(Type commandType)
public ICliApplicationBuilder AddCommand(Type commandType)
{
commandType.GuardNotNull(nameof(commandType));
@@ -34,14 +34,14 @@ namespace CliFx
}
/// <inheritdoc />
public ICliApplicationBuilder WithCommandsFrom(Assembly commandAssembly)
public ICliApplicationBuilder AddCommandsFrom(Assembly commandAssembly)
{
commandAssembly.GuardNotNull(nameof(commandAssembly));
var commandTypes = commandAssembly.ExportedTypes.Where(t => t.Implements(typeof(ICommand)));
foreach (var commandType in commandTypes)
WithCommand(commandType);
AddCommand(commandType);
return this;
}

View File

@@ -14,13 +14,13 @@ namespace CliFx
/// <summary>
/// Adds multiple commands to the application.
/// </summary>
public static ICliApplicationBuilder WithCommands(this ICliApplicationBuilder builder, IReadOnlyList<Type> commandTypes)
public static ICliApplicationBuilder AddCommands(this ICliApplicationBuilder builder, IReadOnlyList<Type> commandTypes)
{
builder.GuardNotNull(nameof(builder));
commandTypes.GuardNotNull(nameof(commandTypes));
foreach (var commandType in commandTypes)
builder.WithCommand(commandType);
builder.AddCommand(commandType);
return builder;
}
@@ -28,13 +28,13 @@ namespace CliFx
/// <summary>
/// Adds commands from specified assemblies to the application.
/// </summary>
public static ICliApplicationBuilder WithCommandsFrom(this ICliApplicationBuilder builder, IReadOnlyList<Assembly> commandAssemblies)
public static ICliApplicationBuilder AddCommandsFrom(this ICliApplicationBuilder builder, IReadOnlyList<Assembly> commandAssemblies)
{
builder.GuardNotNull(nameof(builder));
commandAssemblies.GuardNotNull(nameof(commandAssemblies));
foreach (var commandAssembly in commandAssemblies)
builder.WithCommandsFrom(commandAssembly);
builder.AddCommandsFrom(commandAssembly);
return builder;
}
@@ -42,10 +42,10 @@ namespace CliFx
/// <summary>
/// Adds commands from calling assembly to the application.
/// </summary>
public static ICliApplicationBuilder WithCommandsFromThisAssembly(this ICliApplicationBuilder builder)
public static ICliApplicationBuilder AddCommandsFromThisAssembly(this ICliApplicationBuilder builder)
{
builder.GuardNotNull(nameof(builder));
return builder.WithCommandsFrom(Assembly.GetCallingAssembly());
return builder.AddCommandsFrom(Assembly.GetCallingAssembly());
}
/// <summary>

View File

@@ -12,12 +12,12 @@ namespace CliFx
/// <summary>
/// Adds a command of specified type to the application.
/// </summary>
ICliApplicationBuilder WithCommand(Type commandType);
ICliApplicationBuilder AddCommand(Type commandType);
/// <summary>
/// Adds commands from specified assembly to the application.
/// </summary>
ICliApplicationBuilder WithCommandsFrom(Assembly commandAssembly);
ICliApplicationBuilder AddCommandsFrom(Assembly commandAssembly);
/// <summary>
/// Sets application title, which appears in the help text.

View File

@@ -50,7 +50,7 @@ public static class Program
{
public static Task<int> Main(string[] args) =>
new CliApplicationBuilder()
.WithCommandsFromThisAssembly()
.AddCommandsFromThisAssembly()
.Build()
.RunAsync(args);
}
@@ -138,7 +138,7 @@ public static class Program
var serviceProvider = services.BuildServiceProvider();
return new CliApplicationBuilder()
.WithCommandsFromThisAssembly()
.AddCommandsFromThisAssembly()
.UseCommandFactory(type => (ICommand) serviceProvider.GetRequiredService(type))
.Build()
.RunAsync(args);
@@ -151,16 +151,16 @@ public static class Program
In most cases, your commands will be defined in your main assembly which is where CliFx will look if you initialize the application using the following code.
```c#
var app = new CliApplicationBuilder().WithCommandsFromThisAssembly().Build();
var app = new CliApplicationBuilder().AddCommandsFromThisAssembly().Build();
```
If you want to configure your application to resolve specific commands or commands from another assembly you can use `WithCommand` and `WithCommandsFrom` methods for that.
If you want to configure your application to resolve specific commands or commands from another assembly you can use `AddCommand` and `AddCommandsFrom` methods for that.
```c#
var app = new CliApplicationBuilder()
.WithCommand(typeof(CommandA)) // include CommandA specifically
.WithCommand(typeof(CommandB)) // include CommandB specifically
.WithCommandsFrom(typeof(CommandC).Assembly) // include all commands from assembly that contains CommandC
.AddCommand(typeof(CommandA)) // include CommandA specifically
.AddCommand(typeof(CommandB)) // include CommandB specifically
.AddCommandsFrom(typeof(CommandC).Assembly) // include all commands from assembly that contains CommandC
.Build();
```
@@ -291,7 +291,7 @@ public async Task ConcatCommand_Test()
var console = new VirtualConsole(stdout);
var app = new CliApplicationBuilder()
.WithCommand(typeof(ConcatCommand))
.AddCommand(typeof(ConcatCommand))
.UseConsole(console)
.Build();