Skip to content

Commit 290ac65

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 eb3fe6b commit 290ac65

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
@@ -119,6 +119,12 @@ public void should_add_include_remembered_arguments_to_the_option_set()
119119
{
120120
optionSet.Contains("include-remembered-arguments").ShouldBeTrue();
121121
}
122+
123+
[Fact]
124+
public void should_add_exclude_pins_to_the_option_set()
125+
{
126+
optionSet.Contains("exclude-pins").ShouldBeTrue();
127+
}
122128
}
123129

124130
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
@@ -64,6 +64,9 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati
6464
.Add("include-arguments|include-remembered-arguments",
6565
"Include Remembered Arguments - controls whether or not remembered arguments for each package appear in generated file. Defaults to false. Available in 1.2.0+",
6666
option => configuration.ExportCommand.IncludeRememberedPackageArguments = option != null)
67+
.Add("exclude-pins",
68+
"Exclude Pins - controls whether or not pins are included. Only applies if remembered arguments are exported. Defaults to false.",
69+
option => configuration.ExportCommand.ExcludePins = option != null)
6770
;
6871
}
6972

@@ -110,6 +113,7 @@ choco export [<options/switches>]
110113
choco export
111114
choco export --include-version-numbers
112115
choco export --include-version-numbers --include-remembered-arguments
116+
choco export --include-remembered-arguments --exclude-pins
113117
choco export ""'c:\temp\packages.config'""
114118
choco export ""'c:\temp\packages.config'"" --include-version-numbers
115119
choco export -o=""'c:\temp\packages.config'""
@@ -147,7 +151,11 @@ public bool may_require_admin_access()
147151

148152
public void noop(ChocolateyConfiguration configuration)
149153
{
150-
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));
154+
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(
155+
Environment.NewLine, configuration.ExportCommand.OutputFilePath,
156+
configuration.ExportCommand.IncludeVersionNumbers,
157+
configuration.ExportCommand.IncludeRememberedPackageArguments,
158+
configuration.ExportCommand.ExcludePins));
151159
}
152160

153161
public void run(ChocolateyConfiguration configuration)
@@ -229,6 +237,11 @@ public void run(ChocolateyConfiguration configuration)
229237
// if (configuration.Features.FailOnStandardError) packageElement.FailOnStderr = true;
230238
// if (!configuration.Features.UsePowerShellHost) packageElement.UseSystemPowershell = true;
231239

240+
if (!configuration.ExportCommand.ExcludePins && pkgInfo.IsPinned)
241+
{
242+
xw.WriteAttributeString("pinPackage", "true");
243+
}
244+
232245
// Make sure to reset the configuration so as to be able to parse the next set of remembered arguments
233246
configuration.reset_config();
234247
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ public sealed class ExportCommandConfiguration
667667
{
668668
public bool IncludeVersionNumbers { get; set; }
669669
public bool IncludeRememberedPackageArguments { get; set; }
670+
public bool ExcludePins { get; set; }
670671

671672
public string OutputFilePath { get; set; }
672673
}

0 commit comments

Comments
 (0)