From d2f06e3e2cf0d968fe0a1773e89719ef1235a6e9 Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Thu, 24 Feb 2022 23:08:02 -0600 Subject: [PATCH] (#2603) Export pin status This adds the ability for the export command to include pins in the exported file. They will be exported if --include-arguments is specified, but can be excluded with --exclude-pins. --- .../helpers/ChocolateyTabExpansion.ps1 | 2 +- .../commands/ChocolateyExportCommandSpecs.cs | 6 ++++++ .../commands/ChocolateyExportCommand.cs | 16 +++++++++++++++- .../configuration/ChocolateyConfiguration.cs | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 index 888baa9e06..b1d0b149d6 100644 --- a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 +++ b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 @@ -56,7 +56,7 @@ $commandOptions = @{ config = "--name='' --value=''" feature = "--name=''" apikey = "--source='' --api-key='' --remove" - export = "--include-version-numbers --output-file-path='' --include-remembered-arguments" + export = "--include-version-numbers --output-file-path='' --include-remembered-arguments --exclude-pins" template = "--name=''" cache = "--expired" } diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyExportCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyExportCommandSpecs.cs index 4ad9881de7..73d49c0283 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyExportCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyExportCommandSpecs.cs @@ -120,6 +120,12 @@ public void Should_add_include_remembered_arguments_to_the_option_set() { _optionSet.Contains("include-remembered-arguments").Should().BeTrue(); } + + [Fact] + public void Should_add_exclude_pins_to_the_option_set() + { + _optionSet.Contains("exclude-pins").Should().BeTrue(); + } } public class When_handling_additional_argument_parsing : ChocolateyExportCommandSpecsBase diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs index 8005d471c3..4b4cb5b32f 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs @@ -64,6 +64,9 @@ public void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfiguration .Add("include-arguments|include-remembered-arguments", "Include Remembered Arguments - controls whether or not remembered arguments for each package appear in generated file. Defaults to false. Available in 2.3.0+", option => configuration.ExportCommand.IncludeRememberedPackageArguments = option != null) + .Add("exclude-pins", + "Exclude Pins - controls whether or not pins are included. Only applies if remembered arguments are exported. Defaults to false. Available in 2.4.0+", + option => configuration.ExportCommand.ExcludePins = option != null) ; } @@ -108,6 +111,7 @@ choco export [] choco export choco export --include-version-numbers choco export --include-version-numbers --include-remembered-arguments + choco export --include-remembered-arguments --exclude-pins choco export ""'c:\temp\packages.config'"" choco export ""'c:\temp\packages.config'"" --include-version-numbers choco export -o=""'c:\temp\packages.config'"" @@ -145,7 +149,12 @@ public bool MayRequireAdminAccess() public void DryRun(ChocolateyConfiguration configuration) { - this.Log().Info("Export would have been with options: {0} Output File Path={1}{0} Include Version Numbers:{2}{0} Include Remembered Arguments: {3}".FormatWith(Environment.NewLine, configuration.ExportCommand.OutputFilePath, configuration.ExportCommand.IncludeVersionNumbers, configuration.ExportCommand.IncludeRememberedPackageArguments)); + this.Log().Info("Export would have been with options: {0} Output File Path={1}{0} Include Version Numbers:{2}{0} Include Remembered Arguments: {3}{0} Exclude Pins: {4}".FormatWith( + Environment.NewLine, + configuration.ExportCommand.OutputFilePath, + configuration.ExportCommand.IncludeVersionNumbers, + configuration.ExportCommand.IncludeRememberedPackageArguments, + configuration.ExportCommand.ExcludePins)); } public void Run(ChocolateyConfiguration configuration) @@ -207,6 +216,11 @@ public void Run(ChocolateyConfiguration configuration) // if (configuration.Features.FailOnStandardError) packageElement.FailOnStderr = true; // if (!configuration.Features.UsePowerShellHost) packageElement.UseSystemPowershell = true; + if (!configuration.ExportCommand.ExcludePins && pkgInfo.IsPinned) + { + xw.WriteAttributeString("pinPackage", "true"); + } + // Make sure to reset the configuration so as to be able to parse the next set of remembered arguments configuration.RevertChanges(); } diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 39415dc39b..df0eec7a36 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -721,6 +721,7 @@ public sealed class ExportCommandConfiguration { public bool IncludeVersionNumbers { get; set; } public bool IncludeRememberedPackageArguments { get; set; } + public bool ExcludePins { get; set; } public string OutputFilePath { get; set; } }