Skip to content

Commit 873033e

Browse files
committed
(chocolatey#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.
1 parent b7b4012 commit 873033e

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/chocolatey.tests/infrastructure.app/commands/ChocolateyExportCommandSpecs.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ public void should_add_include_remembered_arguments_to_the_option_set()
117117
{
118118
optionSet.Contains("include-remembered-arguments").ShouldBeTrue();
119119
}
120+
121+
[Fact]
122+
public void should_add_exclude_pins_to_the_option_set()
123+
{
124+
optionSet.Contains("exclude-pins").ShouldBeTrue();
125+
}
120126
}
121127

122128
public class when_handling_additional_argument_parsing : ChocolateyExportCommandSpecsBase

src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati
5858
.Add("include-arguments|include-remembered-arguments",
5959
"Include Remembered Arguments - controls whether or not remembered arguments for each package appear in generated file. Defaults to false.",
6060
option => configuration.ExportCommand.IncludeRememberedPackageArguments = option != null)
61+
.Add("exclude-pins",
62+
"Exclude Pins - controls whether or not pins are included. Only applies if remembered arguments are exported. Defaults to false.",
63+
option => configuration.ExportCommand.ExcludePins = option != null)
6164
;
6265
}
6366

@@ -104,6 +107,7 @@ choco export [<options/switches>]
104107
choco export
105108
choco export --include-version-numbers
106109
choco export --include-version-numbers --include-remembered-arguments
110+
choco export --include-remembered-arguments --exclude-pins
107111
choco export ""'c:\temp\packages.config'""
108112
choco export ""'c:\temp\packages.config'"" --include-version-numbers
109113
choco export -o=""'c:\temp\packages.config'""
@@ -141,7 +145,11 @@ public bool may_require_admin_access()
141145

142146
public void noop(ChocolateyConfiguration configuration)
143147
{
144-
this.Log().Info("Export would have been with options: {0} Output File Path={1}{0} Include Version Numbers:{2}{0} Include Remembered Arguments: {3}".format_with(Environment.NewLine, configuration.ExportCommand.OutputFilePath, configuration.ExportCommand.IncludeVersionNumbers, configuration.ExportCommand.IncludeRememberedPackageArguments));
148+
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}".format_with(
149+
Environment.NewLine, configuration.ExportCommand.OutputFilePath,
150+
configuration.ExportCommand.IncludeVersionNumbers,
151+
configuration.ExportCommand.IncludeRememberedPackageArguments,
152+
configuration.ExportCommand.ExcludePins));
145153
}
146154

147155
public void run(ChocolateyConfiguration configuration)
@@ -221,6 +229,11 @@ public void run(ChocolateyConfiguration configuration)
221229

222230
//Make sure to reset the configuration
223231
configuration = originalConfiguration.deep_copy();
232+
233+
if (!configuration.ExportCommand.ExcludePins && pkgInfo.IsPinned)
234+
{
235+
xw.WriteAttributeString("pinPackage", "true");
236+
}
224237
}
225238

226239
xw.WriteEndElement();

src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ public sealed class ExportCommandConfiguration
573573
{
574574
public bool IncludeVersionNumbers { get; set; }
575575
public bool IncludeRememberedPackageArguments { get; set; }
576+
public bool ExcludePins { get; set; }
576577

577578
public string OutputFilePath { get; set; }
578579
}

0 commit comments

Comments
 (0)