diff --git a/src/CodeCoverageSummary/CodeCoverageSummary.csproj b/src/CodeCoverageSummary/CodeCoverageSummary.csproj index 1d2d39a..a115c84 100644 --- a/src/CodeCoverageSummary/CodeCoverageSummary.csproj +++ b/src/CodeCoverageSummary/CodeCoverageSummary.csproj @@ -5,4 +5,8 @@ net5.0 + + + + diff --git a/src/CodeCoverageSummary/CommandLineOptions.cs b/src/CodeCoverageSummary/CommandLineOptions.cs new file mode 100644 index 0000000..22be465 --- /dev/null +++ b/src/CodeCoverageSummary/CommandLineOptions.cs @@ -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; } + } +} diff --git a/src/CodeCoverageSummary/Program.cs b/src/CodeCoverageSummary/Program.cs index da3f92c..9ec659f 100644 --- a/src/CodeCoverageSummary/Program.cs +++ b/src/CodeCoverageSummary/Program.cs @@ -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(args) + .MapResult(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)