Skip to content

Commit

Permalink
Exclude main program from coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalker5 committed Aug 27, 2023
1 parent 116c8d0 commit 3125148
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/BaseStationReader.Terminal/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
using Serilog;
using Spectre.Console;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace BaseStationReader.Terminal
{
[ExcludeFromCodeCoverage]
public class Program
{
private readonly static Table _table = new Table().Expand().BorderColor(Spectre.Console.Color.Grey);
Expand All @@ -21,7 +23,7 @@ public class Program
public static async Task Main(string[] args)
{
// Read the application config
ApplicationSettings? settings = new ConfigReader().Read("appsettings.json");
ApplicationSettings? settings = BuildSettings(args);

// Configure the log file
#pragma warning disable CS8602
Expand Down Expand Up @@ -65,6 +67,60 @@ await AnsiConsole.Live(_table)
});
}

/// <summary>
/// Construct the application settings from the configuration file and any command line arguments
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
private static ApplicationSettings? BuildSettings(IEnumerable<string> args)
{
// Read the config file to provide default settings
var settings = new ConfigReader().Read("appsettings.json");

// Parse the command line
var parser = new CommandLineParser();
parser.Add(CommandLineOptionType.Host, false, "--host", "-h", "Host to connect to for data stream", 1, 1);
parser.Add(CommandLineOptionType.Port, false, "--port", "-p", "Port to connect to for data stream", 1, 1);
parser.Add(CommandLineOptionType.TimeToRecent, false, "--recent", "-r", "Time (ms) to 'recent' staleness", 1, 1);
parser.Add(CommandLineOptionType.TimeToStale, false, "--stale", "-s", "Time (ms) to 'stale' staleness", 1, 1);
parser.Add(CommandLineOptionType.TimeToRemoval, false, "--remove", "-x", "Time (ms) removal of stale records", 1, 1);
parser.Add(CommandLineOptionType.LogFile, false, "--log-file", "-l", "Log file path and name", 1, 1);
parser.Add(CommandLineOptionType.EnableSqlWriter, false, "--enable-sql-writer", "-w", "Log file path and name", 1, 1);
parser.Add(CommandLineOptionType.WriterInterval, false, "--writer-interval", "-i", "SQL write interval (ms)", 1, 1);
parser.Add(CommandLineOptionType.WriterBatchSize, false, "--writer-batch-size", "-b", "SQL write batch size", 1, 1);
parser.Parse(args);

// Apply the command line values over the defaults
var values = parser.GetValues(CommandLineOptionType.Host);
if (values != null) settings!.Host = values.First();

values = parser.GetValues(CommandLineOptionType.Port);
if (values != null) settings!.Port = int.Parse(values.First());

values = parser.GetValues(CommandLineOptionType.TimeToRecent);
if (values != null) settings!.TimeToRecent = int.Parse(values.First());

values = parser.GetValues(CommandLineOptionType.TimeToStale);
if (values != null) settings!.TimeToStale = int.Parse(values.First());

values = parser.GetValues(CommandLineOptionType.TimeToRemoval);
if (values != null) settings!.TimeToRemoval = int.Parse(values.First());

values = parser.GetValues(CommandLineOptionType.LogFile);
if (values != null) settings!.LogFile = values.First();

values = parser.GetValues(CommandLineOptionType.EnableSqlWriter);
if (values != null) settings!.EnableSqlWriter = bool.Parse(values.First());

values = parser.GetValues(CommandLineOptionType.WriterInterval);
if (values != null) settings!.WriterInterval = int.Parse(values.First());

values = parser.GetValues(CommandLineOptionType.WriterBatchSize);
if (values != null) settings!.WriterBatchSize = int.Parse(values.First());

return settings;
}

/// <summary>
/// Display and continuously update the tracking table
/// </summary>
Expand Down

0 comments on commit 3125148

Please sign in to comment.