Skip to content

Commit

Permalink
Merge pull request #40 from davewalker5/add-cli-help
Browse files Browse the repository at this point in the history
Added command line help
  • Loading branch information
davewalker5 authored Aug 16, 2024
2 parents 065e908 + 5675057 commit 274b64c
Show file tree
Hide file tree
Showing 32 changed files with 425 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.302
dotnet-version: 8.0.101
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
Expand Down
22 changes: 11 additions & 11 deletions src/BaseStationReader.Data/BaseStationReader.Data.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>BaseStationReader.Data</PackageId>
<PackageVersion>1.31.0.0</PackageVersion>
<PackageVersion>1.32.0.0</PackageVersion>
<Authors>Dave Walker</Authors>
<Copyright>Copyright (c) Dave Walker 2023</Copyright>
<Copyright>Copyright (c) 2023, 2024 Dave Walker</Copyright>
<Owners>Dave Walker</Owners>
<Summary>Base Station Reader EF Core Database Layer</Summary>
<PackageTags>BaseStationReader database</PackageTags>
Expand All @@ -17,20 +17,20 @@
<PackageProjectUrl>https://github.com/davewalker5/ADS-B-BaseStationReader</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ReleaseVersion>1.31.0.0</ReleaseVersion>
<ReleaseVersion>1.32.0.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.10">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.10" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions src/BaseStationReader.Entities/BaseStationReader.Entities.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>BaseStationReader.Entities</PackageId>
<PackageVersion>1.31.0.0</PackageVersion>
<PackageVersion>1.32.0.0</PackageVersion>
<Authors>Dave Walker</Authors>
<Copyright>Copyright (c) Dave Walker 2023</Copyright>
<Copyright>Copyright (c) 2023, 2024 Dave Walker</Copyright>
<Owners>Dave Walker</Owners>
<Summary>Base Station Reader Domain Models</Summary>
<PackageTags>BaseStationReader domain models entities</PackageTags>
Expand All @@ -17,13 +17,13 @@
<PackageProjectUrl>https://github.com/davewalker5/ADS-B-BaseStationReader</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ReleaseVersion>1.31.0.0</ReleaseVersion>
<ReleaseVersion>1.32.0.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public enum CommandLineOptionType
{
Help,
MinimumLogLevel,
Host,
Port,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;

namespace BaseStationReader.Entities.Exceptions
{

[Serializable]
[ExcludeFromCodeCoverage]
public class DuplicateOptionException : Exception
Expand All @@ -19,14 +17,5 @@ public DuplicateOptionException(string message) : base(message)
public DuplicateOptionException(string message, Exception inner) : base(message, inner)
{
}

protected DuplicateOptionException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
{
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;

namespace BaseStationReader.Entities.Exceptions
{
Expand All @@ -18,14 +17,5 @@ public MalformedCommandLineException(string message) : base(message)
public MalformedCommandLineException(string message, Exception inner) : base(message, inner)
{
}

protected MalformedCommandLineException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
{
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;

namespace BaseStationReader.Entities.Exceptions
{
Expand All @@ -18,14 +17,5 @@ public MissingMandatoryOptionException(string message) : base(message)
public MissingMandatoryOptionException(string message, Exception inner) : base(message, inner)
{
}

protected MissingMandatoryOptionException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
{
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}
10 changes: 0 additions & 10 deletions src/BaseStationReader.Entities/Exceptions/TooFewValuesException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;

namespace BaseStationReader.Entities.Exceptions
{
Expand All @@ -18,14 +17,5 @@ public TooFewValuesException(string message) : base(message)
public TooFewValuesException(string message, Exception inner) : base(message, inner)
{
}

protected TooFewValuesException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
{
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;

namespace BaseStationReader.Entities.Exceptions
{
Expand All @@ -23,14 +17,5 @@ public TooManyValuesException(string message) : base(message)
public TooManyValuesException(string message, Exception inner) : base(message, inner)
{
}

protected TooManyValuesException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
{
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;

namespace BaseStationReader.Entities.Exceptions
{
Expand All @@ -18,14 +17,5 @@ public UnrecognisedCommandLineOptionException(string message) : base(message)
public UnrecognisedCommandLineOptionException(string message, Exception inner) : base(message, inner)
{
}

protected UnrecognisedCommandLineOptionException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
{
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}
13 changes: 13 additions & 0 deletions src/BaseStationReader.Entities/Interfaces/ICommandLineParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using BaseStationReader.Entities.Config;

namespace BaseStationReader.Entities.Interfaces
{
public interface ICommandLineParser
{
void Add(CommandLineOptionType optionType, bool mandatory, string name, string shortName, string description, int minimumNumberOfValues, int maximumNumberOfValues);
List<string>? GetValues(CommandLineOptionType optionType);
void Help();
bool IsPresent(CommandLineOptionType optionType);
void Parse(IEnumerable<string> args);
}
}
9 changes: 9 additions & 0 deletions src/BaseStationReader.Entities/Interfaces/IHelpGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using BaseStationReader.Entities.Config;

namespace BaseStationReader.Entities.Interfaces
{
public interface IHelpGenerator
{
void Generate(IEnumerable<CommandLineOption> options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using BaseStationReader.Entities.Config;
using BaseStationReader.Entities.Interfaces;

namespace BaseStationReader.Entities.Interfaces
{
public interface ISimulatorSettingsBuilder
{
SimulatorApplicationSettings? BuildSettings(ICommandLineParser parser, string configJsonPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace BaseStationReader.Entities.Interfaces
{
public interface ITrackerSettingsBuilder
{
TrackerApplicationSettings? BuildSettings(IEnumerable<string> args, string configJsonPath);
TrackerApplicationSettings? BuildSettings(ICommandLineParser parser, string configJsonPath);
}
}
14 changes: 7 additions & 7 deletions src/BaseStationReader.Logic/BaseStationReader.Logic.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>BaseStationReader.Logic</PackageId>
<PackageVersion>1.31.0.0</PackageVersion>
<PackageVersion>1.32.0.0</PackageVersion>
<Authors>Dave Walker</Authors>
<Copyright>Copyright (c) Dave Walker 2023</Copyright>
<Copyright>Copyright (c) 2023, 2024 Dave Walker</Copyright>
<Owners>Dave Walker</Owners>
<Summary>Base Station Reader Business Logic</Summary>
<PackageTags>BaseStationReader logic</PackageTags>
Expand All @@ -17,13 +17,13 @@
<PackageProjectUrl>https://github.com/davewalker5/ADS-B-BaseStationReader</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ReleaseVersion>1.31.0.0</ReleaseVersion>
<ReleaseVersion>1.32.0.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.102.1" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="ClosedXML" Version="0.102.3" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>

Expand Down
25 changes: 23 additions & 2 deletions src/BaseStationReader.Logic/Configuration/CommandLineParser.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
using BaseStationReader.Entities.Config;
using BaseStationReader.Entities.Exceptions;
using BaseStationReader.Entities.Interfaces;

namespace BaseStationReader.Logic.Configuration
{
public class CommandLineParser
public class CommandLineParser : ICommandLineParser
{
private readonly List<CommandLineOption> _options = new List<CommandLineOption>();
private readonly Dictionary<CommandLineOptionType, CommandLineOptionValue> _values = new Dictionary<CommandLineOptionType, CommandLineOptionValue>();
private readonly IHelpGenerator? _helpGenerator = null;

public CommandLineParser() { }

public CommandLineParser(IHelpGenerator? generator)
=> _helpGenerator = generator;

/// <summary>
/// Add an option to the available command line options
Expand Down Expand Up @@ -68,6 +75,14 @@ public void Parse(IEnumerable<string> args)
CheckForMandatoryOptions();
}

/// <summary>
/// Return true if a command line option has been specified
/// </summary>
/// <param name="optionType"></param>
/// <returns></returns>
public bool IsPresent(CommandLineOptionType optionType)
=> _values.ContainsKey(optionType);

/// <summary>
/// Return the valus for the specified option type
/// </summary>
Expand All @@ -77,14 +92,20 @@ public void Parse(IEnumerable<string> args)
{
List<string>? values = null;

if (_values.ContainsKey(optionType))
if (IsPresent(optionType))
{
values = _values[optionType].Values;
}

return values;
}

/// <summary>
/// Generate help
/// </summary>
public void Help()
=> _helpGenerator?.Generate(_options);

/// <summary>
/// Check that all mandatory options have been specified
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using BaseStationReader.Entities.Config;
using BaseStationReader.Entities.Interfaces;

namespace BaseStationReader.Logic.Configuration
{
public class SimulatorCommandLineParser : CommandLineParser
{
public SimulatorCommandLineParser(IHelpGenerator? generator) : base(generator)
{
Add(CommandLineOptionType.Help, false, "--help", "-h", "Show command line help",0, 0);
Add(CommandLineOptionType.Port, false, "--port", "-p", "Port to send data on", 1, 1);
Add(CommandLineOptionType.SendInterval, false, "--send-interval", "-s", "Message send interval (ms)", 1, 1);
Add(CommandLineOptionType.NumberOfAircraft, false, "--number", "-n", "Number of concurrent simulated aircraft", 1, 1);
Add(CommandLineOptionType.Lifespan, false, "--lifespan", "-ls", "Simulated aircraft lifespan (ms)", 1, 1);
Add(CommandLineOptionType.LogFile, false, "--log-file", "-l", "Log file path and name", 1, 1);
Add(CommandLineOptionType.MinimumLogLevel, false, "--log-level", "-ll", "Minimum logging level (Debug, Info, Warning or Error)", 1, 1);
}
}
}
Loading

0 comments on commit 274b64c

Please sign in to comment.