Skip to content

Commit 2888750

Browse files
committed
use System.CommandLine V2.0.0-beta4 (latest)
1 parent b36b671 commit 2888750

File tree

23 files changed

+131
-106
lines changed

23 files changed

+131
-106
lines changed

.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,4 @@ csharp_style_prefer_top_level_statements = true:silent
227227
csharp_style_prefer_primary_constructors = true:suggestion
228228
csharp_style_expression_bodied_lambdas = true:silent
229229
csharp_style_expression_bodied_local_functions = false:silent
230+
dotnet_diagnostic.IDE0007.severity = suggestion

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,4 @@ coverage.*.cobertura.xml
315315
coverage.*.opencover.xml
316316

317317
FolderProfile.pubxml
318-
/NuGet.config
318+
nuget.config

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
1616
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1717
<LangVersion>preview</LangVersion>
18-
<NoWarn>$(NoWarn);NU1507;NU5105;CS1591</NoWarn>
18+
<NoWarn>$(NoWarn);NU1507;NU5105;CS1591;NU1608</NoWarn>
1919
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2020
<RestoreSources>
2121
https://api.nuget.org/v3/index.json;

Directory.Packages.props

+17-13
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
</PropertyGroup>
66
<ItemGroup>
77
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
8-
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" />
8+
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.143" />
99
</ItemGroup>
1010
<ItemGroup>
11-
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
11+
<PackageVersion Include="DotNetConfig" Version="1.2.0" />
12+
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
1213
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.8.3" />
1314
<PackageVersion Include="Microsoft.Build.Framework" Version="17.8.3" />
14-
<PackageVersion Include="Microsoft.Build.Locator" Version="1.6.10" />
15+
<PackageVersion Include="Microsoft.Build.Locator" Version="1.7.8" />
1516
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
17+
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
1618
<PackageVersion Include="Microsoft.Extensions.DependencyModel" Version="8.0.0" />
1719
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
1820
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
@@ -30,30 +32,32 @@
3032
NuGetFrameworksVersion is defined here https://github.com/microsoft/vstest/blob/9a0c41811637edf4afe0e265e08fdd1cb18109ed/eng/Versions.props#L94C1-L94C1
3133
-->
3234
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
33-
<PackageVersion Include="NuGet.Frameworks" Version="6.8.0" />
35+
<PackageVersion Include="NuGet.Frameworks" Version="6.11.0" />
3436
<PackageVersion Include="NuGet.Packaging" Version="6.8.0" />
35-
<PackageVersion Include="NuGet.Versioning" Version="6.8.0" />
37+
<PackageVersion Include="NuGet.Versioning" Version="6.11.0" />
3638
<PackageVersion Include="Mono.Cecil" Version="0.11.5" />
37-
<PackageVersion Include="Moq" Version="4.20.70" />
38-
<PackageVersion Include="ReportGenerator.Core" Version="5.2.1" />
39+
<PackageVersion Include="Moq" Version="4.20.72" />
40+
<PackageVersion Include="ReportGenerator.Core" Version="5.3.9" />
3941
<!--For test issue 809 https://github.com/coverlet-coverage/coverlet/issues/809-->
40-
<PackageVersion Include="LinqKit.Microsoft.EntityFrameworkCore" Version="7.1.4" />
41-
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
42+
<PackageVersion Include="LinqKit.Microsoft.EntityFrameworkCore" Version="7.1.5" />
43+
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.24324.3" />
44+
<PackageVersion Include="System.CommandLine.Generator" Version="2.0.0-beta4.23307.1" />
4245
<!--To test issue 1104 https://github.com/coverlet-coverage/coverlet/issues/1104-->
4346
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
4447
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
4548
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
4649
<PackageVersion Include="System.Reflection.Metadata" Version="8.0.0" />
47-
<PackageVersion Include="Tmds.ExecFunction" Version="0.7.1" />
48-
<PackageVersion Include="xunit" Version="2.6.6" />
50+
<PackageVersion Include="Tmds.ExecFunction" Version="0.8.0" />
51+
<PackageVersion Include="xunit" Version="2.9.0" />
4952
<PackageVersion Include="xunit.assemblyfixture" Version="2.2.0" />
50-
<PackageVersion Include="xunit.assert" Version="2.6.6" />
51-
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
53+
<PackageVersion Include="xunit.assert" Version="2.9.0" />
54+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
5255
<PackageVersion Include="System.Buffers" Version="4.5.1" />
5356
<PackageVersion Include="System.Memory" Version="4.5.5" />
5457
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
5558
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="6.0.4" />
5659
<PackageVersion Include="System.Text.Encoding.CodePages" Version="8.0.0" />
60+
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
5761
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
5862
</ItemGroup>
5963
</Project>

global.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "8.0.101"
3+
"version": "8.0.108"
44
}
55
}

