diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index 6d70b29254..3e62b1a0b1 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -15,6 +15,7 @@ // limitations under the License. using System; +using System.Collections.Generic; using System.Security.Principal; using chocolatey.infrastructure.adapters; using chocolatey.infrastructure.filesystem; @@ -101,6 +102,8 @@ public static class ApplicationParameters public static readonly string ChocolateyCommunityFeedPushSource = "https://push.chocolatey.org/"; public static readonly string ChocolateyCommunityGalleryUrl = "https://community.chocolatey.org/"; public static readonly string ChocolateyCommunityFeedSource = "https://community.chocolatey.org/api/v2/"; + public static readonly string NuGetPublicFeedSourceV2 = "https://www.nuget.org/api/v2/"; + public static readonly string NuGetPublicFeedSourceV3 = "https://api.nuget.org/v3/index.json"; public static readonly string ChocolateyLicensedFeedSource = "https://licensedpackages.chocolatey.org/api/v2/"; public static readonly string ChocolateyLicensedFeedSourceName = "chocolatey.licensed"; public static readonly string UserAgent = "Chocolatey Command Line"; @@ -110,6 +113,15 @@ public static class ApplicationParameters public static readonly string PowerShellModulePathProcessDocuments = _fileSystem.CombinePaths(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "WindowsPowerShell\\Modules"); public static readonly string LocalSystemSidString = "S-1-5-18"; public static readonly SecurityIdentifier LocalSystemSid = new SecurityIdentifier(LocalSystemSidString); + public static readonly List PublicNuGetSources = new List() + { + ChocolateyCommunityFeedSource, + ChocolateyCommunityFeedPushSource, + ChocolateyCommunityFeedPushSourceOld, + NuGetPublicFeedSourceV2, + NuGetPublicFeedSourceV3, + ChocolateyLicensedFeedSource, + }; private static string GetHttpCacheLocation() { diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs index af5d646b7e..f02759ac12 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs @@ -314,6 +314,11 @@ choco install nodejs.install --version 0.10.35 choco install choco install +NOTE: `all` is a special package keyword that will allow you to install + all packages available on a source. This keyword is not available for + public repositories like the Chocolatey Community Repository, and is + intended to be used with internal package sources only. + NOTE: See scripting in the command reference (`choco -?`) for how to write proper scripts and integrations. diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index ba71753b0b..0407abc2fd 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -501,7 +501,7 @@ public virtual ConcurrentDictionary Install(ChocolateyCon _fileSystem.EnsureDirectoryExists(ApplicationParameters.PackagesLocation); var packageResultsToReturn = new ConcurrentDictionary(StringComparer.InvariantCultureIgnoreCase); - //todo: #23 handle all + SetRemotePackageNamesIfAllSpecified(config, () => { }); NuGetVersion version = !string.IsNullOrWhiteSpace(config.Version) ? NuGetVersion.Parse(config.Version) : null; if (config.Force) @@ -2913,6 +2913,36 @@ private IEnumerable SetLocalPackageNamesIfAllSpecified(Chocolatey return allPackages; } + private void SetRemotePackageNamesIfAllSpecified(ChocolateyConfiguration config, Action customAction) + { + if (config.PackageNames.IsEqualTo(ApplicationParameters.AllPackages)) + { + foreach (var repositoryUrl in ApplicationParameters.PublicNuGetSources) + { + if (config.Sources.Contains(repositoryUrl.TrimEnd(('/')))) + { + throw new ApplicationException("Installing all packages from {0} is not supported.{1}Only internal NuGet repositories are supported." + .FormatWith(repositoryUrl, Environment.NewLine)); + } + } + + var isQuiet = config.QuietOutput; + config.QuietOutput = true; + var input = config.Input; + config.Input = string.Empty; + var remotePackageList = List(config).Select(p => p.Name).Distinct().ToList(); + config.QuietOutput = isQuiet; + config.Input = input; + + config.PackageNames = remotePackageList.Join(ApplicationParameters.PackageNamesSeparator); + + if (customAction != null) + { + customAction.Invoke(); + } + } + } + #pragma warning disable IDE0022, IDE1006 [Obsolete("This overload is deprecated and will be removed in v3.")] public void ensure_source_app_installed(ChocolateyConfiguration config, Action ensureAction)