Skip to content

Commit

Permalink
(chocolatey#2899) Error on missing input for info command
Browse files Browse the repository at this point in the history
Previously when you ran the choco info command without passing a
package id chocolatey would report 0 packages found.

This commit validates the package count and throws an error if either
of the following conditions exist:

No package id was passed, or multiple package ids were passed.
  • Loading branch information
steviecoaster committed Nov 13, 2022
1 parent 0f13d7c commit dd47f5c
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

namespace chocolatey.infrastructure.app.commands
{
using System;
using System.Collections.Generic;
using System.Linq;
using attributes;
using commandline;
using configuration;
Expand Down Expand Up @@ -83,6 +85,24 @@ public override void handle_additional_argument_parsing(IList<string> unparsedAr
configuration.ListCommand.Exact = true;
}

public override void handle_validation(ChocolateyConfiguration configuration)
{
base.handle_validation(configuration);

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.");
}
}

public override void help_message(ChocolateyConfiguration configuration)
{
this.Log().Info(ChocolateyLoggers.Important, "Info Command");
Expand Down

0 comments on commit dd47f5c

Please # to comment.