Skip to content

Commit

Permalink
Merge pull request chocolatey#3166 from AdmiringWorm/count-nuget-service
Browse files Browse the repository at this point in the history
(chocolatey#3165) Update count method to support nuget service
  • Loading branch information
corbob authored May 24, 2023
2 parents 89c8c9c + 159ee69 commit 5204265
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public ChocolateyPackageService(

public virtual int Count(ChocolateyConfiguration config)
{
if (config.SourceType.IsEqualTo(SourceTypes.Normal))
{
return _nugetService.Count(config);
}

return PerformSourceRunnerFunction<ICountSourceRunner, int>(
config,
runner => runner.Count(config),
Expand All @@ -153,7 +158,7 @@ private void PerformSourceRunnerAction<TSourceRunner>(ChocolateyConfiguration co
private void PerformSourceRunnerAction<TSourceRunner>(ChocolateyConfiguration config, Action<TSourceRunner> action, IEnumerable<TSourceRunner> alternativeSourceRunners, bool throwOnException = false)
where TSourceRunner : class, IAlternativeSourceRunner
{
var runner = GetSourceRunner<TSourceRunner>(config.SourceType, alternativeSourceRunners);
var runner = GetSourceRunner(config.SourceType, alternativeSourceRunners);
if (runner != null && action != null)
{
if (runner is IBootstrappableSourceRunner bootstrapper)
Expand Down Expand Up @@ -186,7 +191,7 @@ private TResult PerformSourceRunnerFunction<TSourceRunner, TResult>(ChocolateyCo
private TResult PerformSourceRunnerFunction<TSourceRunner, TResult>(ChocolateyConfiguration config, Func<TSourceRunner, TResult> function, IEnumerable<TSourceRunner> alternativeSourceRunners, bool throwOnException = false)
where TSourceRunner : class, IAlternativeSourceRunner
{
var runner = GetSourceRunner<TSourceRunner>(config.SourceType, alternativeSourceRunners);
var runner = GetSourceRunner(config.SourceType, alternativeSourceRunners);
if (runner != null && function != null)
{
if (runner is IBootstrappableSourceRunner bootstrapper)
Expand All @@ -209,7 +214,7 @@ private TResult PerformSourceRunnerFunction<TSourceRunner, TResult>(ChocolateyCo
this.Log().Warn("No runner was found that implements source type '{0}' or, it does not support requested functionality.".FormatWith(config.SourceType));
}

return default(TResult);
return default;
}

public void ListDryRun(ChocolateyConfiguration config)
Expand Down Expand Up @@ -1795,15 +1800,6 @@ private void LogEnvironmentChanges(ChocolateyConfiguration config, IEnumerable<G
}
}

private TSourceRunner GetSourceRunner<TSourceRunner>(string sourceType)
where TSourceRunner : class, IAlternativeSourceRunner
{
// We add the trailing s to the check in case of windows feature which can be specified both with and without
// the s.
var sourceRunners = _containerResolver.ResolveAll<TSourceRunner>();
return GetSourceRunner(sourceType, sourceRunners);
}

private TSourceRunner GetSourceRunner<TSourceRunner>(string sourceType, IEnumerable<TSourceRunner> alternativeSourceRunners)
where TSourceRunner : class, IAlternativeSourceRunner
{
Expand Down

0 comments on commit 5204265

Please sign in to comment.