From b669b9d5db497ea64d57fd99e43b902ed8341cfa Mon Sep 17 00:00:00 2001 From: Rain Sallow Date: Wed, 24 May 2023 13:58:53 -0400 Subject: [PATCH 1/2] (#158) Relegate the -lo warning to log-file-only After some discussion internally we determined that for folks to have smooth migration paths a log-file-only warning makes the most sense. --- .../infrastructure.app/commands/ChocolateyListCommand.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index 13d8051369..6a6d079d08 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -148,18 +148,18 @@ public virtual int Count(ChocolateyConfiguration config) public virtual void ParseAdditionalArguments(IList unparsedArguments, ChocolateyConfiguration configuration) { var argumentsWithoutLocalOnly = new List(unparsedArguments.Count); + const string unsupportedArgumentMessage = @" +Ignoring the argument {0}. This argument is unsupported for locally installed packages."; foreach (var argument in unparsedArguments) { if (_unsupportedArguments.Contains(argument, StringComparer.OrdinalIgnoreCase)) { - this.Log().Warn(ChocolateyLoggers.Important, @" -UNSUPPORTED ARGUMENT: Ignoring the argument {0}. This argument is unsupported for locally installed packages, and will be treated as a package name in Chocolatey CLI v3!", argument); + this.Log().Warn(ChocolateyLoggers.LogFileOnly, unsupportedArgumentMessage, argument); } else if (_unsupportedIncludeRegistryProgramsArguments.Contains(argument, StringComparer.OrdinalIgnoreCase)) { - this.Log().Warn(ChocolateyLoggers.Important, @" -UNSUPPORTED ARGUMENT: Ignoring the argument {0}. This argument is unsupported for locally installed packages, and will be treated as a package name in Chocolatey CLI v3!", argument); + this.Log().Warn(ChocolateyLoggers.LogFileOnly, unsupportedArgumentMessage, argument); configuration.ListCommand.IncludeRegistryPrograms = true; } else From 74aadeac12b42f8c89aabba87498ff800552ddf4 Mon Sep 17 00:00:00 2001 From: Rain Sallow Date: Wed, 24 May 2023 14:18:37 -0400 Subject: [PATCH 2/2] (#158) Update tests --- .../commands/ChocolateyListCommandSpecs.cs | 4 ++-- .../commands/choco-list.Tests.ps1 | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs index 9b48db4ced..08128c1244 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs @@ -147,7 +147,7 @@ public void Should_output_warning_message_about_unsupported_argument(string argu _because(); MockLogger.Messages.Keys.ShouldContain("Warn"); MockLogger.Messages["Warn"].ShouldContain(@" -UNSUPPORTED ARGUMENT: Ignoring the argument {0}. This argument is unsupported for locally installed packages, and will be treated as a package name in Chocolatey CLI v3!".FormatWith(argument)); +Ignoring the argument {0}. This argument is unsupported for locally installed packages.".FormatWith(argument)); } [NUnit.Framework.TestCase("-li")] @@ -157,7 +157,7 @@ public void Should_output_warning_message_about_unsupported_argument_and_set_inc _because(); MockLogger.Messages.Keys.ShouldContain("Warn"); MockLogger.Messages["Warn"].ShouldContain(@" -UNSUPPORTED ARGUMENT: Ignoring the argument {0}. This argument is unsupported for locally installed packages, and will be treated as a package name in Chocolatey CLI v3!".FormatWith(argument)); +Ignoring the argument {0}. This argument is unsupported for locally installed packages.".FormatWith(argument)); Configuration.ListCommand.IncludeRegistryPrograms.ShouldBeTrue(); } } diff --git a/tests/chocolatey-tests/commands/choco-list.Tests.ps1 b/tests/chocolatey-tests/commands/choco-list.Tests.ps1 index bc29af4518..b4a273a9e1 100644 --- a/tests/chocolatey-tests/commands/choco-list.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-list.Tests.ps1 @@ -99,17 +99,29 @@ Describe "choco list" -Tag Chocolatey, ListCommand { } } - Context "Listing local packages with unsupported argument outputs warning" -ForEach @('-l', '-lo', '--lo', '--local', '--localonly', '--local-only', '--order-by-popularity', '-a', '--all', '--allversions', '--all-versions', '-li', '-il', '-lai', '-lia', '-ali', '-ail', '-ial', '-ila') { + Context "Listing local packages with unsupported argument outputs warning to log file only" -ForEach @('-l', '-lo', '--lo', '--local', '--localonly', '--local-only', '--order-by-popularity', '-a', '--all', '--allversions', '--all-versions', '-li', '-il', '-lai', '-lia', '-ali', '-ail', '-ial', '-ila') { BeforeAll { + $LogPath = "$env:ChocolateyInstall\logs\chocolatey.log" + $OldLogContent = Get-Content $LogPath + Remove-Item -Path $LogPath + $Output = Invoke-Choco list $_ + $LogFile = Get-Content -Path $LogPath + + # Logs are picked up by CI for investigation if needed, so we'll keep both full sets of logs. + @( + $OldLogContent + $LogFile + ) | Set-Content -Path $LogPath } It "Exits with Success (0)" { $Output.ExitCode | Should -Be 0 } - It "Should contain expected warning message" { - $Output.Lines | Should -Contain "UNSUPPORTED ARGUMENT: Ignoring the argument $_. This argument is unsupported for locally installed packages, and will be treated as a package name in Chocolatey CLI v3!" + It "Should contain expected warning message in the logs" { + @($LogFile) -match "Ignoring the argument $_. This argument is unsupported for locally installed packages." | + Should -Not -BeNullOrEmpty } } }