Skip to content

Commit 6344a51

Browse files
committed
Change: Refactor method and builder naming for consistency
Updated method and builder names in `CliParser` and related classes to improve clarity and consistency. Changed `FromBuilder` to `CreateBuilder`, `AddServices` to `WithServiceProvider`, and `AddCommandsFromAssembly` to `AddFromAssembly`. Adjusted corresponding test cases and usages across the project.
1 parent 4185391 commit 6344a51

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

src/CodeOfChaos.CliArgsParser.Contracts/ICliParserBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace CodeOfChaos.CliArgsParser;
99
// Code
1010
// ---------------------------------------------------------------------------------------------------------------------
1111
public interface ICliParserBuilder {
12-
ICliParserBuilder AddServices(IServiceProvider provider);
13-
ICliParserBuilder AddServices(Func<IServiceProvider> provider);
14-
ICliParserBuilder AddCommandsFromAssembly<TEntrypoint>();
15-
ICliParserBuilder AddCommandsFromAssembly(Assembly assembly);
12+
ICliParserBuilder WithServiceProvider(IServiceProvider provider);
13+
ICliParserBuilder WithServiceProvider(Func<IServiceProvider> provider);
14+
ICliParserBuilder AddFromAssembly<TEntrypoint>();
15+
ICliParserBuilder AddFromAssembly(Assembly assembly);
1616

1717
ICliParser Build();
1818
}

src/CodeOfChaos.CliArgsParser/CliParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public partial class CliParser : ICliParser {
1818
// Methods
1919
// -----------------------------------------------------------------------------------------------------------------
2020
internal CliParser() { }
21-
public static CliParserBuilder FromBuilder() {
21+
public static CliParserBuilder CreateBuilder() {
2222
return new CliParserBuilder();
2323
}
2424

src/CodeOfChaos.CliArgsParser/CliParserBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ public partial class CliParserBuilder : ICliParserBuilder {
1919
// -----------------------------------------------------------------------------------------------------------------
2020
// Methods
2121
// -----------------------------------------------------------------------------------------------------------------
22-
public ICliParserBuilder AddServices(IServiceProvider provider) {
22+
public ICliParserBuilder WithServiceProvider(IServiceProvider provider) {
2323
ServiceProvider = () => provider;
2424
return this;
2525
}
2626

27-
public ICliParserBuilder AddServices(Func<IServiceProvider> provider) {
27+
public ICliParserBuilder WithServiceProvider(Func<IServiceProvider> provider) {
2828
ServiceProvider = provider;
2929
return this;
3030
}
3131

32-
public ICliParserBuilder AddCommandsFromAssembly<TEntrypoint>() => AddCommandsFromAssembly(typeof(TEntrypoint).Assembly);
32+
public ICliParserBuilder AddFromAssembly<TEntrypoint>() => AddFromAssembly(typeof(TEntrypoint).Assembly);
3333

34-
public ICliParserBuilder AddCommandsFromAssembly(Assembly assembly) {
34+
public ICliParserBuilder AddFromAssembly(Assembly assembly) {
3535
Type[] types = assembly.GetTypes();
3636
Type? staticDictionaryType = types.FirstOrDefault(t => FindCommandDictionary.IsMatch(t.Name) && t.IsClass);
3737
var commandsDictionary = staticDictionaryType?.GetField("Commands")?.GetValue(null) as Dictionary<string, Type>;

src/Sample.CodeOfChaos.CliArgsParser/Progam.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace Sample.CodeOfChaos.CliArgsParser;
1010
// ---------------------------------------------------------------------------------------------------------------------
1111
public static class Program {
1212
public static async Task Main(string[] args) {
13-
ICliParser parser = CliParser.FromBuilder()
14-
.AddCommandsFromAssembly<TestCommand>()
13+
ICliParser parser = CliParser.CreateBuilder()
14+
.AddFromAssembly<TestCommand>()
1515
.Build();
1616

1717
await parser.ExecuteAsync(args);

src/Tools.CodeOfChaos.CliArgsParser/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public static class Program {
1212
public static async Task Main(string[] args) {
1313
// Register & Build the parser
1414
// Don't forget to add the current assembly if you built more tools for the current project
15-
ICliParser parser = CliParser.FromBuilder()
16-
.AddCommandsFromAssembly<IAssemblyEntry>()
15+
ICliParser parser = CliParser.CreateBuilder()
16+
.AddFromAssembly<IAssemblyEntry>()
1717
.Build();
1818

1919
// We are doing this here because else the launchSettings.json file becomes a humongous issue to deal with.

tests/Tests.CodeOfChaos.CliArgsParser/CliArgsParserTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class CliParserTests {
1515
public async Task ExecuteAsync_Test() {
1616
// Arrange
1717
const string input = "test-command --test-required-string=\"something\"";
18-
ICliParser parser = CliParser.FromBuilder()
19-
.AddCommandsFromAssembly(typeof(CliParserTests).Assembly)
18+
ICliParser parser = CliParser.CreateBuilder()
19+
.AddFromAssembly(typeof(CliParserTests).Assembly)
2020
.Build();
2121

2222
// Act
@@ -34,9 +34,9 @@ public async Task ExecuteAsync_TestWithServices() {
3434
services.AddSingleton<IService, Service>();
3535
ServiceProvider provider = services.BuildServiceProvider();
3636

37-
ICliParser parser = CliParser.FromBuilder()
38-
.AddServices(provider)
39-
.AddCommandsFromAssembly(typeof(CliParserTests).Assembly)
37+
ICliParser parser = CliParser.CreateBuilder()
38+
.WithServiceProvider(provider)
39+
.AddFromAssembly(typeof(CliParserTests).Assembly)
4040
.Build();
4141

4242
// Act

0 commit comments

Comments
 (0)