Skip to content

Commit

Permalink
(#2603) Export pin status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheCakeIsNaOH committed Jun 27, 2022
1 parent 2c9f8db commit 5c65aa2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public void should_add_include_remembered_arguments_to_the_option_set()
{
optionSet.Contains("include-remembered-arguments").ShouldBeTrue();
}

[Fact]
public void should_add_exclude_pins_to_the_option_set()
{
optionSet.Contains("exclude-pins").ShouldBeTrue();
}
}

public class when_handling_additional_argument_parsing : ChocolateyExportCommandSpecsBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati
.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.",
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.",
option => configuration.ExportCommand.ExcludePins = option != null)
;
}

Expand Down Expand Up @@ -104,6 +107,7 @@ choco export [<options/switches>]
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'""
Expand Down Expand Up @@ -141,7 +145,11 @@ public bool may_require_admin_access()

public void noop(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}".format_with(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}".format_with(
Environment.NewLine, configuration.ExportCommand.OutputFilePath,
configuration.ExportCommand.IncludeVersionNumbers,
configuration.ExportCommand.IncludeRememberedPackageArguments,
configuration.ExportCommand.ExcludePins));
}

public void run(ChocolateyConfiguration configuration)
Expand Down Expand Up @@ -221,6 +229,11 @@ public void run(ChocolateyConfiguration configuration)
//Make sure to reset the configuration
configuration = originalConfiguration.deep_copy();
if (!configuration.ExportCommand.ExcludePins && pkgInfo.IsPinned)
{
xw.WriteAttributeString("pinPackage", "true");
}
}
xw.WriteEndElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,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; }
}
Expand Down

0 comments on commit 5c65aa2

Please sign in to comment.