Skip to content

Commit 906b7c0

Browse files
committed
(new-cli) - register the command in the generator as well
1 parent 88a9361 commit 906b7c0

30 files changed

+239
-88
lines changed

new-cli/.editorconfig

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# http://editorconfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 4
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
14+
[*.yml]
15+
indent_size = 2
16+
17+
### CSharp code style settings ###
18+
[*.cs]
19+
# Organize usings
20+
dotnet_separate_import_directive_groups = false
21+
dotnet_sort_system_directives_first = true
22+
23+
# Avoid "this." and "Me." if not necessary
24+
dotnet_style_qualification_for_field = false:silent
25+
dotnet_style_qualification_for_property = false:silent
26+
dotnet_style_qualification_for_method = false:silent
27+
dotnet_style_qualification_for_event = false:silent
28+
29+
# Use language keywords instead of framework type names for type references
30+
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
31+
dotnet_style_predefined_type_for_member_access = true:warning
32+
33+
# Parentheses preferences
34+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
35+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
36+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
37+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
38+
39+
# Modifier preferences
40+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning
41+
42+
# Field preferences
43+
dotnet_style_readonly_field = true:warning
44+
dotnet_naming_rule.private_members_with_underscore.symbols = private_fields
45+
dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore
46+
dotnet_naming_rule.private_members_with_underscore.severity = suggestion
47+
48+
dotnet_naming_symbols.private_fields.applicable_kinds = field
49+
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
50+
51+
dotnet_naming_style.prefix_underscore.capitalization = camel_case
52+
53+
# Parameter preferences
54+
dotnet_code_quality_unused_parameters = all:warning
55+
56+
# Expression-level preferences
57+
dotnet_style_coalesce_expression = true:suggestion
58+
dotnet_style_collection_initializer = true:suggestion
59+
dotnet_style_explicit_tuple_names = true:suggestion
60+
dotnet_style_null_propagation = true:suggestion
61+
dotnet_style_object_initializer = true:suggestion
62+
dotnet_style_prefer_auto_properties = true:silent
63+
dotnet_style_prefer_compound_assignment = true:warning
64+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
65+
dotnet_style_prefer_conditional_expression_over_return = true:silent
66+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
67+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
68+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
69+
dotnet_style_prefer_simplified_interpolation = true:suggestion
70+
71+
# Dispose rules (CA2000 and CA2213) ported to IDE analyzers. We already execute the CA rules on the repo, so disable the IDE ones.
72+
dotnet_diagnostic.IDE0067.severity = none
73+
dotnet_diagnostic.IDE0068.severity = none
74+
dotnet_diagnostic.IDE0069.severity = none
75+
76+
#### C# Coding Conventions ####
77+
78+
# Prefer "var" everywhere
79+
csharp_style_var_for_built_in_types = true:silent
80+
csharp_style_var_when_type_is_apparent = true:silent
81+
csharp_style_var_elsewhere = true:silent
82+
83+
# Prefer method-like constructs to have a block body, except for lambdas
84+
csharp_style_expression_bodied_methods = true:warning
85+
csharp_style_expression_bodied_constructors = true:warning
86+
csharp_style_expression_bodied_operators = true:warning
87+
csharp_style_expression_bodied_local_functions = true:warning
88+
csharp_style_expression_bodied_lambdas = true:warning
89+
csharp_style_expression_bodied_properties = true:warning
90+
csharp_style_expression_bodied_accessors = true:warning
91+
csharp_style_expression_bodied_indexers = true:warning
92+
93+
# Pattern matching preferences
94+
csharp_style_pattern_matching_over_as_with_null_check = true:warning
95+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
96+
csharp_style_prefer_switch_expression = true:suggestion
97+
98+
# Null-checking preferences
99+
csharp_style_conditional_delegate_call = true:warning
100+
101+
# Modifier preferences
102+
csharp_prefer_static_local_function = true:warning
103+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
104+
105+
# Code-block preferences
106+
csharp_prefer_braces = when_multiline:none
107+
csharp_prefer_simple_using_statement = true:warning
108+
109+
# Expression-level preferences
110+
csharp_style_unused_value_assignment_preference = discard_variable:warning
111+
csharp_prefer_simple_default_expression = true:suggestion
112+
csharp_style_deconstructed_variable_declaration = true:suggestion
113+
csharp_style_inlined_variable_declaration = true:suggestion
114+
csharp_style_pattern_local_over_anonymous_function = true:suggestion
115+
csharp_style_prefer_index_operator = true:suggestion
116+
csharp_style_prefer_range_operator = true:suggestion
117+
csharp_style_throw_expression = true:suggestion
118+
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
119+
120+
# 'using' directive preferences
121+
csharp_using_directive_placement = outside_namespace:silent
122+
123+
#### C# Formatting Rules ####
124+
125+
# New line preferences
126+
csharp_new_line_before_open_brace = all
127+
csharp_new_line_before_else = true
128+
csharp_new_line_before_catch = true
129+
csharp_new_line_before_finally = true
130+
csharp_new_line_before_members_in_object_initializers = true
131+
csharp_new_line_before_members_in_anonymous_types = true
132+
csharp_new_line_between_query_expression_clauses = true
133+
134+
# Indentation preferences
135+
csharp_indent_block_contents = true
136+
csharp_indent_braces = false
137+
csharp_indent_case_contents = true
138+
csharp_indent_case_contents_when_block = true
139+
csharp_indent_labels = no_change
140+
csharp_indent_switch_labels = true
141+
142+
# Space preferences
143+
csharp_space_after_cast = false
144+
csharp_space_after_colon_in_inheritance_clause = true
145+
csharp_space_after_comma = true
146+
csharp_space_after_dot = false
147+
csharp_space_after_keywords_in_control_flow_statements = true
148+
csharp_space_after_semicolon_in_for_statement = true
149+
csharp_space_around_binary_operators = before_and_after
150+
csharp_space_around_declaration_statements = false
151+
csharp_space_before_colon_in_inheritance_clause = true
152+
csharp_space_before_comma = false
153+
csharp_space_before_dot = false
154+
csharp_space_before_open_square_brackets = false
155+
csharp_space_before_semicolon_in_for_statement = false
156+
csharp_space_between_empty_square_brackets = false
157+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
158+
csharp_space_between_method_call_name_and_opening_parenthesis = false
159+
csharp_space_between_method_call_parameter_list_parentheses = false
160+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
161+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
162+
csharp_space_between_method_declaration_parameter_list_parentheses = false
163+
csharp_space_between_parentheses = false
164+
csharp_space_between_square_brackets = false
165+
166+
# Alignment
167+
align_multiline_parameter = true
168+
169+
# Qualify fields with "this."
170+
csharp_instance_members_qualify_members = field
171+
172+
# IDE0011: Add braces
173+
dotnet_diagnostic.IDE0011.severity = none
174+
175+
# IDE0090: Use 'new(...)'
176+
dotnet_diagnostic.IDE0090.severity = warning
177+
178+
# IDE0041: Use 'is null' check
179+
dotnet_diagnostic.IDE0041.severity = warning
180+
181+
# CA1825: Avoid zero-length array allocations
182+
dotnet_diagnostic.CA1825.severity = warning
183+
184+
# CA1822: Mark members as static
185+
dotnet_diagnostic.CA1822.severity = warning
186+
187+
# CA2208: Instantiate argument exceptions correctly
188+
dotnet_diagnostic.CA2208.severity = warning
189+
190+
# CA1810: Initialize reference type static fields inline
191+
dotnet_diagnostic.CA1810.severity = warning
192+
193+
# CA1816: Dispose methods should call SuppressFinalize
194+
dotnet_diagnostic.CA1816.severity = warning
195+
196+
# IDE0005: Using directive is unnecessary.
197+
dotnet_diagnostic.IDE0005.severity = warning

