Skip to content

Commit

Permalink
(chocolatey#23) Implement all keyword for install command
Browse files Browse the repository at this point in the history
This adds the ability to install all packages from a source via the all
keyword. It runs a list against the current sources, and sets the
package names from that list of packages.

This functionality is only intended to be used with internal
repositories. Therefore a list of public repositories has been added,
and the current sources are checked against it to ensure only internal
sources are specified.
  • Loading branch information
TheCakeIsNaOH committed Jan 9, 2024
1 parent f47af28 commit 0861a57
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace chocolatey.infrastructure.app
{
using System;
using System.Collections.Generic;
using System.Security.Principal;
using adapters;
using filesystem;
Expand Down Expand Up @@ -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";
Expand All @@ -110,6 +113,16 @@ 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<string> PublicNugetSources = new List<string>()
{
ChocolateyCommunityFeedSource,
ChocolateyCommunityFeedPushSource,
ChocolateyCommunityFeedPushSourceOld,
NugetPublicFeedSourceV2,
NugetPublicFeedSourceV3,
ChocolateyLicensedFeedSource,

};

private static string GetHttpCacheLocation()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ choco install nodejs.install --version 0.10.35
choco install <path/to/nuspec>
choco install <path/to/nupkg>
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 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.
Expand Down
29 changes: 28 additions & 1 deletion src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ public virtual ConcurrentDictionary<string, PackageResult> Install(ChocolateyCon
_fileSystem.EnsureDirectoryExists(ApplicationParameters.PackagesLocation);
var packageResultsToReturn = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);

//todo: #23 handle all
SetRemotePackageNamesIfAllSpecified(config, () => { });

NuGetVersion version = !string.IsNullOrWhiteSpace(config.Version) ? NuGetVersion.Parse(config.Version) : null;
if (config.Force) config.AllowDowngrade = true;
Expand Down Expand Up @@ -2730,6 +2730,33 @@ private IEnumerable<PackageResult> SetLocalPackageNamesIfAllSpecified(Chocolatey
return allPackages;
}

private void SetRemotePackageNamesIfAllSpecified(ChocolateyConfiguration config, Action customAction)
{
if (config.PackageNames.is_equal_to(ApplicationParameters.AllPackages))
{
foreach (string repositoryUrl in ApplicationParameters.PublicNugetSources)
{
if (config.Sources.contains(repositoryUrl))
{
throw new ApplicationException("Installing all packages from {0} is not supported.{1}Only internal nuget repositories are supported."
.format_with(repositoryUrl, Environment.NewLine));
}
}

var isQuiet = config.QuietOutput;
config.QuietOutput = true;
var input = config.Input;
config.Input = string.Empty;
var remotePackageList = list_run(config).Select(p => p.Name).ToList();
config.QuietOutput = isQuiet;
config.Input = input;

config.PackageNames = remotePackageList.@join(ApplicationParameters.PackageNamesSeparator);

if (customAction != null) customAction.Invoke();
}
}

#pragma warning disable IDE1006
[Obsolete("This overload is deprecated and will be removed in v3.")]
public void ensure_source_app_installed(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> ensureAction)
Expand Down

0 comments on commit 0861a57

Please sign in to comment.