Skip to content

Commit

Permalink
(GH-1237) Choco list/search results by id only
Browse files Browse the repository at this point in the history
Previously, list/search results would have id and other information,
typically at least the version as well. Sometimes it makes sense to just
see the id of the package. Allow for that to occur in different
scenarios.
  • Loading branch information
Tor Hovland authored and ferventcoder committed May 19, 2017
1 parent 52e7394 commit 1dfbc45
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 12 deletions.
13 changes: 12 additions & 1 deletion Scenarios.md
Expand Up @@ -400,7 +400,7 @@
* should not have inconclusive package result
* should not have warning package result

### ChocolateyListCommand [ 8 Scenario(s), 36 Observation(s) ]
### ChocolateyListCommand [ 10 Scenario(s), 41 Observation(s) ]

#### when listing local packages

Expand All @@ -417,6 +417,17 @@
* should not contain packages and versions with a space between them
* should only have messages related to package information

#### when listing local packages limiting output with id only

* should contain packages id
* should not contain any version number
* should not contain pipe

#### when listing local packages with id only

* should contain package name
* should not contain any version number

#### when listing packages with no sources enabled

* should have no sources enabled result
Expand Down
Expand Up @@ -41,7 +41,7 @@ $proNewOptions = " --file='' --build-package --file64='' --from-programs-and-fea
$proUninstallOptions = " --from-programs-and-features"

$commandOptions = @{
list = "--lo --pre --exact --by-id-only --id-starts-with --detailed --approved-only --not-broken --source='' --user= --password= --local-only --prerelease --include-programs --page= --page-size= --order-by-popularity --download-cache-only" + $allcommands
list = "--lo --id-only --pre --exact --by-id-only --id-starts-with --detailed --approved-only --not-broken --source='' --user= --password= --local-only --prerelease --include-programs --page= --page-size= --order-by-popularity --download-cache-only" + $allcommands
search = "--pre --exact --by-id-only --id-starts-with --detailed --approved-only --not-broken --source='' --user= --password= --local-only --prerelease --include-programs --page= --page-size= --order-by-popularity --download-cache-only" + $allcommands
info = "--pre --lo --source='' --user= --password= --local-only --prerelease" + $allcommands
install = "-y -whatif -? --pre --version= --params='' --install-arguments='' --override-arguments --ignore-dependencies --source='' --source='windowsfeatures' --source='webpi' --user= --password= --prerelease --forcex86 --not-silent --package-parameters='' --allow-downgrade --force-dependencies --require-checksums --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --allow-multiple-versions --ignore-checksums --allow-empty-checksums --allow-empty-checksums-secure --download-checksum='' --download-checksum-type='' --download-checksum-x64='' --download-checksum-type-x64='' --stop-on-first-package-failure" + $proInstallUpgradeOptions + $allcommands
Expand Down
1 change: 1 addition & 0 deletions src/chocolatey.tests.integration/Scenario.cs
Expand Up @@ -175,6 +175,7 @@ private static ChocolateyConfiguration baseline_configuration()
config.UpgradeCommand.FailOnNotInstalled = false;
config.PinCommand.Name = string.Empty;
config.PinCommand.Command = PinCommandType.unknown;
config.ListCommand.IdOnly = false;

return config;
}
Expand Down
68 changes: 68 additions & 0 deletions src/chocolatey.tests.integration/scenarios/ListScenarios.cs
Expand Up @@ -289,6 +289,36 @@ public void should_contain_debugging_messages()
}
}

[Concern(typeof(ChocolateyListCommand))]
public class when_listing_local_packages_with_id_only : ScenariosBase
{
public override void Context()
{
base.Context();
Configuration.ListCommand.LocalOnly = true;
Configuration.ListCommand.IdOnly = true;
Configuration.Sources = ApplicationParameters.PackagesLocation;
}

public override void Because()
{
MockLogger.reset();
Results = Service.list_run(Configuration).ToList();
}

[Fact]
public void should_contain_package_name()
{
MockLogger.contains_message("upgradepackage").ShouldBeTrue();
}

[Fact]
public void should_not_contain_any_version_number()
{
MockLogger.contains_message(".0").ShouldBeFalse();
}
}