new-cli/Directory.Build.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
<Nullable>enable</Nullable>
88
<ImplicitUsings>enable</ImplicitUsings>
99
<NoWarn>8625;2254</NoWarn>
10+
11+
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
12+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
13+
<AnalysisLevel>latest</AnalysisLevel>
14+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1015
</PropertyGroup>
1116

1217
<ItemGroup>

new-cli/GitVersion.Calculation/CalculateCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using GitVersion.Git;
22
using GitVersion.Infrastructure;
33

4-
namespace GitVersion;
4+
namespace GitVersion.Commands;
5+
6+
public record CalculateSettings : GitVersionSettings;
57

68
[Command("calculate", "Calculates the version object from the git history.")]
79
public class CalculateCommand : ICommand<CalculateSettings>

new-cli/GitVersion.Calculation/CalculateModule.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

new-cli/GitVersion.Calculation/CalculateSettings.cs

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class CommandImplGenerator : IIncrementalGenerator
1010
private const string GeneratedNamespaceName = "GitVersion.Generated";
1111
private const string InfraNamespaceName = "GitVersion";
1212
private const string DependencyInjectionNamespaceName = "GitVersion.Infrastructure";
13+
private const string CommandNamespaceName = "GitVersion.Commands";
1314
private const string CommandInterfaceFullName = $"{InfraNamespaceName}.ICommand<T>";
1415
private const string CommandAttributeFullName = $"{InfraNamespaceName}.CommandAttribute";
1516
private const string CommandAttributeGenericFullName = $"{InfraNamespaceName}.CommandAttribute<T>";
@@ -62,7 +63,8 @@ private static void GenerateSourceCode(SourceProductionContext context, Immutabl
6263
Model = commandInfos,
6364
Namespace = GeneratedNamespaceName,
6465
InfraNamespaceName,
65-
DependencyInjectionNamespaceName
66+
DependencyInjectionNamespaceName,
67+
CommandNamespaceName
6668
}, member => member.Name);
6769
context.AddSource("CommandsModule.g.cs", string.Join("\n", commandHandlersModuleSource));
6870

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private void AddCommand(ICommandImpl command, IDictionary<string, ICommandImpl>
110110
{{{GeneratedHeader}}}
111111
using System.CommandLine;
112112
using {{DependencyInjectionNamespaceName}};
113+
using {{CommandNamespaceName}};
113114
using {{InfraNamespaceName}};
114115
115116
namespace {{Namespace}};
@@ -121,7 +122,9 @@ public void RegisterTypes(IContainerRegistrar services)
121122
{{- $commands = Model | array.sort "CommandTypeName" }}
122123
services.AddSingleton<RootCommandImpl>();
123124
{{~ for $command in $commands ~}}
125+
services.AddSingleton<{{$command.CommandTypeName}}>();
124126
services.AddSingleton<ICommandImpl, {{$command.CommandTypeName}}Impl>();
127+
125128
{{~ end ~}}
126129
}
127130
}

