From d9318814b82ae98c5e69015181438f272cca89fb Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 25 Feb 2015 07:42:15 -0600 Subject: [PATCH] (GH-119) Report version Respond to `choco -v` and `choco --version` by just printing the version. Older versions of chocolatey will ignore `choco --version` and report the default text which contains the version, so this is great for determining what version choco is on across both clients. --- src/chocolatey.console/Program.cs | 18 +++++++++++++++++- .../configuration/ConfigurationOptions.cs | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/chocolatey.console/Program.cs b/src/chocolatey.console/Program.cs index bfe47a604d..ca74eb8cf4 100644 --- a/src/chocolatey.console/Program.cs +++ b/src/chocolatey.console/Program.cs @@ -18,6 +18,7 @@ namespace chocolatey.console using System; using System.Collections.Generic; using System.IO; + using System.Linq; using infrastructure.adapters; using infrastructure.app; using infrastructure.app.builders; @@ -58,7 +59,7 @@ private static void Main(string[] args) var warnings = new List(); - ConfigurationBuilder.set_up_configuration( + ConfigurationBuilder.set_up_configuration( args, config, fileSystem, @@ -67,6 +68,8 @@ private static void Main(string[] args) ); Config.initialize_with(config); + report_version_and_exit_if_requested(args, config); + trap_exit_scenarios(config); if (config.RegularOuptut) @@ -156,6 +159,19 @@ private static void Main(string[] args) } } + private static void report_version_and_exit_if_requested(string[] args, ChocolateyConfiguration config) + { + if (args == null || args.Length == 0) return; + + var firstArg = args.FirstOrDefault(); + if (firstArg.is_equal_to("-v") || firstArg.is_equal_to("--version")) + { + "chocolatey".Log().Info(ChocolateyLoggers.Important, () => "{0}".format_with(config.Information.ChocolateyProductVersion)); + pause_execution_if_debug(); + Environment.Exit(0); + } + } + static EventHandler _handler; private static void trap_exit_scenarios(ChocolateyConfiguration config) diff --git a/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs b/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs index 602d203b37..aa76a485dc 100644 --- a/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs +++ b/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs @@ -95,6 +95,10 @@ public static void parse_arguments_and_update_configuration(ICollection { configuration.CommandName = commandName; } + else if (commandName.is_equal_to("-v") || commandName.is_equal_to("--version")) + { + // skip help menu + } else { configuration.HelpRequested = true;