Skip to content

Commit e378b21

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 1438bc6 commit e378b21

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ $commandOptions = @{
6868
download = "--internalize --internalize-all-urls --ignore-dependencies --installed-packages --ignore-unfound-packages --resources-location='' --download-location='' --outputdirectory='' --source='' --version='' --prerelease --user='' --password='' --cert='' --certpassword='' --append-use-original-location --recompile --disable-package-repository-optimizations -? --use-self-service" + $allcommands
6969
sync = "--output-directory='' --id='' --package-id='' -? --use-self-service" + $allcommands
7070
optimize = "--deflate-nupkg-only --id='' -? --use-self-service" + $allcommands
71-
export = "--include-version-numbers --output-file-path='' --include-remembered-arguments -?" + $allcommands
71+
export = "--include-version-numbers --output-file-path='' --include-remembered-arguments --exclude-pins -?" + $allcommands
7272
template = "--name=''" + $allcommands
7373
}
7474

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

+6
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ public void should_add_include_remembered_arguments_to_the_option_set()
120120
{
121121
optionSet.Contains("include-remembered-arguments").ShouldBeTrue();
122122
}
123+
124+
[Fact]
125+
public void should_add_exclude_pins_to_the_option_set()
126+
{
127+
optionSet.Contains("exclude-pins").ShouldBeTrue();
128+
}
123129
}
124130

125131
public class when_handling_additional_argument_parsing : ChocolateyExportCommandSpecsBase

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

+14-1
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

+1
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ public sealed class ExportCommandConfiguration
681681
{
682682
public bool IncludeVersionNumbers { get; set; }
683683
public bool IncludeRememberedPackageArguments { get; set; }
684+
public bool ExcludePins { get; set; }
684685

685686
public string OutputFilePath { get; set; }
686687
}

0 commit comments

Comments
 (0)