From 09966291e9dfaf647d419eaf0dd058c84a8c0179 Mon Sep 17 00:00:00 2001 From: Stephen Valdinger Date: Sat, 12 Nov 2022 14:07:58 -0500 Subject: [PATCH] (#2899) Move validation logic inside command check First we check that we are running the info command, then we do validation on whether no package ids or multiple package ids have been passed to the command. This allows the list command to function as normal, as it happily accepts 0 or multiple packages. --- .../commands/ChocolateyListCommand.cs | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index 426c2ee529..d4fcfce81d 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -147,19 +147,22 @@ public virtual void handle_additional_argument_parsing(IList unparsedArg public virtual void handle_validation(ChocolateyConfiguration configuration) { //Validate a package has been passed to info. - if(configuration.CommandName == "info" && string.IsNullOrWhiteSpace(configuration.Input)) + if(configuration.CommandName == "info") { - throw new ApplicationException(@"A single package id is required to run the info again."); - } + + if (string.IsNullOrWhiteSpace(configuration.Input)) + { + throw new ApplicationException(@"A single package id is required to run the info again."); + } - //Validate only a single package has been passed to info - //TODO: Provide ability to get info on a list of packages - string[] input = configuration.Input.Split(' '); - if (input.Count() > 1) - { - throw new ApplicationException(@"This command only accepts a single package id."); + //Validate only a single package has been passed to info + //TODO: Provide ability to get info on a list of packages + string[] input = configuration.Input.Split(' '); + if (input.Count() > 1) + { + throw new ApplicationException(@"This command only accepts a single package id."); + } } - if (!string.IsNullOrWhiteSpace(configuration.SourceCommand.Username) && string.IsNullOrWhiteSpace(configuration.SourceCommand.Password)) { @@ -289,13 +292,7 @@ public virtual void noop(ChocolateyConfiguration configuration) public virtual void run(ChocolateyConfiguration configuration) { - var logger = ChocolateyLoggers.LogFileOnly; var packageResults = _packageService.list_run(configuration).ToList(); - - if (configuration.RegularOutput) - { - logger = ChocolateyLoggers.Normal; - } log_deprecation_warning(configuration);