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;