Skip to content

Commit d2f06e3

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 db7ea32 commit d2f06e3

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ $commandOptions = @{
5656
config = "--name='' --value=''"
5757
feature = "--name=''"
5858
apikey = "--source='' --api-key='' --remove"
59-
export = "--include-version-numbers --output-file-path='' --include-remembered-arguments"
59+
export = "--include-version-numbers --output-file-path='' --include-remembered-arguments --exclude-pins"
6060
template = "--name=''"
6161
cache = "--expired"
6262
}

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").Should().BeTrue();
122122
}
123+
124+
[Fact]
125+
public void Should_add_exclude_pins_to_the_option_set()
126+
{
127+
_optionSet.Contains("exclude-pins").Should().BeTrue();
128+
}
123129
}
124130

125131
public class When_handling_additional_argument_parsing : ChocolateyExportCommandSpecsBase

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfiguration
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 2.3.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. Available in 2.4.0+",
69+
option => configuration.ExportCommand.ExcludePins = option != null)
6770
;
6871
}
6972

@@ -108,6 +111,7 @@ choco export [<options/switches>]
108111
choco export
109112
choco export --include-version-numbers
110113
choco export --include-version-numbers --include-remembered-arguments
114+
choco export --include-remembered-arguments --exclude-pins
111115
choco export ""'c:\temp\packages.config'""
112116
choco export ""'c:\temp\packages.config'"" --include-version-numbers
113117
choco export -o=""'c:\temp\packages.config'""
@@ -145,7 +149,12 @@ public bool MayRequireAdminAccess()
145149

146150
public void DryRun(ChocolateyConfiguration configuration)
147151
{
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}".FormatWith(Environment.NewLine, configuration.ExportCommand.OutputFilePath, configuration.ExportCommand.IncludeVersionNumbers, configuration.ExportCommand.IncludeRememberedPackageArguments));
152+
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(
153+
Environment.NewLine,
154+
configuration.ExportCommand.OutputFilePath,
155+
configuration.ExportCommand.IncludeVersionNumbers,
156+
configuration.ExportCommand.IncludeRememberedPackageArguments,
157+
configuration.ExportCommand.ExcludePins));
149158
}
150159

151160
public void Run(ChocolateyConfiguration configuration)
@@ -207,6 +216,11 @@ public void Run(ChocolateyConfiguration configuration)
207216
// if (configuration.Features.FailOnStandardError) packageElement.FailOnStderr = true;
208217
// if (!configuration.Features.UsePowerShellHost) packageElement.UseSystemPowershell = true;
209218

219+
if (!configuration.ExportCommand.ExcludePins && pkgInfo.IsPinned)
220+
{
221+
xw.WriteAttributeString("pinPackage", "true");
222+
}
223+
210224
// Make sure to reset the configuration so as to be able to parse the next set of remembered arguments
211225
configuration.RevertChanges();
212226
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ public sealed class ExportCommandConfiguration
721721
{
722722
public bool IncludeVersionNumbers { get; set; }
723723
public bool IncludeRememberedPackageArguments { get; set; }
724+
public bool ExcludePins { get; set; }
724725

725726
public string OutputFilePath { get; set; }
726727
}

0 commit comments

Comments
 (0)