Skip to content

Commit 263ef09

Browse files
committed
Adds extensions namespace to code generator
Adds the extensions namespace to the code generator, ensuring it is correctly included in generated files. This change ensures consistency and proper referencing of extension methods within the generated code.
1 parent 36cb36c commit 263ef09

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

new-cli/GitVersion.Cli.Generator.Tests/SystemCommandlineGeneratorTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public void RegisterTypes(IServiceCollection services)
8585
{
8686
services.AddSingleton<RootCommandImpl>();
8787
services.AddSingleton<ICliApp, CliAppImpl>();
88+
8889
services.AddSingleton<TestCommand>();
8990
services.AddSingleton<ICommandImpl, TestCommandImpl>();
9091
}
@@ -98,7 +99,7 @@ public void RegisterTypes(IServiceCollection services)
9899
using System.CommandLine;
99100
100101
using {{Constants.CommonNamespaceName}};
101-
using GitVersion.Extensions;
102+
using {{Constants.ExtensionsNamespaceName}};
102103
103104
namespace {{Constants.GeneratedNamespaceName}};
104105
@@ -135,7 +136,7 @@ private void AddCommand(ICommandImpl command, Dictionary<string, ICommandImpl> m
135136
$$"""
136137
{{Constants.GeneratedHeader}}
137138
using System.CommandLine;
138-
using GitVersion.Extensions;
139+
using {{Constants.ExtensionsNamespaceName}};
139140
using {{Constants.InfrastructureNamespaceName}};
140141
141142
namespace {{Constants.GeneratedNamespaceName}};

new-cli/GitVersion.Cli.Generator/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public static class Constants
66
internal const string CommonNamespaceName = "GitVersion";
77
internal const string InfrastructureNamespaceName = "GitVersion.Infrastructure";
88
internal const string CommandNamespaceName = "GitVersion.Commands";
9+
internal const string ExtensionsNamespaceName = "GitVersion.Extensions";
910

1011
/*language=cs*/
1112
internal const string GeneratedHeader =

new-cli/GitVersion.Cli.Generator/SystemCommandlineContent.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Task<int> Run(ParseResult parseResult, CancellationToken cancellationToken)
6464
using System.CommandLine;
6565
6666
using {{CommonNamespaceName}};
67-
using GitVersion.Extensions;
67+
using {{ExtensionsNamespaceName}};
6868
6969
namespace {{GeneratedNamespaceName}};
7070
@@ -114,6 +114,7 @@ public void RegisterTypes(IServiceCollection services)
114114
{{- $commands = Model | array.sort "CommandTypeName" }}
115115
services.AddSingleton<RootCommandImpl>();
116116
services.AddSingleton<ICliApp, CliAppImpl>();
117+
117118
{{~ for $command in $commands ~}}
118119
services.AddSingleton<{{ if $command.CommandTypeNamespace != CommandNamespaceName }}{{$command.CommandTypeNamespace}}.{{ end }}{{$command.CommandTypeName}}>();
119120
services.AddSingleton<ICommandImpl, {{$command.CommandTypeName}}Impl>();
@@ -126,7 +127,7 @@ public void RegisterTypes(IServiceCollection services)
126127
public const string CliAppContent = $$$"""
127128
{{{Constants.GeneratedHeader}}}
128129
using System.CommandLine;
129-
using GitVersion.Extensions;
130+
using {{ExtensionsNamespaceName}};
130131
using {{InfrastructureNamespaceName}};
131132
132133
namespace {{GeneratedNamespaceName}};

new-cli/GitVersion.Cli.Generator/SystemCommandlineGenerator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ internal override void GenerateSourceCode(SourceProductionContext context, Immut
3636
var rootCommandHandlerSource = rootCommandHandlerTemplate.Render(new
3737
{
3838
Constants.GeneratedNamespaceName,
39-
Constants.CommonNamespaceName
39+
Constants.CommonNamespaceName,
40+
Constants.ExtensionsNamespaceName
4041
}, member => member.Name);
4142
context.AddSource("RootCommandImpl.g.cs", string.Join("\n", rootCommandHandlerSource));
4243

@@ -45,7 +46,8 @@ internal override void GenerateSourceCode(SourceProductionContext context, Immut
4546
{
4647
Constants.GeneratedNamespaceName,
4748
Constants.InfrastructureNamespaceName,
48-
Constants.CommonNamespaceName
49+
Constants.CommonNamespaceName,
50+
Constants.ExtensionsNamespaceName
4951
}, member => member.Name);
5052
context.AddSource("CliAppImpl.g.cs", string.Join("\n", cliAppSource));
5153
}

0 commit comments

Comments
 (0)