src/coverlet.console/Program.cs

+60-53
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System;
55
using System.Collections.Generic;
66
using System.CommandLine;
7+
using System.CommandLine.Help;
8+
using System.CommandLine.Parsing;
79
using System.ComponentModel;
810
using System.Diagnostics;
911
using System.Globalization;
@@ -25,32 +27,33 @@ namespace Coverlet.Console
2527
{
2628
public static class Program
2729
{
28-
static int Main(string[] args)
30+
static async Task Main(string[] args)
2931
{
30-
var moduleOrAppDirectory = new Argument<string>("path", "Path to the test assembly or application directory.");
31-
var target = new Option<string>(new[] { "--target", "-t" }, "Path to the test runner application.") { Arity = ArgumentArity.ZeroOrOne, IsRequired = true };
32-
var targs = new Option<string>(new[] { "--targetargs", "-a" }, "Arguments to be passed to the test runner.") { Arity = ArgumentArity.ZeroOrOne };
33-
var output = new Option<string>(new[] { "--output", "-o" }, "Output of the generated coverage report") { Arity = ArgumentArity.ZeroOrOne };
34-
var verbosity = new Option<LogLevel>(new[] { "--verbosity", "-v" }, () => LogLevel.Normal, "Sets the verbosity level of the command. Allowed values are quiet, minimal, normal, detailed.") { Arity = ArgumentArity.ZeroOrOne };
35-
var formats = new Option<string[]>(new[] { "--format", "-f" }, () => new[] { "json" }, "Format of the generated coverage report.") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
36-
var threshold = new Option<string>("--threshold", "Exits with error if the coverage % is below value.") { Arity = ArgumentArity.ZeroOrOne };
37-
var thresholdTypes = new Option<List<string>>("--threshold-type", () => new List<string>(new string[] { "line", "branch", "method" }), "Coverage type to apply the threshold to.").FromAmong("line", "branch", "method");
38-
var thresholdStat = new Option<ThresholdStatistic>("--threshold-stat", () => ThresholdStatistic.Minimum, "Coverage statistic used to enforce the threshold value.") { Arity = ArgumentArity.ZeroOrOne };
39-
var excludeFilters = new Option<string[]>("--exclude", "Filter expressions to exclude specific modules and types.") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
40-
var includeFilters = new Option<string[]>("--include", "Filter expressions to include only specific modules and types.") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
41-
var excludedSourceFiles = new Option<string[]>("--exclude-by-file", "Glob patterns specifying source files to exclude.") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
42-
var includeDirectories = new Option<string[]>("--include-directory", "Include directories containing additional assemblies to be instrumented.") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
43-
var excludeAttributes = new Option<string[]>("--exclude-by-attribute", "Attributes to exclude from code coverage.") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
44-
var includeTestAssembly = new Option<bool>("--include-test-assembly", "Specifies whether to report code coverage of the test assembly.") { Arity = ArgumentArity.Zero };
45-
var singleHit = new Option<bool>("--single-hit", "Specifies whether to limit code coverage hit reporting to a single hit for each location") { Arity = ArgumentArity.Zero };
46-
var skipAutoProp = new Option<bool>("--skipautoprops", "Neither track nor record auto-implemented properties.") { Arity = ArgumentArity.Zero };
47-
var mergeWith = new Option<string>("--merge-with", "Path to existing coverage result to merge.") { Arity = ArgumentArity.ZeroOrOne };
48-
var useSourceLink = new Option<bool>("--use-source-link", "Specifies whether to use SourceLink URIs in place of file system paths.") { Arity = ArgumentArity.Zero };
49-
var doesNotReturnAttributes = new Option<string[]>("--does-not-return-attribute", "Attributes that mark methods that do not return") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
50-
var excludeAssembliesWithoutSources = new Option<string>("--exclude-assemblies-without-sources", "Specifies behaviour of heuristic to ignore assemblies with missing source documents.") { Arity = ArgumentArity.ZeroOrOne };
51-
var sourceMappingFile = new Option<string>("--source-mapping-file", "Specifies the path to a SourceRootsMappings file.") { Arity = ArgumentArity.ZeroOrOne };
52-
53-
RootCommand rootCommand = new()
32+
CliArgument<string> moduleOrAppDirectory = new ("path") { Description = "Path to the test assembly or application directory." };
33+
CliOption<string> target = new ("--target", aliases: new[]{ "--target", "-t" }) { Description = "Path to the test runner application." , Arity = ArgumentArity.ZeroOrOne, Required = true };
34+
CliOption<string> targs = new ("--targetargs", aliases: new[] { "--targetargs", "-a" } ) { Description = "Arguments to be passed to the test runner.", Arity = ArgumentArity.ZeroOrOne };
35+
CliOption<string> output = new ("--output", aliases: new[] { "--output", "-o" }) { Description = "Output of the generated coverage report", Arity = ArgumentArity.ZeroOrOne };
36+
CliOption<LogLevel> verbosity = new ("--verbosity", aliases: new[] { "--verbosity", "-v" }) { DefaultValueFactory = (_) => LogLevel.Normal, Description = "Sets the verbosity level of the command. Allowed values are quiet, minimal, normal, detailed.", Arity = ArgumentArity.ZeroOrOne };
37+
CliOption<string[]> formats = new ("--format", aliases: new[] { "--format", "-f" }) { DefaultValueFactory = (_) => new[] { "json" }, Description = "Format of the generated coverage report.", Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
38+
CliOption<string> threshold = new ("--threshold") { Description = "Exits with error if the coverage % is below value.", Arity = ArgumentArity.ZeroOrOne };
39+
CliOption<List<string>> thresholdTypes = new ("--threshold-type") { DefaultValueFactory = (_) => new List<string>(new string[] { "line", "branch", "method" }), Description = ("Coverage type to apply the threshold to.")};
40+
thresholdTypes.AcceptOnlyFromAmong("line", "branch", "method");
41+
CliOption<ThresholdStatistic> thresholdStat = new ("--threshold-stat") {DefaultValueFactory = (_) => ThresholdStatistic.Minimum, Description = "Coverage statistic used to enforce the threshold value." , Arity = ArgumentArity.ZeroOrOne };
42+
CliOption<string[]> excludeFilters = new ("--exclude") { Description = "Filter expressions to exclude specific modules and types.", Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
43+
CliOption<string[]> includeFilters = new ("--include") { Description = "Filter expressions to include only specific modules and types.", Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
44+
CliOption<string[]> excludedSourceFiles = new ("--exclude-by-file") { Description = "Glob patterns specifying source files to exclude.", Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
45+
CliOption<string[]> includeDirectories = new("--include-directory") { Description = "Include directories containing additional assemblies to be instrumented.", Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
46+
CliOption<string[]> excludeAttributes = new ("--exclude-by-attribute") { Description = "Attributes to exclude from code coverage.", Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
47+
CliOption<bool> includeTestAssembly = new ("--include-test-assembly") { Description = "Specifies whether to report code coverage of the test assembly.", Arity = ArgumentArity.Zero };
48+
CliOption<bool> singleHit = new ("--single-hit") { Description = "Specifies whether to limit code coverage hit reporting to a single hit for each location", Arity = ArgumentArity.Zero };
49+
CliOption<bool> skipAutoProp = new ("--skipautoprops") { Description = "Neither track nor record auto-implemented properties.", Arity = ArgumentArity.Zero };
50+
CliOption<string> mergeWith = new ("--merge-with") { Description = "Path to existing coverage result to merge.", Arity = ArgumentArity.ZeroOrOne };
51+
CliOption<bool> useSourceLink = new ("--use-source-link") { Description = "Specifies whether to use SourceLink URIs in place of file system paths.", Arity = ArgumentArity.Zero };
52+
CliOption<string[]> doesNotReturnAttributes = new ("--does-not-return-attribute") { Description = "Attributes that mark methods that do not return", Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
53+
CliOption<string> excludeAssembliesWithoutSources = new ("--exclude-assemblies-without-sources") { Description = "Specifies behaviour of heuristic to ignore assemblies with missing source documents.", Arity = ArgumentArity.ZeroOrOne };
54+
CliOption<string> sourceMappingFile = new ("--source-mapping-file") { Description = "Specifies the path to a SourceRootsMappings file.", Arity = ArgumentArity.ZeroOrOne };
55+
56+
CliRootCommand rootCommand = new("Cross platform .NET Core code coverage tool")
5457
{
5558
moduleOrAppDirectory,
5659
target,
@@ -75,38 +78,40 @@ static int Main(string[] args)
7578
excludeAssembliesWithoutSources,
7679
sourceMappingFile
7780
};
81+
rootCommand.Add(new HelpOption());
82+
rootCommand.Add(new VersionOption());
7883

79-
rootCommand.Description = "Cross platform .NET Core code coverage tool";
84+
ParseResult parseResult = CliParser.Parse(rootCommand, args);
8085

81-
rootCommand.SetHandler(async (context) =>
86+
rootCommand.SetAction(async (context) =>
8287
{
83-
string moduleOrAppDirectoryValue = context.ParseResult.GetValueForArgument(moduleOrAppDirectory);
84-
string targetValue = context.ParseResult.GetValueForOption(target);
85-
string targsValue = context.ParseResult.GetValueForOption(targs);
86-
string outputValue = context.ParseResult.GetValueForOption(output);
87-
LogLevel verbosityValue = context.ParseResult.GetValueForOption(verbosity);
88-
string[] formatsValue = context.ParseResult.GetValueForOption(formats);
89-
string thresholdValue = context.ParseResult.GetValueForOption(threshold);
90-
List<string> thresholdTypesValue = context.ParseResult.GetValueForOption(thresholdTypes);
91-
ThresholdStatistic thresholdStatValue = context.ParseResult.GetValueForOption(thresholdStat);
92-
string[] excludeFiltersValue = context.ParseResult.GetValueForOption(excludeFilters);
93-
string[] includeFiltersValue = context.ParseResult.GetValueForOption(includeFilters);
94-
string[] excludedSourceFilesValue = context.ParseResult.GetValueForOption(excludedSourceFiles);
95-
string[] includeDirectoriesValue = context.ParseResult.GetValueForOption(includeDirectories);
96-
string[] excludeAttributesValue = context.ParseResult.GetValueForOption(excludeAttributes);
97-
bool includeTestAssemblyValue = context.ParseResult.GetValueForOption(includeTestAssembly);
98-
bool singleHitValue = context.ParseResult.GetValueForOption(singleHit);
99-
bool skipAutoPropValue = context.ParseResult.GetValueForOption(skipAutoProp);
100-
string mergeWithValue = context.ParseResult.GetValueForOption(mergeWith);
101-
bool useSourceLinkValue = context.ParseResult.GetValueForOption(useSourceLink);
102-
string[] doesNotReturnAttributesValue = context.ParseResult.GetValueForOption(doesNotReturnAttributes);
103-
string excludeAssembliesWithoutSourcesValue = context.ParseResult.GetValueForOption(excludeAssembliesWithoutSources);
104-
string sourceMappingFileValue = context.ParseResult.GetValueForOption(sourceMappingFile);
88+
string moduleOrAppDirectoryValue = parseResult.GetValue(moduleOrAppDirectory);
89+
string targetValue = parseResult.GetValue(target);
90+
string targsValue = parseResult.GetValue(targs);
91+
string outputValue = parseResult.GetValue(output);
92+
LogLevel verbosityValue = parseResult.GetValue(verbosity);
93+
string[] formatsValue = parseResult.GetValue(formats);
94+
string thresholdValue = parseResult.GetValue(threshold);
95+
List<string> thresholdTypesValue = parseResult.GetValue(thresholdTypes);
96+
ThresholdStatistic thresholdStatValue = parseResult.GetValue(thresholdStat);
97+
string[] excludeFiltersValue = parseResult.GetValue(excludeFilters);
98+
string[] includeFiltersValue = parseResult.GetValue(includeFilters);
99+
string[] excludedSourceFilesValue = parseResult.GetValue(excludedSourceFiles);
100+
string[] includeDirectoriesValue = parseResult.GetValue(includeDirectories);
101+
string[] excludeAttributesValue = parseResult.GetValue(excludeAttributes);
102+
bool includeTestAssemblyValue = parseResult.GetValue(includeTestAssembly);
103+
bool singleHitValue = parseResult.GetValue(singleHit);
104+
bool skipAutoPropValue = parseResult.GetValue(skipAutoProp);
105+
string mergeWithValue = parseResult.GetValue(mergeWith);
106+
bool useSourceLinkValue = parseResult.GetValue(useSourceLink);
107+
string[] doesNotReturnAttributesValue = parseResult.GetValue(doesNotReturnAttributes);
108+
string excludeAssembliesWithoutSourcesValue = parseResult.GetValue(excludeAssembliesWithoutSources);
109+
string sourceMappingFileValue = parseResult.GetValue(sourceMappingFile);
105110

106111
if (string.IsNullOrEmpty(moduleOrAppDirectoryValue) || string.IsNullOrWhiteSpace(moduleOrAppDirectoryValue))
107112
throw new ArgumentException("No test assembly or application directory specified.");
108113

109-
var taskStatus = await HandleCommand(moduleOrAppDirectoryValue,
114+
int taskStatus = await HandleCommand(moduleOrAppDirectoryValue,
110115
targetValue,
111116
targsValue,
112117
outputValue,
@@ -128,10 +133,13 @@ static int Main(string[] args)
128133
doesNotReturnAttributesValue,
129134
excludeAssembliesWithoutSourcesValue,
130135
sourceMappingFileValue);
131-
context.ExitCode = taskStatus;
136+
//context.ExitCode = taskStatus;
132137

133138
});
134-
return rootCommand.Invoke(args);
139+
140+
CliConfiguration config = new(rootCommand);
141+
142+
await config.InvokeAsync(args).ConfigureAwait(false);
135143
}
136144
private static Task<int> HandleCommand(string moduleOrAppDirectory,
137145
string target,
@@ -385,7 +393,6 @@ string sourceMappingFile
385393

386394
return Task.FromResult(exitCode);
387395

388-
389396
}
390397

391398
catch (Win32Exception we) when (we.Source == "System.Diagnostics.Process")

0 commit comments

Comments
 (0)