Skip to content

Commit

Permalink
(GH-1147) Sync - Ensure machine parseable output
Browse files Browse the repository at this point in the history
Ensure that logging can be silenced so that the output is parseable
when calling `choco sync -r`
  • Loading branch information
ferventcoder committed Jan 21, 2017
1 parent 22d1171 commit b954825
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace chocolatey.infrastructure.app.services
using configuration;
using filesystem;
using infrastructure.commands;
using logging;
using platforms;

public class FileTypeDetectorService : IFileTypeDetectorService
Expand Down Expand Up @@ -91,7 +92,6 @@ public FileTypeDetectorService(IFileSystem fileSystem)
// }
//}


public string scan_file(string filePath)
{
if (Platform.get_platform() != PlatformType.Windows)
Expand Down Expand Up @@ -141,7 +141,7 @@ public string scan_file(string filePath)
},
(s, e) =>
{
this.Log().Warn("{0}".format_with(e.Data));
if (!string.IsNullOrWhiteSpace(e.Data)) this.Log().Warn("{0}".format_with(e.Data));
},
false,
false);
Expand Down
4 changes: 2 additions & 2 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void pack_run(ChocolateyConfiguration config)
string outputFile = builder.Id + "." + builder.Version + Constants.PackageExtension;
string outputPath = _fileSystem.combine_paths(config.OutputDirectory ?? _fileSystem.get_current_directory(), outputFile);

this.Log().Info(() => "Attempting to build package from '{0}'.".format_with(_fileSystem.get_file_name(nuspecFilePath)));
this.Log().Info(config.QuietOutput ? ChocolateyLoggers.LogFileOnly : ChocolateyLoggers.Normal, () => "Attempting to build package from '{0}'.".format_with(_fileSystem.get_file_name(nuspecFilePath)));

IPackage package = NugetPack.BuildPackage(builder, _fileSystem, outputPath);
// package.Validate().Any(v => v.Level == PackageIssueLevel.Error)
Expand All @@ -270,7 +270,7 @@ public void pack_run(ChocolateyConfiguration config)
// AnalyzePackage(package);
//}

this.Log().Info(ChocolateyLoggers.Important, () => "Successfully created package '{0}'".format_with(outputPath));
this.Log().Info(config.QuietOutput ? ChocolateyLoggers.LogFileOnly : ChocolateyLoggers.Important, () => "Successfully created package '{0}'".format_with(outputPath));
}

public void push_noop(ChocolateyConfiguration config)
Expand Down
10 changes: 6 additions & 4 deletions src/chocolatey/infrastructure.app/services/TemplateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ public void noop(ChocolateyConfiguration configuration)

public void generate(ChocolateyConfiguration configuration)
{
var logger = ChocolateyLoggers.Normal;
if (configuration.QuietOutput) logger = ChocolateyLoggers.LogFileOnly;

var packageLocation = _fileSystem.combine_paths(configuration.OutputDirectory ?? _fileSystem.get_current_directory(), configuration.NewCommand.Name);
if (_fileSystem.directory_exists(packageLocation) && !configuration.Force)
{
throw new ApplicationException(
"The location for the template already exists. You can:{0} 1. Remove '{1}'{0} 2. Use --force{0} 3. Specify a different name".format_with(Environment.NewLine, packageLocation));
}

if (configuration.RegularOutput) this.Log().Info(() => "Creating a new package specification at {0}".format_with(packageLocation));
if (configuration.RegularOutput) this.Log().Info(logger, () => "Creating a new package specification at {0}".format_with(packageLocation));
try
{
_fileSystem.delete_directory_if_exists(packageLocation, recursive: true);
Expand Down Expand Up @@ -109,7 +112,7 @@ public void generate(ChocolateyConfiguration configuration)
var templatePath = _fileSystem.combine_paths(ApplicationParameters.TemplatesLocation, configuration.NewCommand.TemplateName);
if (!_fileSystem.directory_exists(templatePath)) throw new ApplicationException("Unable to find path to requested template '{0}'. Path should be '{1}'".format_with(configuration.NewCommand.TemplateName, templatePath));

this.Log().Info(ChocolateyLoggers.Important, "Generating package from custom template at '{0}'.".format_with(templatePath));
this.Log().Info(configuration.QuietOutput ? logger : ChocolateyLoggers.Important, "Generating package from custom template at '{0}'.".format_with(templatePath));
foreach (var file in _fileSystem.get_files(templatePath, "*.*", SearchOption.AllDirectories))
{
var packageFileLocation = file.Replace(templatePath, packageLocation);
Expand All @@ -118,8 +121,7 @@ public void generate(ChocolateyConfiguration configuration)
}
}

this.Log().Info(
ChocolateyLoggers.Important,
this.Log().Info(configuration.QuietOutput ? logger : ChocolateyLoggers.Important,
"Successfully generated {0}{1} package specification files{2} at '{3}'".format_with(
configuration.NewCommand.Name, configuration.NewCommand.AutomaticPackage ? " (automatic)" : string.Empty, Environment.NewLine, packageLocation));
}
Expand Down

0 comments on commit b954825

Please sign in to comment.