Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#798) Add pin-version parameter for choco install command to execute choco pin at the end #1915

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ namespace chocolatey.tests.infrastructure.app.commands
using chocolatey.infrastructure.app.domain;
using chocolatey.infrastructure.app.services;
using chocolatey.infrastructure.commandline;
using chocolatey.infrastructure.commands;
using Moq;
using NuGet;
using Should;

public class ChocolateyInstallCommandSpecs
Expand All @@ -34,12 +36,16 @@ public abstract class ChocolateyInstallCommandSpecsBase : TinySpec
{
protected ChocolateyInstallCommand command;
protected Mock<IChocolateyPackageService> packageService = new Mock<IChocolateyPackageService>();
protected Mock<IChocolateyPackageInformationService> chocolateyPackageInformationService = new Mock<IChocolateyPackageInformationService>();
protected Mock<INugetService> nugetService = new Mock<INugetService>();
protected Mock<ILogger> nugetLogger = new Mock<ILogger>();
protected ChocolateyConfiguration configuration = new ChocolateyConfiguration();

public override void Context()
{
configuration.Sources = "bob";
command = new ChocolateyInstallCommand(packageService.Object);
var chocolateyPinCommand = new ChocolateyPinCommand(chocolateyPackageInformationService.Object, nugetLogger.Object, nugetService.Object);
command = new ChocolateyInstallCommand(packageService.Object, chocolateyPinCommand, nugetLogger.Object);
}
}

Expand Down Expand Up @@ -235,6 +241,12 @@ public void should_add_short_version_of_password_to_the_option_set()
{
optionSet.Contains("p").ShouldBeTrue();
}

[Fact]
public void should_add_pinVersion_to_the_option_set()
{
optionSet.Contains("pin-version").ShouldBeTrue();
}
}

public class when_handling_additional_argument_parsing : ChocolateyInstallCommandSpecsBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,27 @@ namespace chocolatey.infrastructure.app.commands
using System.Collections.Generic;
using System.Linq;
using attributes;
using chocolatey.infrastructure.app.nuget;
using commandline;
using configuration;
using infrastructure.commands;
using infrastructure.configuration;
using logging;
using NuGet;
using services;

[CommandFor("install", "installs packages from various sources")]
public class ChocolateyInstallCommand : ICommand
{
private readonly IChocolateyPackageService _packageService;
private readonly ChocolateyPinCommand _chocolateyPinCommand;
private readonly ILogger _nugetLogger;

public ChocolateyInstallCommand(IChocolateyPackageService packageService)
public ChocolateyInstallCommand(IChocolateyPackageService packageService, ChocolateyPinCommand chocolateyPinCommand, ILogger nugetLogger)
{
_packageService = packageService;
_chocolateyPinCommand = chocolateyPinCommand;
_nugetLogger = nugetLogger;
}

public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyConfiguration configuration)
Expand Down Expand Up @@ -180,6 +186,15 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
configuration.Features.UsePackageRepositoryOptimizations = false;
}
})
.Add("pin-version",
"Pin version to prevent future upgrades.",
option =>
{
if (option != null)
{
configuration.Features.PinVersion = true;
}
})
;

//todo: package name can be a url / installertype
Expand Down Expand Up @@ -436,6 +451,17 @@ public virtual void run(ChocolateyConfiguration configuration)
{
_packageService.ensure_source_app_installed(configuration);
_packageService.install_run(configuration);

if (configuration.Features.PinVersion)
{
var packageManager = NugetCommon.GetPackageManager(configuration, _nugetLogger,
new PackageDownloader(),
installSuccessAction: null,
uninstallSuccessAction: null,
addUninstallHandler: false);

_chocolateyPinCommand.set_pin(packageManager, configuration);
}
}

public virtual bool may_require_admin_access()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ public sealed class FeaturesConfiguration
public bool ExitOnRebootDetected { get; set; }
public bool LogValidationResultsOnWarnings { get; set; }
public bool UsePackageRepositoryOptimizations { get; set; }
public bool PinVersion { get; set; }

//todo remove in 0.11.0
public bool ScriptsCheckLastExitCode { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void RegisterComponents(Container container)
{
new ChocolateyListCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyInfoCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyInstallCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyInstallCommand(container.GetInstance<IChocolateyPackageService>(), container.GetInstance<ChocolateyPinCommand>(), container.GetInstance<ILogger>()),
new ChocolateyPinCommand(container.GetInstance<IChocolateyPackageInformationService>(), container.GetInstance<ILogger>(), container.GetInstance<INugetService>()),
new ChocolateyOutdatedCommand(container.GetInstance<IChocolateyPackageService>()),
new ChocolateyUpgradeCommand(container.GetInstance<IChocolateyPackageService>()),
Expand Down