Skip to content

Commit

Permalink
(chocolatey#2899) Move validation logic inside command check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
steviecoaster committed Nov 12, 2022
1 parent 0af866c commit 0996629
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,22 @@ public virtual void handle_additional_argument_parsing(IList<string> 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))
{
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0996629

Please # to comment.