< Summary

Information
Class: DirectSight.ReportConfigurationBuilder
Assembly DirectSight
File(s): /home/runner/work/DirectSight/DirectSight/DirectSight/ReportConfigurationBuilder.cs
Line coverage
82%
Covered lines: 38
Uncovered lines: 8
Coverable lines: 46
Total lines: 94
Line coverage: 82.6%
Branch coverage
85%
Covered branches: 12
Total branches: 14
Branch coverage: 85.7%
Method coverage

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
Create(...)100%66100%
Create(...)75%8865.21%

File(s)

/home/runner/work/DirectSight/DirectSight/DirectSight/ReportConfigurationBuilder.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DirectSight.Common;
 4using DirectSight.Logging;
 5
 6namespace DirectSight;
 7
 8/// <summary>
 9/// Builder for <see cref="ReportConfiguration"/>.
 10/// Creates instances of <see cref="ReportConfiguration"/> based on command line parameters.
 11/// </summary>
 12public class ReportConfigurationBuilder
 13{
 14    /// <summary>
 15    /// The argument separators.
 16    /// </summary>
 117    private static readonly char ArgumentSeparator = ';';
 18
 19    /// <summary>
 20    /// Initializes a new instance of the <see cref="ReportConfiguration"/> class.
 21    /// </summary>
 22    /// <param name="cliArguments">The command line arguments stored as key value pairs.</param>
 23    /// <returns>The report configuration.</returns>
 24    public static ReportConfiguration Create(Dictionary<string, string> cliArguments)
 325    {
 326        var namedArguments = new Dictionary<string, string>(cliArguments);
 27
 328        var reportFilePatterns = Array.Empty<string>();
 329        var targetDirectory = string.Empty;
 330        string debugMode = null;
 31
 32
 333        if (namedArguments.TryGetValue(CommandLineArgumentNames.Reports, out string value))
 334        {
 335            reportFilePatterns = value.SplitThatEnsuresGlobsAreSafe(ArgumentSeparator);
 336        }
 37
 338        if (namedArguments.TryGetValue(CommandLineArgumentNames.TargetDirectory, out value))
 339        {
 340            targetDirectory = value;
 341        }
 42
 343        if (namedArguments.TryGetValue(CommandLineArgumentNames.DebugMode, out value))
 344        {
 345            debugMode = value;
 346        }
 47
 348        return new ReportConfiguration(
 349            reportFilePatterns,
 350            targetDirectory,
 351            debugMode);
 352    }
 53
 54    /// <summary>
 55    /// Initializes a new instance of the <see cref="ReportConfiguration"/> class.
 56    /// </summary>
 57    /// <param name="args">The command line arguments.</param>
 58    /// <returns>The report configuration.</returns>
 59    internal static ReportConfiguration Create(string[] args)
 360    {
 361        ArgumentNullException.ThrowIfNull(args);
 62
 363        var namedArguments = new Dictionary<string, string>();
 64
 2765        foreach (var arg in args)
 966        {
 967            var match = CommandLineArgumentNames.CommandLineParameterRegex.Match(arg);
 68
 969            if (!match.Success) continue;
 70
 971            var matchKey = match.Groups["key"].Value;
 72
 973            if (namedArguments.TryGetValue(matchKey, out string value))
 074            {
 075                ConsoleLogger.Warn(
 076                    "Duplicate command line parameter '{0}'. Using value '{1}'",
 077                    matchKey,
 078                    value);
 79
 080                continue;
 81            }
 82
 983            if (CommandLineArgumentNames.IsValid(matchKey))
 984            {
 985                namedArguments[matchKey] = match.Groups["value"].Value;
 986                continue;
 87            }
 88
 089            ConsoleLogger.Warn("Unknown command line parameter '{0}'", matchKey);
 090        }
 91
 392        return Create(namedArguments);
 393    }
 94}