diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index a54b5a4b36..28c68cb8b3 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -113,6 +113,7 @@ public static class Features public static readonly string LogEnvironmentValues = "logEnvironmentValues"; public static readonly string VirusCheck = "virusCheck"; public static readonly string FailOnInvalidOrMissingLicense = "failOnInvalidOrMissingLicense"; + public static readonly string IgnoreInvalidOptionsSwitches = "ignoreInvalidOptionsSwitches"; } public static class Messages diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index 8d7f9485f0..097865e38f 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -245,6 +245,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile config.Features.LogEnvironmentValues = set_feature_flag(ApplicationParameters.Features.LogEnvironmentValues, configFileSettings, defaultEnabled: false, description: "Log Environment Values - will log values of environment before and after install (could disclose sensitive data)."); config.Features.VirusCheck = set_feature_flag(ApplicationParameters.Features.VirusCheck, configFileSettings, defaultEnabled: false, description: "Virus Check [licensed versions only] - perform virus checking on downloaded files."); config.Features.FailOnInvalidOrMissingLicense = set_feature_flag(ApplicationParameters.Features.FailOnInvalidOrMissingLicense, configFileSettings, defaultEnabled: false, description: "Fail On Invalid Or Missing License - allows knowing when a license is expired or not applied to a machine."); + config.Features.IgnoreInvalidOptionsSwitches = set_feature_flag(ApplicationParameters.Features.IgnoreInvalidOptionsSwitches, configFileSettings, defaultEnabled: true, description: "Ignore Invalid Options/Switches - If a switch or option is passed that is not recognized, should choco fail?"); config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass."); } diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 5db1b955c9..de802a5b02 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -341,6 +341,7 @@ public sealed class FeaturesConfiguration public bool LogEnvironmentValues { get; set; } public bool VirusCheck { get; set; } public bool FailOnInvalidOrMissingLicense { get; set; } + public bool IgnoreInvalidOptionsSwitches { get; set; } } //todo: retrofit other command configs this way diff --git a/src/chocolatey/infrastructure.app/runners/ConsoleApplication.cs b/src/chocolatey/infrastructure.app/runners/ConsoleApplication.cs index 39e9185c97..3066d5a5f0 100644 --- a/src/chocolatey/infrastructure.app/runners/ConsoleApplication.cs +++ b/src/chocolatey/infrastructure.app/runners/ConsoleApplication.cs @@ -60,13 +60,16 @@ public void run(string[] args, ChocolateyConfiguration config, Container contain command.handle_additional_argument_parsing(unparsedArgs, config); - // all options / switches should be parsed, - // so show help menu if there are any left - foreach (var unparsedArg in unparsedArgs.or_empty_list_if_null()) + if (!config.Features.IgnoreInvalidOptionsSwitches) { - if (unparsedArg.StartsWith("-") || unparsedArg.StartsWith("/")) + // all options / switches should be parsed, + // so show help menu if there are any left + foreach (var unparsedArg in unparsedArgs.or_empty_list_if_null()) { - config.HelpRequested = true; + if (unparsedArg.StartsWith("-") || unparsedArg.StartsWith("/")) + { + config.HelpRequested = true; + } } } },