[Concern(typeof(ChocolateyListCommand))]
public class when_listing_local_packages_limiting_output : ScenariosBase
{
Expand Down Expand Up @@ -342,6 +372,44 @@ public void should_not_contain_debugging_messages()
}
}

[Concern(typeof(ChocolateyListCommand))]
public class when_listing_local_packages_limiting_output_with_id_only : ScenariosBase
{
public override void Context()
{
base.Context();

Configuration.ListCommand.LocalOnly = true;
Configuration.ListCommand.IdOnly = true;
Configuration.Sources = ApplicationParameters.PackagesLocation;
Configuration.RegularOutput = false;
}

public override void Because()
{
MockLogger.reset();
Results = Service.list_run(Configuration).ToList();
}

[Fact]
public void should_contain_packages_id()
{
MockLogger.contains_message("upgradepackage").ShouldBeTrue();
}

[Fact]
public void should_not_contain_any_version_number()
{
MockLogger.contains_message(".0").ShouldBeFalse();
}

[Fact]
public void should_not_contain_pipe()
{
MockLogger.contains_message("|").ShouldBeFalse();
}
}

[Concern(typeof(ChocolateyListCommand))]
public class when_listing_packages_with_no_sources_enabled : ScenariosBase
{
Expand Down
Expand Up @@ -46,6 +46,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("l|lo|localonly|local-only",
"LocalOnly - Only search against local machine items.",
option => configuration.ListCommand.LocalOnly = option != null)
.Add("idonly|id-only",
"Id Only - Only return Package Ids in the list results.",
option => configuration.ListCommand.IdOnly = option != null)
.Add("pre|prerelease",
"Prerelease - Include Prereleases? Defaults to false.",
option => configuration.Prerelease = option != null)
Expand Down
Expand Up @@ -385,6 +385,7 @@ public ListCommandConfiguration()

// list
public bool LocalOnly { get; set; }
public bool IdOnly { get; set; }
public bool IncludeRegistryPrograms { get; set; }
public int? Page { get; set; }
public int PageSize { get; set; }
Expand Down
22 changes: 12 additions & 10 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Expand Up @@ -149,17 +149,19 @@ public virtual IEnumerable<PackageResult> list_run(ChocolateyConfiguration confi

if (!config.QuietOutput)
{
var logger = config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal;

if (config.RegularOutput)
{
this.Log().Info(config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal, () => "{0} {1}{2}{3}{4}".format_with(
package.Id,
package.Version.to_string(),
package.IsApproved ? " [Approved]" : string.Empty,
package.IsDownloadCacheAvailable ? " Downloads cached for licensed users" : string.Empty,
package.PackageTestResultStatus == "Failing" && package.IsDownloadCacheAvailable ? " - Possibly broken for FOSS users (due to original download location changes by vendor)" : package.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty
)
this.Log().Info(logger, () => "{0}{1}".format_with(package.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3}".format_with(
package.Version.to_string(),
package.IsApproved ? " [Approved]" : string.Empty,
package.IsDownloadCacheAvailable ? " Downloads cached for licensed users" : string.Empty,
package.PackageTestResultStatus == "Failing" && package.IsDownloadCacheAvailable ? " - Possibly broken for FOSS users (due to original download location changes by vendor)" : package.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty
))
);
if (config.Verbose) this.Log().Info(() =>

if (config.Verbose && !config.ListCommand.IdOnly) this.Log().Info(() =>
@" Title: {0} | Published: {1}{2}{3}
Number of Downloads: {4} | Downloads for this version: {5}
Package url
Expand Down Expand Up @@ -203,12 +205,12 @@ Package url
}
else
{
this.Log().Info(config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal, () => "{0}|{1}".format_with(package.Id, package.Version.to_string()));
this.Log().Info(logger, () => "{0}{1}".format_with(package.Id, config.ListCommand.IdOnly ? string.Empty : "|{0}".format_with(package.Version.to_string())));
}
}
else
{
this.Log().Debug(() => "{0} {1}".format_with(package.Id, package.Version.to_string()));
this.Log().Debug(() => "{0}{1}".format_with(package.Id, config.ListCommand.IdOnly ? string.Empty : " {0}".format_with(package.Version.to_string())));
}
count++;

Expand Down

0 comments on commit 1dfbc45

Please sign in to comment.