File tree Expand file tree Collapse file tree 6 files changed +18
-18
lines changed
CodeOfChaos.CliArgsParser.Contracts
CodeOfChaos.CliArgsParser
Sample.CodeOfChaos.CliArgsParser
Tools.CodeOfChaos.CliArgsParser
tests/Tests.CodeOfChaos.CliArgsParser Expand file tree Collapse file tree 6 files changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -9,10 +9,10 @@ namespace CodeOfChaos.CliArgsParser;
9
9
// Code
10
10
// ---------------------------------------------------------------------------------------------------------------------
11
11
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 ) ;
16
16
17
17
ICliParser Build ( ) ;
18
18
}
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public partial class CliParser : ICliParser {
18
18
// Methods
19
19
// -----------------------------------------------------------------------------------------------------------------
20
20
internal CliParser ( ) { }
21
- public static CliParserBuilder FromBuilder ( ) {
21
+ public static CliParserBuilder CreateBuilder ( ) {
22
22
return new CliParserBuilder ( ) ;
23
23
}
24
24
Original file line number Diff line number Diff line change @@ -19,19 +19,19 @@ public partial class CliParserBuilder : ICliParserBuilder {
19
19
// -----------------------------------------------------------------------------------------------------------------
20
20
// Methods
21
21
// -----------------------------------------------------------------------------------------------------------------
22
- public ICliParserBuilder AddServices ( IServiceProvider provider ) {
22
+ public ICliParserBuilder WithServiceProvider ( IServiceProvider provider ) {
23
23
ServiceProvider = ( ) => provider ;
24
24
return this ;
25
25
}
26
26
27
- public ICliParserBuilder AddServices ( Func < IServiceProvider > provider ) {
27
+ public ICliParserBuilder WithServiceProvider ( Func < IServiceProvider > provider ) {
28
28
ServiceProvider = provider ;
29
29
return this ;
30
30
}
31
31
32
- public ICliParserBuilder AddCommandsFromAssembly < TEntrypoint > ( ) => AddCommandsFromAssembly ( typeof ( TEntrypoint ) . Assembly ) ;
32
+ public ICliParserBuilder AddFromAssembly < TEntrypoint > ( ) => AddFromAssembly ( typeof ( TEntrypoint ) . Assembly ) ;
33
33
34
- public ICliParserBuilder AddCommandsFromAssembly ( Assembly assembly ) {
34
+ public ICliParserBuilder AddFromAssembly ( Assembly assembly ) {
35
35
Type [ ] types = assembly . GetTypes ( ) ;
36
36
Type ? staticDictionaryType = types . FirstOrDefault ( t => FindCommandDictionary . IsMatch ( t . Name ) && t . IsClass ) ;
37
37
var commandsDictionary = staticDictionaryType ? . GetField ( "Commands" ) ? . GetValue ( null ) as Dictionary < string , Type > ;
Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ namespace Sample.CodeOfChaos.CliArgsParser;
10
10
// ---------------------------------------------------------------------------------------------------------------------
11
11
public static class Program {
12
12
public static async Task Main ( string [ ] args ) {
13
- ICliParser parser = CliParser . FromBuilder ( )
14
- . AddCommandsFromAssembly < TestCommand > ( )
13
+ ICliParser parser = CliParser . CreateBuilder ( )
14
+ . AddFromAssembly < TestCommand > ( )
15
15
. Build ( ) ;
16
16
17
17
await parser . ExecuteAsync ( args ) ;
Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ public static class Program {
12
12
public static async Task Main ( string [ ] args ) {
13
13
// Register & Build the parser
14
14
// 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 > ( )
17
17
. Build ( ) ;
18
18
19
19
// We are doing this here because else the launchSettings.json file becomes a humongous issue to deal with.
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ public class CliParserTests {
15
15
public async Task ExecuteAsync_Test ( ) {
16
16
// Arrange
17
17
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 )
20
20
. Build ( ) ;
21
21
22
22
// Act
@@ -34,9 +34,9 @@ public async Task ExecuteAsync_TestWithServices() {
34
34
services . AddSingleton < IService , Service > ( ) ;
35
35
ServiceProvider provider = services . BuildServiceProvider ( ) ;
36
36
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 )
40
40
. Build ( ) ;
41
41
42
42
// Act
You can’t perform that action at this time.
0 commit comments