diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs index b6936d68b5..5603cb241b 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs @@ -233,7 +233,7 @@ public override void Because() [Fact] public void should_call_service_list_run() { - packageService.Verify(c => c.list_run(configuration, true), Times.Once); + packageService.Verify(c => c.list_run(configuration), Times.Once); } } } diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs index 95ae4330cd..e9248924b2 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs @@ -342,7 +342,7 @@ public override void Context() new PackageResult(package.Object, null), new PackageResult(pinnedPackage.Object, null) }; - nugetService.Setup(n => n.list_run(It.IsAny(), true)).Returns(packageResults); + nugetService.Setup(n => n.list_run(It.IsAny())).Returns(packageResults); configuration.PinCommand.Command = PinCommandType.list; } @@ -414,7 +414,7 @@ public void should_call_nuget_service_list_run_when_command_is_list() configuration.PinCommand.Command = PinCommandType.list; command.run(configuration); - nugetService.Verify(n => n.list_run(It.IsAny(), true), Times.Once); + nugetService.Verify(n => n.list_run(It.IsAny()), Times.Once); } [Pending("NuGet is killing me with extension methods. Need to find proper item to mock out to return the package object.")] diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index fc92e3d41a..70ce382e1c 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -16,17 +16,19 @@ namespace chocolatey.infrastructure.app.commands { using System.Collections.Generic; + using System.Linq; using attributes; using commandline; using configuration; using domain; using infrastructure.commands; using logging; + using results; using services; [CommandFor(CommandNameType.list)] [CommandFor(CommandNameType.search)] - public sealed class ChocolateyListCommand : ICommand + public sealed class ChocolateyListCommand : IListCommand { private readonly IChocolateyPackageService _packageService; @@ -66,12 +68,6 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati public void handle_additional_argument_parsing(IList unparsedArguments, ChocolateyConfiguration configuration) { configuration.Input = string.Join(" ", unparsedArguments); - - if (configuration.ListCommand.LocalOnly) - { - configuration.Sources = ApplicationParameters.PackagesLocation; - configuration.Prerelease = true; - } } public void handle_validation(ChocolateyConfiguration configuration) @@ -115,7 +111,15 @@ public void noop(ChocolateyConfiguration configuration) public void run(ChocolateyConfiguration configuration) { _packageService.ensure_source_app_installed(configuration); - _packageService.list_run(configuration, logResults: true); + // note: you must leave the .ToList() here or else the method won't be evaluated! + _packageService.list_run(configuration).ToList(); + } + + public IEnumerable list(ChocolateyConfiguration configuration) + { + configuration.QuietOutput = true; + // here it's up to the caller to enumerate the results + return _packageService.list_run(configuration); } public bool may_require_admin_access() diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs index 11ab93045f..e82b88e58c 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs @@ -139,7 +139,7 @@ public void run(ChocolateyConfiguration configuration) public void list_pins(IPackageManager packageManager, ChocolateyConfiguration config) { - foreach (var pkg in _nugetService.list_run(config, logResults: true)) + foreach (var pkg in _nugetService.list_run(config)) { var pkgInfo = _packageInfoService.get_package_information(pkg.Package); if (pkgInfo != null && pkgInfo.IsPinned) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyVersionCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyVersionCommand.cs index 02f285fccc..a3fd4de673 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyVersionCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyVersionCommand.cs @@ -115,7 +115,7 @@ public override void run(ChocolateyConfiguration configuration) { if (configuration.ListCommand.LocalOnly) { - _packageService.list_run(configuration,logResults:true); + _packageService.list_run(configuration); } else { diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 3720f48c74..8ecd74249d 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -153,7 +153,22 @@ private void append_output(StringBuilder propertyValues, string append) public bool Force { get; set; } public bool Noop { get; set; } public bool HelpRequested { get; set; } + + // TODO: Should look into using mutually exclusive output levels - Debug, Info (Regular), Error (Quiet) + // Verbose and Important are not part of the levels at all + /// + /// Gets or sets a value indicating whether output should be limited. + /// This supports the --limit-output parameter. + /// + /// true for regular output; false for limited output. public bool RegularOutput { get; set; } + /// + /// Gets or sets a value indicating whether console logging should be supressed. + /// This is for use by API calls which surface results in alternate forms. + /// + /// true for no output; false for regular or limited output. + /// This has only been implemented for NuGet List + public bool QuietOutput { get; set; } public bool PromptForConfirmation { get; set; } public bool AcceptLicense { get; set; } public bool AllowUnofficialBuild { get; set; } diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index ae5eb42019..de88e159bb 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -22,13 +22,14 @@ namespace chocolatey.infrastructure.app.services using commandline; using configuration; using domain; - using filesystem; using infrastructure.commands; using infrastructure.services; using logging; + using NuGet; using platforms; using results; using tolerance; + using IFileSystem = filesystem.IFileSystem; public class ChocolateyPackageService : IChocolateyPackageService { @@ -44,9 +45,9 @@ public class ChocolateyPackageService : IChocolateyPackageService private readonly IXmlService _xmlService; private readonly IConfigTransformService _configTransformService; - public ChocolateyPackageService(INugetService nugetService, IPowershellService powershellService, - IEnumerable sourceRunners, IShimGenerationService shimgenService, - IFileSystem fileSystem, IRegistryService registryService, + public ChocolateyPackageService(INugetService nugetService, IPowershellService powershellService, + IEnumerable sourceRunners, IShimGenerationService shimgenService, + IFileSystem fileSystem, IRegistryService registryService, IChocolateyPackageInformationService packageInfoService, IFilesService filesService, IAutomaticUninstallerService autoUninstallerService, IXmlService xmlService, IConfigTransformService configTransformService) @@ -99,55 +100,68 @@ public void list_noop(ChocolateyConfiguration config) perform_source_runner_action(config, r => r.list_noop(config)); } - public void list_run(ChocolateyConfiguration config, bool logResults) + public IEnumerable list_run(ChocolateyConfiguration config) { this.Log().Debug(() => "Searching for package information"); - var list = perform_source_runner_function(config, r => r.list_run(config, logResults)); + var packages = new List(); - if (config.SourceType == SourceType.normal) + foreach (var package in perform_source_runner_function(config, r => r.list_run(config))) { - if (config.RegularOutput) + if (config.SourceType == SourceType.normal) { - this.Log().Warn(() => @"{0} packages {1}.".format_with(list.Count(), config.ListCommand.LocalOnly ? "installed" : "found")); + if (!config.ListCommand.IncludeRegistryPrograms) + { + yield return package; + } - if (config.ListCommand.LocalOnly && config.ListCommand.IncludeRegistryPrograms) + if (config.ListCommand.LocalOnly && config.ListCommand.IncludeRegistryPrograms && package.Package != null) { - report_registry_programs(config, list); + packages.Add(package.Package); } } } - } - private void report_registry_programs(ChocolateyConfiguration config, IEnumerable list) - { - var itemsToRemoveFromMachine = new List(); - foreach (var packageResult in list) + if (config.RegularOutput) { - if (packageResult != null && packageResult.Package != null) + if (config.ListCommand.LocalOnly && config.ListCommand.IncludeRegistryPrograms) { - var pkginfo = _packageInfoService.get_package_information(packageResult.Package); - if (pkginfo.RegistrySnapshot == null) - { - continue; - } - var key = pkginfo.RegistrySnapshot.RegistryKeys.FirstOrDefault(); - if (key != null) + foreach (var installed in report_registry_programs(config, packages)) { - itemsToRemoveFromMachine.Add(key.DisplayName); + yield return installed; } } } - var machineInstalled = _registryService.get_installer_keys().RegistryKeys.Where((p) => p.is_in_programs_and_features() && !itemsToRemoveFromMachine.Contains(p.DisplayName)).OrderBy((p) => p.DisplayName).Distinct().ToList(); - if (machineInstalled.Count != 0) + } + + private IEnumerable report_registry_programs(ChocolateyConfiguration config, IEnumerable list) + { + var itemsToRemoveFromMachine = list.Select(package => _packageInfoService.get_package_information(package)). + Where(p => p.RegistrySnapshot != null). + Select(p => p.RegistrySnapshot.RegistryKeys.FirstOrDefault()). + Where(p => p != null). + Select(p => p.DisplayName).ToList(); + + var count = 0; + var machineInstalled = _registryService.get_installer_keys().RegistryKeys. + Where((p) => p.is_in_programs_and_features() && !itemsToRemoveFromMachine.Contains(p.DisplayName)). + OrderBy((p) => p.DisplayName).Distinct(); + this.Log().Info(() => ""); + foreach (var key in machineInstalled) { - this.Log().Info(() => ""); - foreach (var key in machineInstalled.or_empty_list_if_null()) + if (config.RegularOutput) { this.Log().Info("{0}|{1}".format_with(key.DisplayName, key.DisplayVersion)); if (config.Verbose) this.Log().Info(" InstallLocation: {0}{1} Uninstall:{2}".format_with(key.InstallLocation.escape_curly_braces(), Environment.NewLine, key.UninstallString.escape_curly_braces())); } - this.Log().Warn(() => @"{0} applications not managed with Chocolatey.".format_with(machineInstalled.Count)); + count++; + + yield return new PackageResult(key.DisplayName, key.DisplayName, key.InstallLocation); + } + + if (config.RegularOutput) + { + this.Log().Warn(() => @"{0} applications not managed with Chocolatey.".format_with(count)); } } @@ -227,8 +241,8 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu var powerShellRan = _powershellService.install(config, packageResult); if (powerShellRan) { - // we don't care about the exit code - if (config.Information.PlatformType == PlatformType.Windows) CommandExecutor.execute_static("shutdown", "/a", config.CommandExecutionTimeoutSeconds, _fileSystem.get_current_directory(), (s, e) => { }, (s, e) => { }, false, false); + // we don't care about the exit code + if (config.Information.PlatformType == PlatformType.Windows) CommandExecutor.execute_static("shutdown", "/a", config.CommandExecutionTimeoutSeconds, _fileSystem.get_current_directory(), (s, e) => { }, (s, e) => { }, false, false); } var difference = _registryService.get_differences(before, _registryService.get_installer_keys()); @@ -263,7 +277,7 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu { handle_extension_packages(config, packageResult); } - + _packageInfoService.save_package_information(pkgInfo); ensure_bad_package_path_is_clean(config, packageResult); @@ -277,7 +291,7 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu remove_rollback_if_exists(packageResult); - this.Log().Info(ChocolateyLoggers.Important, " The {0} of {1} was successful.".format_with( commandName.to_string(), packageResult.Name)); + this.Log().Info(ChocolateyLoggers.Important, " The {0} of {1} was successful.".format_with(commandName.to_string(), packageResult.Name)); } public ConcurrentDictionary install_run(ChocolateyConfiguration config) @@ -296,7 +310,7 @@ public ConcurrentDictionary install_run(ChocolateyConfigu action = (packageResult) => handle_package_result(packageResult, packageConfig, CommandNameType.install); } var results = perform_source_runner_function(packageConfig, r => r.install_run(packageConfig, action)); - + foreach (var result in results) { packageInstalls.GetOrAdd(result.Key, result.Value); @@ -312,7 +326,7 @@ public ConcurrentDictionary install_run(ChocolateyConfigu packageInstalls.Count, installFailures, installWarnings == 0 ? string.Empty : "{0} {1} package(s) had warnings.".format_with(Environment.NewLine, installWarnings), - _fileSystem.combine_paths(ApplicationParameters.LoggingLocation,ApplicationParameters.LoggingFile) + _fileSystem.combine_paths(ApplicationParameters.LoggingLocation, ApplicationParameters.LoggingFile) )); if (installWarnings != 0) @@ -367,7 +381,7 @@ Output is package name | current version | available version | pinned? config.RegularOutput = false; var oudatedPackages = _nugetService.upgrade_noop(config, null); config.RegularOutput = output; - + if (config.RegularOutput) { var upgradeWarnings = oudatedPackages.Count(p => p.Value.Warning); @@ -546,16 +560,16 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi this.Log().Info(@"Uninstalling the following packages:"); this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames)); - foreach (var packageConfigFile in config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().Where(p => p.EndsWith(".config")).ToList()) + if (config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().Any(p => p.EndsWith(".config"))) { throw new ApplicationException("A packages.config file is only used with installs."); } - + Action action = null; if (config.SourceType == SourceType.normal) { action = (packageResult) => handle_package_uninstall(packageResult, config); - } + } var packageUninstalls = perform_source_runner_function(config, r => r.uninstall_run(config, action)); @@ -600,11 +614,11 @@ public void handle_package_uninstall(PackageResult packageResult, ChocolateyConf _powershellService.uninstall(config, packageResult); } - if (packageResult.Success) - { + if (packageResult.Success) + { _autoUninstallerService.run(packageResult, config); - } - + } + // we don't care about the exit code if (config.Information.PlatformType == PlatformType.Windows) CommandExecutor.execute_static("shutdown", "/a", config.CommandExecutionTimeoutSeconds, _fileSystem.get_current_directory(), (s, e) => { }, (s, e) => { }, false, false); @@ -632,7 +646,7 @@ private void uninstall_cleanup(ChocolateyConfiguration config, PackageResult pac ensure_bad_package_path_is_clean(config, packageResult); remove_rollback_if_exists(packageResult); handle_extension_packages(config, packageResult); - + if (config.Force) { var packageDirectory = _fileSystem.combine_paths(packageResult.InstallLocation); @@ -741,14 +755,14 @@ private void move_bad_package_to_failure_location(PackageResult packageResult) { FaultTolerance.try_catch_with_logging_exception( () => _fileSystem.move_directory(packageResult.InstallLocation, packageResult.InstallLocation.Replace(ApplicationParameters.PackagesLocation, ApplicationParameters.PackageFailuresLocation)), - "Could not move bad package to failure directory It will show as installed.{0} {1}{0} The error".format_with(Environment.NewLine,packageResult.InstallLocation)); + "Could not move bad package to failure directory It will show as installed.{0} {1}{0} The error".format_with(Environment.NewLine, packageResult.InstallLocation)); } } private void rollback_previous_version(ChocolateyConfiguration config, PackageResult packageResult) { if (packageResult.InstallLocation == null) return; - + var rollbackDirectory = packageResult.InstallLocation.Replace(ApplicationParameters.PackagesLocation, ApplicationParameters.PackageBackupLocation); if (!_fileSystem.directory_exists(rollbackDirectory)) { @@ -784,4 +798,4 @@ private void remove_rollback_if_exists(PackageResult packageResult) _nugetService.remove_rollback_directory_if_exists(packageResult.Name); } } -} \ No newline at end of file +} diff --git a/src/chocolatey/infrastructure.app/services/CygwinService.cs b/src/chocolatey/infrastructure.app/services/CygwinService.cs index 3462c824c8..c94681202b 100644 --- a/src/chocolatey/infrastructure.app/services/CygwinService.cs +++ b/src/chocolatey/infrastructure.app/services/CygwinService.cs @@ -136,10 +136,11 @@ public void ensure_source_app_installed(ChocolateyConfiguration config, Action

p.Name.is_equal_to(CYGWIN_PACKAGE))) { @@ -184,7 +185,7 @@ public void list_noop(ChocolateyConfiguration config) this.Log().Warn(ChocolateyLoggers.Important, "{0} does not implement list".format_with(APP_NAME)); } - public IEnumerable list_run(ChocolateyConfiguration config, bool logResults) + public IEnumerable list_run(ChocolateyConfiguration config) { throw new NotImplementedException("{0} does not implement list".format_with(APP_NAME)); } diff --git a/src/chocolatey/infrastructure.app/services/IChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/IChocolateyPackageService.cs index 51d17671f7..eccfa5efb6 100644 --- a/src/chocolatey/infrastructure.app/services/IChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/IChocolateyPackageService.cs @@ -16,6 +16,7 @@ namespace chocolatey.infrastructure.app.services { using System.Collections.Concurrent; + using System.Collections.Generic; using configuration; using results; @@ -41,9 +42,8 @@ public interface IChocolateyPackageService /// Lists/searches for packages that meet a search criteria /// /// The configuration. - /// Should results be logged? /// - void list_run(ChocolateyConfiguration config, bool logResults); + IEnumerable list_run(ChocolateyConfiguration config); ///

/// Run pack in noop mode diff --git a/src/chocolatey/infrastructure.app/services/ISourceRunner.cs b/src/chocolatey/infrastructure.app/services/ISourceRunner.cs index 7c705fb74e..ac9826ddfd 100644 --- a/src/chocolatey/infrastructure.app/services/ISourceRunner.cs +++ b/src/chocolatey/infrastructure.app/services/ISourceRunner.cs @@ -49,9 +49,8 @@ public interface ISourceRunner /// Lists/searches for packages from the source feed /// /// The configuration. - /// Should results be logged? /// - IEnumerable list_run(ChocolateyConfiguration config, bool logResults); + IEnumerable list_run(ChocolateyConfiguration config); /// /// Run install in noop mode diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index e598cf8649..4711f1717d 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -84,34 +84,41 @@ public void list_noop(ChocolateyConfiguration config) )); } - public IEnumerable list_run(ChocolateyConfiguration config, bool logResults) + public IEnumerable list_run(ChocolateyConfiguration config) { + int count = 0; + + if (config.ListCommand.LocalOnly) + { + config.Sources = ApplicationParameters.PackagesLocation; + config.Prerelease = true; + } + if (config.RegularOutput) this.Log().Debug(() => "Running list with the following filter = '{0}'".format_with(config.Input)); if (config.RegularOutput) this.Log().Debug(() => "--- Start of List ---"); - foreach (var package in NugetList.GetPackages(config, _nugetLogger)) + foreach (var pkg in NugetList.GetPackages(config, _nugetLogger)) + { - var pkg = package; // for lamda access - if (logResults) + var package = pkg; // for lamda access + if (!config.QuietOutput) { - if (config.RegularOutput) - { - this.Log().Info(config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal, () => "{0} {1}".format_with(pkg.Id, pkg.Version.to_string())); - if (config.Verbose) this.Log().Info(() => " {0}{1} Description: {2}{1} Tags: {3}{1} Number of Downloads: {4}{1}".format_with(pkg.Title.escape_curly_braces(), Environment.NewLine, pkg.Description.escape_curly_braces(), pkg.Tags.escape_curly_braces(), pkg.DownloadCount <= 0 ? "n/a" : pkg.DownloadCount.to_string())); - // Maintainer(s):{3}{1} | pkg.Owners.join(", ") - null at the moment - } - else - { - this.Log().Info(config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal, () => "{0}|{1}".format_with(pkg.Id, pkg.Version.to_string())); - } + this.Log().Info(config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal, () => "{0} {1}".format_with(package.Id, package.Version.to_string())); + if (config.RegularOutput && config.Verbose) this.Log().Info(() => " {0}{1} Description: {2}{1} Tags: {3}{1} Number of Downloads: {4}{1}".format_with(package.Title.escape_curly_braces(), Environment.NewLine, package.Description.escape_curly_braces(), package.Tags.escape_curly_braces(), package.DownloadCount <= 0 ? "n/a" : package.DownloadCount.to_string())); } else { - this.Log().Debug(() => "{0} {1}".format_with(pkg.Id, pkg.Version.to_string())); + this.Log().Debug(() => "{0} {1}".format_with(package.Id, package.Version.to_string())); } + count++; - yield return new PackageResult(pkg, null); + yield return new PackageResult(package, null, config.Sources); } + if (config.RegularOutput) this.Log().Debug(() => "--- End of List ---"); + if (config.RegularOutput) + { + this.Log().Warn(() => @"{0} packages {1}.".format_with(count, config.ListCommand.LocalOnly ? "installed" : "found")); + } } public void pack_noop(ChocolateyConfiguration config) @@ -1037,8 +1044,12 @@ private void set_package_names_if_all_is_specified(ChocolateyConfiguration confi config.PackageNames = string.Empty; var input = config.Input; config.Input = string.Empty; + var quiet = config.QuietOutput; + config.QuietOutput = true; - config.PackageNames = list_run(config, logResults: false).Select(p => p.Name).@join(ApplicationParameters.PackageNamesSeparator); + config.PackageNames = list_run(config).Select(p => p.Name).@join(ApplicationParameters.PackageNamesSeparator); + + config.QuietOutput = quiet; config.Input = input; config.Noop = noop; config.Prerelease = pre; diff --git a/src/chocolatey/infrastructure.app/services/PythonService.cs b/src/chocolatey/infrastructure.app/services/PythonService.cs index bdf4d701c4..1441cb7640 100644 --- a/src/chocolatey/infrastructure.app/services/PythonService.cs +++ b/src/chocolatey/infrastructure.app/services/PythonService.cs @@ -174,10 +174,11 @@ public void ensure_source_app_installed(ChocolateyConfiguration config, Action

p.Name.is_equal_to(PYTHON_PACKAGE))) { @@ -270,7 +271,7 @@ public void list_noop(ChocolateyConfiguration config) this.Log().Info("Would have run '{0} {1}'".format_with(_exePath, args)); } - public IEnumerable list_run(ChocolateyConfiguration config, bool logResults) + public IEnumerable list_run(ChocolateyConfiguration config) { set_executable_path_if_not_set(); var args = build_args(config, _listArguments); @@ -285,7 +286,7 @@ public IEnumerable list_run(ChocolateyConfiguration config, bool { var logMessage = e.Data; if (string.IsNullOrWhiteSpace(logMessage)) return; - if (logResults) + if (!config.QuietOutput) { this.Log().Info(e.Data); } diff --git a/src/chocolatey/infrastructure.app/services/RubyGemsService.cs b/src/chocolatey/infrastructure.app/services/RubyGemsService.cs index 50565be910..5accde55a1 100644 --- a/src/chocolatey/infrastructure.app/services/RubyGemsService.cs +++ b/src/chocolatey/infrastructure.app/services/RubyGemsService.cs @@ -109,10 +109,11 @@ public void ensure_source_app_installed(ChocolateyConfiguration config, Action

p.Name.is_equal_to(RUBY_PACKAGE) || p.Name.is_equal_to(RUBY_PORTABLE_PACKAGE))) { @@ -131,7 +132,7 @@ public void list_noop(ChocolateyConfiguration config) this.Log().Info("Would have run '{0} {1}'".format_with(EXE_PATH, args)); } - public IEnumerable list_run(ChocolateyConfiguration config, bool logResults) + public IEnumerable list_run(ChocolateyConfiguration config) { var packageResults = new List(); var args = ExternalCommandArgsBuilder.build_arguments(config, _listArguments); @@ -144,7 +145,7 @@ public IEnumerable list_run(ChocolateyConfiguration config, bool { var logMessage = e.Data; if (string.IsNullOrWhiteSpace(logMessage)) return; - if (logResults) + if (!config.QuietOutput) { this.Log().Info(e.Data); } diff --git a/src/chocolatey/infrastructure.app/services/WebPiService.cs b/src/chocolatey/infrastructure.app/services/WebPiService.cs index 7e0d581925..ba28b59475 100644 --- a/src/chocolatey/infrastructure.app/services/WebPiService.cs +++ b/src/chocolatey/infrastructure.app/services/WebPiService.cs @@ -105,10 +105,11 @@ public void ensure_source_app_installed(ChocolateyConfiguration config, Action

p.Name.is_equal_to(WEB_PI_PACKAGE))) { @@ -127,7 +128,7 @@ public void list_noop(ChocolateyConfiguration config) this.Log().Info("Would have run '{0} {1}'".format_with(EXE_PATH, args)); } - public IEnumerable list_run(ChocolateyConfiguration config, bool logResults) + public IEnumerable list_run(ChocolateyConfiguration config) { var packageResults = new List(); var args = ExternalCommandArgsBuilder.build_arguments(config, _listArguments); @@ -145,7 +146,7 @@ public IEnumerable list_run(ChocolateyConfiguration config, bool { var logMessage = e.Data; if (string.IsNullOrWhiteSpace(logMessage)) return; - if (logResults) + if (!config.QuietOutput) { this.Log().Info(e.Data); } diff --git a/src/chocolatey/infrastructure.app/services/WindowsFeatureService.cs b/src/chocolatey/infrastructure.app/services/WindowsFeatureService.cs index 24d3109767..efee226712 100644 --- a/src/chocolatey/infrastructure.app/services/WindowsFeatureService.cs +++ b/src/chocolatey/infrastructure.app/services/WindowsFeatureService.cs @@ -180,7 +180,7 @@ public void list_noop(ChocolateyConfiguration config) this.Log().Info("Would have run '{0} {1}'".format_with(_exePath, args)); } - public IEnumerable list_run(ChocolateyConfiguration config, bool logResults) + public IEnumerable list_run(ChocolateyConfiguration config) { set_executable_path_if_not_set(); var args = build_args(config, _listArguments); @@ -195,7 +195,7 @@ public IEnumerable list_run(ChocolateyConfiguration config, bool { var logMessage = e.Data; if (string.IsNullOrWhiteSpace(logMessage)) return; - if (logResults) + if (!config.QuietOutput) { this.Log().Info(e.Data); } diff --git a/src/chocolatey/infrastructure/commands/IListCommand.cs b/src/chocolatey/infrastructure/commands/IListCommand.cs index d24a89ccb2..bb4817e4cb 100644 --- a/src/chocolatey/infrastructure/commands/IListCommand.cs +++ b/src/chocolatey/infrastructure/commands/IListCommand.cs @@ -1,25 +1,25 @@ -// Copyright © 2015 - Present RealDimensions Software, LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace chocolatey.infrastructure.commands -{ - using System.Collections.Generic; - using app.configuration; - - public interface IListCommand : ICommand - { - IEnumerable list(ChocolateyConfiguration config); - } -} +// Copyright © 2011 - Present RealDimensions Software, LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace chocolatey.infrastructure.commands +{ + using System.Collections.Generic; + using app.configuration; + + public interface IListCommand : ICommand + { + IEnumerable list(ChocolateyConfiguration config); + } +} \ No newline at end of file diff --git a/src/chocolatey/infrastructure/results/PackageResult.cs b/src/chocolatey/infrastructure/results/PackageResult.cs index 29aaed8f5d..aadd6322b7 100644 --- a/src/chocolatey/infrastructure/results/PackageResult.cs +++ b/src/chocolatey/infrastructure/results/PackageResult.cs @@ -15,7 +15,9 @@ namespace chocolatey.infrastructure.results { - using System.Linq; + using System; + using System.Collections.Generic; + using System.Linq; using NuGet; ///

@@ -37,17 +39,41 @@ public bool Warning public string Version { get; private set; } public IPackage Package { get; private set; } public string InstallLocation { get; set; } + public string Source { get; set; } + public string SourceUri { get; set; } - public PackageResult(IPackage package, string installLocation) : this(package.Id.to_lower(), package.Version.to_string(), installLocation) + public PackageResult(IPackage package, string installLocation, string source = null) : this(package.Id.to_lower(), package.Version.to_string(), installLocation) { Package = package; + Source = source; + var sources = new List(); + if (!string.IsNullOrEmpty(source)) + { + sources.AddRange(source.Split(new[] {";", ","}, StringSplitOptions.RemoveEmptyEntries).Select(s => new Uri(s))); + } + + var rp = Package as DataServicePackage; + if (rp != null) + { + SourceUri = rp.DownloadUrl.ToString(); + Source = sources.FirstOrDefault(uri => uri.IsBaseOf(rp.DownloadUrl)).to_string(); + if (string.IsNullOrEmpty(Source)) + { + Source = sources.FirstOrDefault(uri => uri.DnsSafeHost == rp.DownloadUrl.DnsSafeHost).to_string(); + } + } + else + { + Source = sources.FirstOrDefault(uri => uri.IsFile || uri.IsUnc).to_string(); + } } - public PackageResult(string name, string version, string installLocation) + public PackageResult(string name, string version, string installLocation, string source = null) { Name = name; Version = version; InstallLocation = installLocation; + Source = source; } } } \ No newline at end of file