diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInfoCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInfoCommandSpecs.cs index 308b8db85e..2a6e63b112 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInfoCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInfoCommandSpecs.cs @@ -133,6 +133,12 @@ public void should_add_short_version_of_password_to_the_option_set() { optionSet.Contains("p").ShouldBeTrue(); } + + [Fact] + public void should_add_include_sources_from_config_to_the_option_set() + { + optionSet.Contains("include-sources-from-config").ShouldBeTrue(); + } } public class when_handling_additional_argument_parsing : ChocolateyInfoCommandSpecsBase diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs index 9eb359f23d..8ba4bd87bf 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs @@ -266,6 +266,12 @@ public void should_add_short_version_of_skip_hooks_to_the_option_set() { optionSet.Contains("skiphooks").ShouldBeTrue(); } + + [Fact] + public void should_add_include_sources_from_config_to_the_option_set() + { + optionSet.Contains("include-sources-from-config").ShouldBeTrue(); + } } public class when_handling_additional_argument_parsing : ChocolateyInstallCommandSpecsBase diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs index d808bc4e7c..f5885d3b9c 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs @@ -294,6 +294,12 @@ public void should_add_short_version_of_password_to_the_option_set() optionSet.Contains("p").ShouldBeTrue(); } + [Fact] + public void should_add_include_sources_from_config_to_the_option_set() + { + optionSet.Contains("include-sources-from-config").ShouldBeTrue(); + } + [NUnit.Framework.Theory] [NUnit.Framework.TestCase("localonly")] [NUnit.Framework.TestCase("source")] @@ -304,6 +310,7 @@ public void should_add_short_version_of_password_to_the_option_set() [NUnit.Framework.TestCase("approved-only")] [NUnit.Framework.TestCase("download-cache-only")] [NUnit.Framework.TestCase("disable-package-repository-optimizations")] + [NUnit.Framework.TestCase("include-sources-from-config")] public void should_add_deprecation_notice_to_option(string argument) { optionSet[argument].Description.ShouldNotContain("DEPRECATION NOTICE"); diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs index 29ee7f966d..ab9c4c547c 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs @@ -114,6 +114,12 @@ public void should_add_ignore_pinned_to_the_option_set() { optionSet.Contains("ignore-pinned").ShouldBeTrue(); } + + [Fact] + public void should_add_include_sources_from_config_to_the_option_set() + { + optionSet.Contains("include-sources-from-config").ShouldBeTrue(); + } } public class when_noop_is_called : ChocolateyOutdatedCommandSpecsBase diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs index 5fe367a9ef..a4b98c68fb 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs @@ -248,6 +248,12 @@ public void should_add_short_version_of_skip_hooks_to_the_option_set() { optionSet.Contains("skiphooks").ShouldBeTrue(); } + + [Fact] + public void should_add_include_sources_from_config_to_the_option_set() + { + optionSet.Contains("include-sources-from-config").ShouldBeTrue(); + } } public class when_handling_additional_argument_parsing : ChocolateyUpgradeCommandSpecsBase diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyInfoCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyInfoCommand.cs index de65dc3c0b..379e70f6ad 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyInfoCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyInfoCommand.cs @@ -73,6 +73,9 @@ public override void configure_argument_parser(OptionSet optionSet, ChocolateyCo configuration.Features.UsePackageRepositoryOptimizations = false; } }) + .Add("include-sources-from-config", + "Include Sources From Configuration - Include the sources used when --source is not specified, which are configured by the source command. Available in 1.2.0+", + option => configuration.IncludeMachineSources = option != null) ; } diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs index 495f0d656d..b30a75407f 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs @@ -187,6 +187,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon "Skip hooks - Do not run hook scripts. Available in 1.2.0+", option => configuration.SkipHookScripts = option != null ) + .Add("include-sources-from-config", + "Include Sources From Configuration - Include the sources used when --source is not specified, which are configured by the source command. Available in 1.2.0+", + option => configuration.IncludeMachineSources = option != null + ) ; //todo: #770 package name can be a url / installertype diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index 5eaf697342..0a371f12e4 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -136,6 +136,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon configuration.Features.UsePackageRepositoryOptimizations = false; } }) + .Add("include-sources-from-config", + "Include Sources From Configuration - Include the sources used when --source is not specified, which are configured by the source command. Available in 1.2.0+", + option => configuration.IncludeMachineSources = option != null) ; } diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyOutdatedCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyOutdatedCommand.cs index 750fef4185..874ca7be66 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyOutdatedCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyOutdatedCommand.cs @@ -71,6 +71,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon configuration.Features.UsePackageRepositoryOptimizations = false; } }) + .Add("include-sources-from-config", + "Include Sources From Configuration - Include the sources used when --source is not specified, which are configured by the source command. Available in 1.2.0+", + option => configuration.IncludeMachineSources = option != null) ; } diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index 6accfe2334..47c90effbc 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -226,6 +226,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon "Skip hooks - Do not run hook scripts. Available in 1.2.0+", option => configuration.SkipHookScripts = option != null ) + .Add("include-sources-from-config", + "Include Sources From Configuration - Include the sources used when --source is not specified, which are configured by the source command. Available in 1.2.0+", + option => configuration.IncludeMachineSources = option != null + ) ; } diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 6bb87039a8..e78670eb89 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -253,6 +253,7 @@ private void append_output(StringBuilder propertyValues, string append) public string Sources { get; set; } public string SourceType { get; set; } + public bool IncludeMachineSources { get; set; } // top level commands diff --git a/src/chocolatey/infrastructure.app/runners/GenericRunner.cs b/src/chocolatey/infrastructure.app/runners/GenericRunner.cs index 769d4d78fc..7396b53f5f 100644 --- a/src/chocolatey/infrastructure.app/runners/GenericRunner.cs +++ b/src/chocolatey/infrastructure.app/runners/GenericRunner.cs @@ -72,6 +72,7 @@ private ICommand find_command(ChocolateyConfiguration config, Container containe } set_source_type(config, container); + include_machine_sources(config); // guaranteed that all settings are set. EnvironmentSettings.set_environment_variables(config); @@ -127,6 +128,29 @@ private void set_source_type(ChocolateyConfiguration config, Container container this.Log().Debug(() => "The source '{0}' evaluated to a '{1}' source type".format_with(config.Sources, sourceType)); } + private void include_machine_sources(ChocolateyConfiguration config) + { + if (config.IncludeMachineSources) + { + if (config.SourceType != SourceTypes.NORMAL) + { + this.Log().Warn("Not including sources from config because {0} is an alternate source".format_with(config.Sources)); + } + else + { + foreach (var machineSource in config.MachineSources.or_empty_list_if_null()) + { + if (!config.Sources.contains(machineSource.Key)) + { + config.Sources += ";" + machineSource.Key; + } + } + + this.Log().Debug("Including sources from config"); + } + } + } + public void fail_when_license_is_missing_or_invalid_if_requested(ChocolateyConfiguration config) { if (!config.Features.FailOnInvalidOrMissingLicense ||