Skip to content

Commit 2d1e0ae

Browse files
authored
Merge pull request #60 from atc-net/feature/issue-58-options-file-create-should-support-setting-target-framework
Fix Issues #58 and #59
2 parents 1a6c4e4 + 18822a4 commit 2d1e0ae

File tree

10 files changed

+48
-34
lines changed

10 files changed

+48
-34
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<PackageReference Include="Meziantou.Analyzer" Version="1.0.688" PrivateAssets="All" />
4747
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.0" PrivateAssets="All" />
4848
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
49-
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.34.0.42011" PrivateAssets="All" />
49+
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.35.0.42613" PrivateAssets="All" />
5050
</ItemGroup>
5151

5252
</Project>

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ EXAMPLES:
139139
atc-coding-rules-updater.exe options-file create . (equivalent to 'options-file create -p [CurrentFolder]')
140140
atc-coding-rules-updater.exe options-file create -p . (equivalent to 'options-file create -p [CurrentFolder]')
141141
atc-coding-rules-updater.exe options-file create -p c:\temp\MyProject
142+
atc-coding-rules-updater.exe options-file create -p c:\temp\MyProject -t DotNet5
142143
atc-coding-rules-updater.exe options-file validate . (equivalent to 'options-file validate -p [CurrentFolder]')
143144
atc-coding-rules-updater.exe options-file validate -p c:\temp\MyProject
144145
@@ -230,11 +231,6 @@ The tool has an optional options parameter, which can be used to control the pat
230231
"temporarySuppressionAsExcel": false,
231232
"analyzerProviderCollectingMode": "LocalCache",
232233
"mappings": {
233-
"sample": {
234-
"paths": [
235-
"sample"
236-
]
237-
},
238234
"src": {
239235
"paths": [
240236
"src"

src/Atc.CodingRules.AnalyzerProviders/Atc.CodingRules.AnalyzerProviders.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Atc" Version="1.1.381" />
12+
<PackageReference Include="Atc" Version="1.1.385" />
1313
<PackageReference Include="HtmlAgilityPack" Version="1.11.40" />
1414
</ItemGroup>
1515

src/Atc.CodingRules.Updater.CLI/Atc.CodingRules.Updater.CLI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Atc" Version="1.1.381" />
17-
<PackageReference Include="Atc.Console.Spectre" Version="1.1.381" />
16+
<PackageReference Include="Atc" Version="1.1.385" />
17+
<PackageReference Include="Atc.Console.Spectre" Version="1.1.385" />
1818
<PackageReference Include="EPPlus" Version="5.8.5" />
1919
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
2020
</ItemGroup>

src/Atc.CodingRules.Updater.CLI/Commands/OptionsFileCreateCommand.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
namespace Atc.CodingRules.Updater.CLI.Commands;
22

3-
public class OptionsFileCreateCommand : AsyncCommand<ProjectBaseCommandSettings>
3+
public class OptionsFileCreateCommand : AsyncCommand<ProjectCommandSettings>
44
{
55
private readonly ILogger<OptionsFileCreateCommand> logger;
66

77
public OptionsFileCreateCommand(ILogger<OptionsFileCreateCommand> logger) => this.logger = logger;
88

99
public override Task<int> ExecuteAsync(
1010
CommandContext context,
11-
ProjectBaseCommandSettings settings)
11+
ProjectCommandSettings settings)
1212
{
1313
ArgumentNullException.ThrowIfNull(settings);
1414
return ExecuteInternalAsync(settings);
1515
}
1616

1717
private async Task<int> ExecuteInternalAsync(
18-
ProjectBaseCommandSettings settings)
18+
ProjectCommandSettings settings)
1919
{
2020
ConsoleHelper.WriteHeader();
2121

2222
var projectPath = new DirectoryInfo(settings.ProjectPath);
23-
var optionsPath = settings.GetOptionsPath();
2423

2524
try
2625
{
27-
(bool isSuccessful, string error) = await OptionsHelper.CreateOptionsFile(projectPath, optionsPath);
26+
(bool isSuccessful, string error) = await OptionsHelper.CreateOptionsFile(projectPath, settings);
2827
if (isSuccessful)
2928
{
3029
logger.LogInformation("The options file is created");

src/Atc.CodingRules.Updater.CLI/OptionsHelper.cs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ public static async Task<Options> CreateDefault(
1212
var fileInfo = GetOptionsFile(projectPath, settingsOptionsPath);
1313
if (!fileInfo.Exists)
1414
{
15-
return CreateDefaultOptions();
15+
return CreateDefaultOptions(projectPath);
1616
}
1717

1818
var optionsPath = GetOptionsPath(projectPath, settingsOptionsPath);
1919
var options = await DeserializeFile(fileInfo);
2020
if (options is null)
2121
{
22-
return CreateDefaultOptions();
22+
return CreateDefaultOptions(projectPath);
2323
}
2424

2525
options.Mappings.ResolvePaths(new DirectoryInfo(optionsPath));
@@ -28,15 +28,23 @@ public static async Task<Options> CreateDefault(
2828

2929
public static async Task<(bool, string)> CreateOptionsFile(
3030
DirectoryInfo projectPath,
31-
string? settingsOptionsPath)
31+
ProjectCommandSettings settings)
3232
{
33-
var fileInfo = GetOptionsFile(projectPath, settingsOptionsPath);
33+
ArgumentNullException.ThrowIfNull(projectPath);
34+
ArgumentNullException.ThrowIfNull(settings);
35+
36+
var fileInfo = GetOptionsFile(projectPath, settings.GetOptionsPath());
3437
if (fileInfo.Exists)
3538
{
3639
return (false, "File already exist");
3740
}
3841

39-
var options = CreateDefaultOptions();
42+
var options = CreateDefaultOptions(projectPath);
43+
if (settings.ProjectTarget.IsSet)
44+
{
45+
options.ProjectTarget = settings.ProjectTarget.Value;
46+
}
47+
4048
var serializeOptions = JsonSerializerOptionsFactory.Create();
4149
var json = JsonSerializer.Serialize(options, serializeOptions);
4250
await File.WriteAllTextAsync(fileInfo.FullName, json, Encoding.UTF8);
@@ -59,12 +67,24 @@ public static async Task<Options> CreateDefault(
5967
: (true, string.Empty);
6068
}
6169

62-
private static Options CreateDefaultOptions()
70+
private static Options CreateDefaultOptions(
71+
DirectoryInfo projectPath)
6372
{
6473
var options = new Options();
65-
options.Mappings.Sample.Paths.Add("sample");
66-
options.Mappings.Src.Paths.Add("src");
67-
options.Mappings.Test.Paths.Add("test");
74+
var directories = projectPath.GetDirectories();
75+
76+
var sampleName = directories.FirstOrDefault(x => x.Name.Equals("sample", StringComparison.OrdinalIgnoreCase))?.Name;
77+
if (sampleName is not null)
78+
{
79+
options.Mappings.Sample.Paths.Add(sampleName);
80+
}
81+
82+
var srcName = directories.FirstOrDefault(x => x.Name.Equals("src", StringComparison.OrdinalIgnoreCase))?.Name ?? "src";
83+
options.Mappings.Src.Paths.Add(srcName);
84+
85+
var testName = directories.FirstOrDefault(x => x.Name.Equals("test", StringComparison.OrdinalIgnoreCase))?.Name ?? "test";
86+
options.Mappings.Test.Paths.Add(testName);
87+
6888
return options;
6989
}
7090

src/Atc.CodingRules.Updater/Atc.CodingRules.Updater.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Atc" Version="1.1.381" />
11-
<PackageReference Include="Atc.DotNet" Version="1.1.381" />
10+
<PackageReference Include="Atc" Version="1.1.385" />
11+
<PackageReference Include="Atc.DotNet" Version="1.1.385" />
1212
</ItemGroup>
1313

1414
<ItemGroup>
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
namespace Atc.CodingRules.Updater
1+
namespace Atc.CodingRules.Updater;
2+
3+
public enum SupportedProjectTargetType
24
{
3-
public enum SupportedProjectTargetType
4-
{
5-
DotNetCore,
6-
DotNet5,
7-
DotNet6,
8-
}
5+
DotNetCore,
6+
DotNet5,
7+
DotNet6,
98
}

src/Atc.CodingRules/Atc.CodingRules.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Atc" Version="1.1.381" />
10+
<PackageReference Include="Atc" Version="1.1.385" />
1111
</ItemGroup>
1212

1313
</Project>

test/Atc.CodingRules.AnalyzerProviders.Tests/Atc.CodingRules.AnalyzerProviders.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
<PrivateAssets>all</PrivateAssets>
1515
</PackageReference>
16-
<PackageReference Include="coverlet.collector" Version="3.1.0">
16+
<PackageReference Include="coverlet.collector" Version="3.1.1">
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
<PrivateAssets>all</PrivateAssets>
1919
</PackageReference>

0 commit comments

Comments
 (0)