浏览代码

Merge pull request #262 from nickbabcock/version

Add version option when interactively running
Nick Babcock 3 年之前
父节点
当前提交
07c5193d79
共有 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(