Skip to content

Commit

Permalink
Updated logging and application defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihnea Rădulescu committed Jun 25, 2024
1 parent 16a9ff1 commit 0ed5ef2
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<Copyright>Copyright © Mihnea Rădulescu 2023 - 2024</Copyright>
<AssemblyVersion>1.2024.05.04</AssemblyVersion>
<AssemblyVersion>1.2024.06.25</AssemblyVersion>
<Version>$(AssemblyVersion)</Version>
<DebugType>embedded</DebugType>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions ImageNormalizer.Test/ImageNormalizer.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
9 changes: 6 additions & 3 deletions ImageNormalizer/ApplicationRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ public void Run(
var arguments = _argumentsFactory.Create(
inputDirectory, outputDirectory, outputMaximumImageSize, outputImageQuality, maxDegreeOfParallelism);

var areValidArguments = _argumentsValidator.AreValidArguments(
arguments, out string? errorMessage);
var areValidArguments = _argumentsValidator.AreValidArguments(arguments, out string? errorMessage);

if (!areValidArguments)
{
_logger.Error(errorMessage!);

return;
}


_logger.Info(
$@"Normalizing images from input directory ""{arguments.InputPath}"" to output directory ""{arguments.OutputPath}"", resizing to output maximum image width/height {arguments.OutputMaximumImageSize}, at output image quality {arguments.OutputImageQuality}, using maximum degree of parallelism {arguments.MaxDegreeOfParallelism}.");
_logger.NewLine();

try
{
var imageDirectoryInfo = _imageDirectoryInfoFactory.Create(arguments);
Expand Down
2 changes: 1 addition & 1 deletion ImageNormalizer/FileSystemInfo/ImageDirectoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void NormalizeFileSystemInfo()
}

_logger.Info(
$@"Processing input directory ""{_arguments.InputPath}"" into output directory ""{_arguments.OutputPath}"", resizing to output maximum image width/height {_arguments.OutputMaximumImageSize}, at output image quality {_arguments.OutputImageQuality}, using maximum degree of parallelism {_arguments.MaxDegreeOfParallelism}.");
$@"Processing images from input directory ""{_arguments.InputPath}"" to output directory ""{_arguments.OutputPath}"".");

Parallel.ForEach(
_imageFileInfoCollection,
Expand Down
17 changes: 5 additions & 12 deletions ImageNormalizer/Logger/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@ namespace ImageNormalizer.Logger;

public class ConsoleLogger : ILogger
{
public void Info(string message)
{
Console.Out.WriteLine(message);
}
public void NewLine() => Console.Out.WriteLine();

public void Error(string message)
{
Console.Error.WriteLine($"Error: {message}");
}
public void Info(string message) => Console.Out.WriteLine(message);

public void Error(string message) => Console.Error.WriteLine($"Error: {message}");

public void Error(Exception ex)
{
Console.Error.WriteLine($"Error: {ex}");
}
public void Error(Exception ex) => Console.Error.WriteLine($"Error: {ex}");
}
2 changes: 2 additions & 0 deletions ImageNormalizer/Logger/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace ImageNormalizer.Logger;

public interface ILogger
{
void NewLine();

void Info(string message);

void Error(string message);
Expand Down
4 changes: 2 additions & 2 deletions ImageNormalizer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static void RegisterCommands(CoconaApp app)
[Argument(Description = "The input directory")]
string inputDirectory,
[Argument(Description = "The output directory")]
[Argument(Description = "The output directory, to be created, if it does not exist")]
string outputDirectory,
[Option("max-width-height", ['m'], Description = "The output maximum image width/height")]
Expand All @@ -59,7 +59,7 @@ private static void RegisterCommands(CoconaApp app)
[Option("max-degree-of-parallelism", ['p'], Description = "The maximum degree of parallel image processing, upper-bounded by processor count")]
[Range(1, 128)]
int maxDegreeOfParallelism = 16
int maxDegreeOfParallelism = 4
) =>
{
var applicationRunner = app.Services.GetService<IApplicationRunner>();
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ __Usage__: ImageNormalizer [--max-width-height] [--quality] [--max-degree-of-par

Arguments:
* 0: input-directory - The input directory (Required)
* 1: output-directory - The output directory (Required)
* 1: output-directory - The output directory, to be created, if it does not exist (Required)

Options:
* -m, --max-width-height - The output maximum image width/height (Default: 3840)
* -q, --quality - The output image quality (Default: 80)
* -p, --max-degree-of-parallelism - The maximum degree of parallel image processing, upper-bounded by processor count (Default: 16)
* -p, --max-degree-of-parallelism - The maximum degree of parallel image processing, upper-bounded by processor count (Default: 4)
* -h, --help - Show help message
* --version - Show version

0 comments on commit 0ed5ef2

Please sign in to comment.