瀏覽代碼

Add version option when interactively running

This adds the ability to query OhmGraphite for it's version.

```
.\OhmGraphite.exe run --version
```

The above will print something like the following, with the version printed on
the last line:

```
2021-11-06 07:34:26.0893|INFO|Topshelf.HostFactory|Configuration Result:
[Success] Name OhmGraphite
[Success] DisplayName Ohm Graphite
[Success] Description Extract hardware sensor data and exports it to a given host and port in a graphite compatible format
[Success] ServiceName OhmGraphite
2021-11-06 07:34:26.1141|INFO|Topshelf.HostConfigurators.HostConfiguratorImpl|Topshelf v4.3.0.0, .NET 5.0.6 (5.0.6)
0.22.0.0
```

This serves an alternative to the previous ways of determining the version
installed with powershell:

```pwsh
(Get-Item .\OhmGraphite.exe).VersionInfo.FileVersion
```

or

```pwsh
(Get-Command .\OhmGraphite.exe).Version
```

or right clicking on the executable to get details.
Nick Babcock 3 年之前
父節點
當前提交
ba124b148c
共有 1 個文件被更改,包括 10 次插入0 次删除
  1. 10 0
      OhmGraphite/Program.cs

+ 10 - 0
OhmGraphite/Program.cs

@@ -2,6 +2,7 @@
 using System.Configuration;
 using System.Diagnostics;
 using System.IO;
+using System.Reflection;
 using NLog;
 using LibreHardwareMonitor.Hardware;
 using Prometheus;
@@ -16,12 +17,20 @@ namespace OhmGraphite
         private static void Main()
         {
             string configPath = string.Empty;
+            bool showVersion = false;
             HostFactory.Run(x =>
             {
                 x.Service<IManage>(s =>
                 {
                     s.ConstructUsing(name =>
                     {
+                        if (showVersion)
+                        {
+                            var version = Assembly.GetExecutingAssembly().GetName().Version?.ToString();
+                            Console.WriteLine(version ?? "no version detected");
+                            Environment.Exit(0);
+                        }
+
                         var configDisplay = string.IsNullOrEmpty(configPath) ? "default" : configPath;
                         var config = Logger.LogFunction($"parse config {configDisplay}", () => MetricConfig.ParseAppSettings(CreateConfiguration(configPath)));
 
@@ -45,6 +54,7 @@ namespace OhmGraphite
 
                 // Allow one to specify a command line argument when running interactively
                 x.AddCommandLineDefinition("config", v => configPath = v);
+                x.AddCommandLineSwitch("version", v => showVersion = v);
                 x.UseNLog();
                 x.RunAsLocalSystem();
                 x.SetDescription(