mirror of
https://github.com/irongut/CodeCoverageSummary.git
synced 2026-05-16 15:00:14 +02:00
added args using CommandLineParser
This commit is contained in:
@@ -5,4 +5,8 @@
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.8.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using CommandLine;
|
||||
|
||||
namespace CodeCoverageSummary
|
||||
{
|
||||
public class CommandLineOptions
|
||||
{
|
||||
[Value(index: 0, Required = true, HelpText = "Code coverage file to analyse.")]
|
||||
public string Filename { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using CommandLine;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -8,21 +9,33 @@ namespace CodeCoverageSummary
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private const string _filename = "D:\\Dev\\Csharp\\CodeCoverageSummary\\coverage.cobertura.xml";
|
||||
//private const string _filename = "D:\\Dev\\Csharp\\CodeCoverageSummary\\coverage.cobertura.xml";
|
||||
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
Console.WriteLine($"Parsing Code Coverage File: {_filename}{Environment.NewLine}");
|
||||
string summary = ParseTestResults(_filename);
|
||||
if (string.IsNullOrWhiteSpace(summary))
|
||||
{
|
||||
return -3;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(summary);
|
||||
return 0;
|
||||
}
|
||||
return Parser.Default.ParseArguments<CommandLineOptions>(args)
|
||||
.MapResult<CommandLineOptions, int>(o =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"Parsing Code Coverage File: {o.Filename}{Environment.NewLine}");
|
||||
string summary = ParseTestResults(o.Filename);
|
||||
if (string.IsNullOrWhiteSpace(summary))
|
||||
{
|
||||
return -2; // error
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(summary);
|
||||
return 0; // success
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return -3; // unhandled error
|
||||
}
|
||||
},
|
||||
errs => -1); // invalid arguments
|
||||
}
|
||||
|
||||
private static string ParseTestResults(string filename)
|
||||
|
||||
Reference in New Issue
Block a user