From 62b1e4a3603ca1b3ab42c71e9dd8ce9cc401e24f Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Sun, 6 Mar 2022 15:33:42 -0600 Subject: [PATCH] (#1310) List remembered arguments This adds the listing of remembered arguments to the list/info commands It only grabs the arguments when --local-only is specified, then decrypts and outputs them. Requires --verbose to be listed on the command line. --- .../scenarios/ListScenarios.cs | 4 ++++ .../infrastructure.app/services/NugetService.cs | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs index ab016df449..879c3fd77d 100644 --- a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs @@ -23,6 +23,7 @@ namespace chocolatey.tests.integration.scenarios using NuGet.Configuration; using FluentAssertions; using FluentAssertions.Execution; + using NUnit.Framework; public class ListScenarios { @@ -140,7 +141,10 @@ public void Should_contain_packages_and_versions_with_a_pipe_between_them() MockLogger.ContainsMessage("upgradepackage|1.0.0").Should().BeTrue(); } + // Windows only because decryption fallback on Mac/Linux logs a message [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] public void Should_only_have_messages_related_to_package_information() { MockLogger.Messages.Should() diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 21f5df285a..b4a2de799b 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -183,6 +183,7 @@ it is possible that incomplete package lists are returned from a command foreach (var pkg in NugetList.GetPackages(config, _nugetLogger, _fileSystem)) { var package = pkg; // for lamda access + string packageArgumentsUnencrypted = null; ChocolateyPackageMetadata packageLocalMetadata; string packageInstallLocation = null; @@ -207,6 +208,10 @@ it is possible that incomplete package lists are returned from a command } } + if (!string.IsNullOrWhiteSpace(packageInfo.Arguments)) + { + packageArgumentsUnencrypted = "\n Remembered Package Arguments: " + (packageInfo.Arguments.contains(" --") && packageInfo.Arguments.to_string().Length > 4 ? packageInfo.Arguments : NugetEncryptionUtility.DecryptString(packageInfo.Arguments)); + } } if (!config.QuietOutput) @@ -231,7 +236,7 @@ Package url{6} Tags: {9} Software Site: {10} Software License: {11}{12}{13}{14}{15}{16} - Description: {17}{18} + Description: {17}{18}{19} ".FormatWith( package.Title.EscapeCurlyBraces(), package.Published.GetValueOrDefault().UtcDateTime.ToShortDateString(), @@ -265,7 +270,8 @@ Package url{6} !string.IsNullOrWhiteSpace(package.BugTrackerUrl.ToStringSafe()) ? "{0} Issues: {1}".FormatWith(Environment.NewLine, package.BugTrackerUrl.ToStringSafe()) : string.Empty, package.Summary != null && !string.IsNullOrWhiteSpace(package.Summary.ToStringSafe()) ? "\r\n Summary: {0}".FormatWith(package.Summary.EscapeCurlyBraces().ToStringSafe()) : string.Empty, package.Description.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n "), - !string.IsNullOrWhiteSpace(package.ReleaseNotes.ToStringSafe()) ? "{0} Release Notes: {1}".FormatWith(Environment.NewLine, package.ReleaseNotes.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n ")) : string.Empty + !string.IsNullOrWhiteSpace(package.ReleaseNotes.ToStringSafe()) ? "{0} Release Notes: {1}".FormatWith(Environment.NewLine, package.ReleaseNotes.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n ")) : string.Empty, + packageArgumentsUnencrypted != null ? packageArgumentsUnencrypted : string.Empty ));