Added command line options parsing and possibility to override config
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ini-parser" Version="2.5.2" />
|
||||
<PackageReference Include="NLog" Version="4.7.4" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
+21
-1
@@ -1,6 +1,9 @@
|
||||
using IniParser;
|
||||
using NLog;
|
||||
using System.Collections.Generic;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Invocation;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
@@ -16,6 +19,19 @@ namespace Barsik
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-US");
|
||||
var rootCommand = new RootCommand();
|
||||
var runCommand = new Command("run")
|
||||
{
|
||||
new Option<string>("--config", () => "", "Path to configuration file")
|
||||
};
|
||||
runCommand.Handler = CommandHandler.Create<string>(RunService);
|
||||
rootCommand.AddCommand(runCommand);
|
||||
rootCommand.InvokeAsync(args).Wait();
|
||||
}
|
||||
|
||||
static void RunService(string configPath)
|
||||
{
|
||||
Logging.Setup();
|
||||
logger.Info("Barsik monitoring service starting");
|
||||
|
||||
@@ -24,8 +40,12 @@ namespace Barsik
|
||||
units = new List<BaseMonitoringUnit>();
|
||||
|
||||
var configParser = new FileIniDataParser();
|
||||
if (string.IsNullOrEmpty(configPath))
|
||||
{
|
||||
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
var data = configParser.ReadFile(Path.Combine(assemblyFolder, "barsik.ini"));
|
||||
configPath = Path.Combine(assemblyFolder, "barsik.ini");
|
||||
}
|
||||
var data = configParser.ReadFile(configPath);
|
||||
foreach (var section in data.Sections)
|
||||
{
|
||||
if (section.SectionName.StartsWith("Unit"))
|
||||
|
||||
Reference in New Issue
Block a user