From 1a619a6df087f18801c70ba1fe52790fc5fbfd8a Mon Sep 17 00:00:00 2001 From: Bilal Fazlani Date: Tue, 9 Jan 2018 21:38:29 +0530 Subject: [PATCH] Fixes #26 , Added version option. Its on by default and can be turned off with settings --- CommandDotNet/AppCreator.cs | 12 ++++++++++++ CommandDotNet/Enums/MultiValueType.cs | 8 -------- CommandDotNet/Models/AppSettings.cs | 2 ++ 3 files changed, 14 insertions(+), 8 deletions(-) delete mode 100644 CommandDotNet/Enums/MultiValueType.cs diff --git a/CommandDotNet/AppCreator.cs b/CommandDotNet/AppCreator.cs index 76a8587aa..d4c683bc8 100644 --- a/CommandDotNet/AppCreator.cs +++ b/CommandDotNet/AppCreator.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Reflection; using CommandDotNet.Attributes; using CommandDotNet.MicrosoftCommandLineUtils; @@ -30,6 +31,8 @@ public CommandLineApplication CreateApplication( { string rootName = $"dotnet {Assembly.GetEntryAssembly().GetName().Name}.dll"; app = new CommandLineApplication(throwOnUnexpectedArg: _appSettings.ThrowOnUnexpectedArgument) { Name = rootName }; + + AddVersion(app); } else { @@ -59,5 +62,14 @@ public CommandLineApplication CreateApplication( return app; } + + private void AddVersion(CommandLineApplication app) + { + if (_appSettings.EnableVersionOption) + { + FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location); + app.VersionOption("-v | --version", shortFormVersion: fvi.ProductVersion); + } + } } } \ No newline at end of file diff --git a/CommandDotNet/Enums/MultiValueType.cs b/CommandDotNet/Enums/MultiValueType.cs deleted file mode 100644 index 43d970a46..000000000 --- a/CommandDotNet/Enums/MultiValueType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CommandDotNet -{ - public enum MultiValueType - { - MultipleArguments = 0, - CommaSeparated = 1 - } -} \ No newline at end of file diff --git a/CommandDotNet/Models/AppSettings.cs b/CommandDotNet/Models/AppSettings.cs index 6a66a753d..16929f315 100644 --- a/CommandDotNet/Models/AppSettings.cs +++ b/CommandDotNet/Models/AppSettings.cs @@ -20,6 +20,8 @@ public AppSettings() public ArgumentMode MethodArgumentMode { get; set; } = ArgumentMode.Parameter; public Case Case { get; set; } = Case.DontChange; + + public bool EnableVersionOption { get; set; } = true; } public enum ArgumentMode