diff --git a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 index 9e32783f06..5d4209a3b5 100644 --- a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 +++ b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 @@ -38,7 +38,7 @@ function script:chocoCmdOperations($commands, $command, $filter, $currentArgumen $script:chocoCommands = @('-?','search','list','info','install','outdated','upgrade','uninstall','new','pack','push','-h','--help','pin','source','config','feature','apikey','export','help','template','--version') # ensure these all have a space to start, or they will cause issues -$allcommands = " --debug --verbose --trace --noop --help -? --accept-license --confirm --limit-output --no-progress --log-file='' --execution-timeout='' --cache-location='' --proxy='' --proxy-user='' --proxy-password='' --proxy-bypass-list='' --proxy-bypass-on-local --force --no-color --skip-compatibility-checks" +$allcommands = " --debug --verbose --trace --noop --help -? --online --accept-license --confirm --limit-output --no-progress --log-file='' --execution-timeout='' --cache-location='' --proxy='' --proxy-user='' --proxy-password='' --proxy-bypass-list='' --proxy-bypass-on-local --force --no-color --skip-compatibility-checks" $commandOptions = @{ list = "--id-only --pre --exact --by-id-only --id-starts-with --detailed --prerelease --include-programs --page='' --page-size=''" diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index d417e2de7f..53a17c11ce 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -285,6 +285,7 @@ private static ChocolateyConfiguration baseline_configuration() config.ForceDependencies = false; config.ForceX86 = false; config.HelpRequested = false; + config.ShowOnlineHelp = false; config.UnsuccessfulParsing = false; config.UnsuccessfulParsing = false; config.IgnoreDependencies = false; diff --git a/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs b/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs index a07fdd7e6a..f076c05c5a 100644 --- a/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs +++ b/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs @@ -100,6 +100,19 @@ public void Should_show_help_menu_when_help_is_requested() because(); config.HelpRequested.ShouldBeTrue(); + config.ShowOnlineHelp.ShouldBeFalse(); + } + + [Fact] + public void Should_show_online_help_menu_when_help_is_requested() + { + args.Add("-h"); + args.Add("--online"); + + because(); + + config.HelpRequested.ShouldBeTrue(); + config.ShowOnlineHelp.ShouldBeTrue(); } [Fact] diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index 3e90eed2fc..67cc2b401f 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -448,8 +448,11 @@ private static void SetGlobalOptions(IList args, ChocolateyConfiguration { if (!string.IsNullOrWhiteSpace(config.CommandName)) { - // save help for next menu + // The setOptions lambda above is called twice, once to set the command name, and then to execute the command with all options. + // To ensure correct option of the help options, we need to reset them to false in the first execution, to then have them parsed correctly in the second + // iteration. config.HelpRequested = false; + config.ShowOnlineHelp = false; config.UnsuccessfulParsing = false; } }, diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 8093447e92..19955e5558 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -263,6 +263,7 @@ private void AppendOutput(StringBuilder propertyValues, string append) // top level commands + public bool ShowOnlineHelp { get; set; } public bool Debug { get; set; } public bool Verbose { get; set; } public bool Trace { get; set; } diff --git a/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs b/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs index 6935c3c377..8a19f00c1e 100644 --- a/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs +++ b/src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs @@ -19,6 +19,7 @@ namespace chocolatey.infrastructure.app.configuration using System; using System.Collections.Generic; using System.ComponentModel; + using System.Diagnostics; using System.Linq; using System.Text.RegularExpressions; using adapters; @@ -75,8 +76,11 @@ public static void ParseArgumentsAndUpdateConfiguration(ICollection args { _optionSet .Add("?|help|h", - "Prints out the help menu.", - option => configuration.HelpRequested = option != null); + "Prints out the help menu.", + option => configuration.HelpRequested = option != null) + .Add("online", + "Online - Open help for specified command in default browser application. This option only works when used in combintation with the -?/--help/-h option.", + option => configuration.ShowOnlineHelp = option != null); } if (setOptions != null) @@ -120,10 +124,38 @@ public static void ParseArgumentsAndUpdateConfiguration(ICollection args if (configuration.HelpRequested) { + if (configuration.ShowOnlineHelp) + { + if (string.IsNullOrWhiteSpace(configuration.CommandName)) + { + "chocolatey".Log().Warn("Unable to open command help as no command name has been provided."); + return; + } + + var targetAddress = "https://ch0.co/c/{0}".FormatWith(configuration.CommandName.ToLowerSafe()); + + try + { + System.Diagnostics.Process.Start(new ProcessStartInfo(targetAddress) { UseShellExecute = true }); + } + catch (Exception) + { + "chocolatey".Log().Warn("There was an error while attempting to open the following URL: {0} in the default browser.".FormatWith(targetAddress)); + } + + return; + } + ShowHelp(_optionSet, helpMessage); } else { + // Only show this warning once + if (configuration.ShowOnlineHelp) + { + "chocolatey".Log().Warn("The --online option has been used, without the corresponding -?/--help/-h option. Command execution will be completed without invoking help."); + } + if (validateConfiguration != null) { validateConfiguration();