Skip to content

Commit

Permalink
(GH-878) Installation with .config file prints packages in file
Browse files Browse the repository at this point in the history
Previously when running choco install with a .config file as parameter the
output would say ''Installing the following packages:'' followed by the
path to the .config file. This change prints out that a .config file is
being used, as well as listing the packages set for installation.
  • Loading branch information
andmos authored and ferventcoder committed Aug 3, 2016
1 parent 00c7b88 commit 75375b1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Scenarios.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Chocolatey Usage Scenarios

### ChocolateyInstallCommand [ 35 Scenario(s), 291 Observation(s) ]
### ChocolateyInstallCommand [ 35 Scenario(s), 293 Observation(s) ]

#### when force installing a package that depends on an unavailable newer version of an installed dependency forcing dependencies

Expand Down Expand Up @@ -362,6 +362,8 @@
* should not have a successful package result for missing package
* should not have inconclusive package result
* should not have warning package result
* should print out package from config file in message
* should specify config file is being used in message

#### when noop installing a package

Expand Down
24 changes: 24 additions & 0 deletions src/chocolatey.tests.integration/scenarios/InstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,30 @@ public void should_not_have_warning_package_result()
packageResult.Value.Warning.ShouldBeFalse();
}
}

[Fact]
public void should_specify_config_file_is_being_used_in_message()
{
bool expectedMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null())
{
if (message.Contains("Installing from config file:")) expectedMessage = true;
}

expectedMessage.ShouldBeTrue();
}

[Fact]
public void should_print_out_package_from_config_file_in_message()
{
bool expectedMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null())
{
if (message.Contains("installpackage")) expectedMessage = true;
}

expectedMessage.ShouldBeTrue();
}
}

[Concern(typeof(ChocolateyInstallCommand))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private string capture_arguments(ChocolateyConfiguration config, PackageResult p

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config)
{
this.Log().Info(@"Installing the following packages:");
this.Log().Info(is_packages_config_file(config.PackageNames) ? @"Installing from config file:" : @"Installing the following packages:");
this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames));

var packageInstalls = new ConcurrentDictionary<string, PackageResult>();
Expand All @@ -446,6 +446,7 @@ public ConcurrentDictionary<string, PackageResult> 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)
Expand Down Expand Up @@ -524,13 +525,23 @@ private IEnumerable<ChocolateyConfiguration> set_config_from_package_names_and_p

foreach (var packageConfig in get_packages_from_config(packageConfigFile, config, packageInstalls).or_empty_list_if_null())
{
yield return packageConfig;
yield return packageConfig;
}
}

yield return config;
}

private bool contains_packages_config_file(string packageNames)
{
return packageNames.to_string().Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().Any(p => p.EndsWith(".config", StringComparison.OrdinalIgnoreCase));
}

private bool is_packages_config_file(string packageNames)
{
return packageNames.to_string().EndsWith(".config", StringComparison.OrdinalIgnoreCase) && !packageNames.to_string().contains(";");
}

private IEnumerable<ChocolateyConfiguration> get_packages_from_config(string packageConfigFile, ChocolateyConfiguration config, ConcurrentDictionary<string, PackageResult> packageInstalls)
{
IList<ChocolateyConfiguration> packageConfigs = new List<ChocolateyConfiguration>();
Expand All @@ -546,6 +557,7 @@ private IEnumerable<ChocolateyConfiguration> get_packages_from_config(string pac
}

var settings = _xmlService.deserialize<PackagesConfigFileSettings>(_fileSystem.get_full_path(packageConfigFile));
this.Log().Info(@"Installing the following packages:");
foreach (var pkgSettings in settings.Packages.or_empty_list_if_null())
{
if (!pkgSettings.Disabled)
Expand All @@ -560,6 +572,7 @@ private IEnumerable<ChocolateyConfiguration> get_packages_from_config(string pac
if (pkgSettings.AllowMultipleVersions) packageConfig.AllowMultipleVersions = true;
if (pkgSettings.IgnoreDependencies) packageConfig.IgnoreDependencies = true;

this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(packageConfig.PackageNames));
packageConfigs.Add(packageConfig);
}
}
Expand Down

0 comments on commit 75375b1

Please sign in to comment.