new-cli/GitVersion.Cli/GitVersionApp.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ private static void EnrichLogger(InvocationContext context)
4949
LoggingEnricher.LogLevel.MinimumLevel = GetLevelForVerbosity(verbosity);
5050
}
5151

52-
private static LogEventLevel GetLevelForVerbosity(Verbosity verbosity) => VerbosityMaps[verbosity];
52+
private static LogEventLevel GetLevelForVerbosity(Verbosity verbosity) => verbosityMaps[verbosity];
5353

54-
private static readonly Dictionary<Verbosity, LogEventLevel> VerbosityMaps = new()
54+
private static readonly Dictionary<Verbosity, LogEventLevel> verbosityMaps = new()
5555
{
5656
{ Verbosity.Verbose, LogEventLevel.Verbose },
5757
{ Verbosity.Diagnostic, LogEventLevel.Debug },

new-cli/GitVersion.Cli/Program.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,18 @@
66
var modules = new IGitVersionModule[]
77
{
88
new CoreModule(),
9-
new LibGit2SharpCoreModule(),
10-
new NormalizeModule(),
11-
new CalculateModule(),
12-
new ConfigModule(),
13-
new OutputModule(),
9+
new LibGit2SharpCoreModule()
1410
};
1511

16-
using var serviceProvider = LoadGitVersionModules(modules);
12+
using var serviceProvider = RegisterModules(modules);
1713
var app = serviceProvider.GetRequiredService<GitVersionApp>();
1814
var result = await app.RunAsync(args);
1915

2016
if (!Console.IsInputRedirected) Console.ReadKey();
2117

2218
return result;
2319

24-
static IContainer LoadGitVersionModules(IEnumerable<IGitVersionModule> gitVersionModules)
20+
static IContainer RegisterModules(IEnumerable<IGitVersionModule> gitVersionModules)
2521
{
2622
var serviceProvider = new ContainerRegistrar()
2723
.RegisterModules(gitVersionModules)

new-cli/GitVersion.Configuration/ConfigCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using GitVersion.Infrastructure;
22

3-
namespace GitVersion;
3+
namespace GitVersion.Commands;
4+
5+
public record ConfigSettings : GitVersionSettings;
46

57
[Command("config", "Manages the GitVersion configuration file.")]
68
public class ConfigCommand : ICommand<ConfigSettings>

0 commit comments

Comments
 (0)