Skip to content

Commit 6f4c4c4

Browse files
committed
implemented format handling for normal and raw
1 parent 8d7ea7a commit 6f4c4c4

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/LineCountData.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class LineCountData
1212

1313
public FilterType FilterType { get; } = (FilterType)(-1);
1414
public required bool ListFiles { get; init; }
15-
public required Format Format { get; init; }
1615

1716
public static readonly TimeSpan TimeOut = TimeSpan.FromMilliseconds(500);
1817

src/Logging/Logger.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using LineCount.Errors;
1+
using System.Globalization;
2+
using LineCount.Errors;
23

34
namespace LineCount.Logging;
45

@@ -34,20 +35,38 @@ public static void Log(string path, string value)
3435
Console.ForegroundColor = color;
3536
}
3637
}
38+
3739
public static void LogError<T>(T error) where T : IError
3840
{
39-
4041
Console.Error.WriteLine($"\x1b[0;31m{error}\x1b[0m");
4142
}
4243

43-
public static void LogReport(LineCountReport report)
44+
public static void LogReport(LineCountReport report, Format format)
45+
{
46+
switch(format)
47+
{
48+
case Format.Normal:
49+
LogNormalReport(report);
50+
break;
51+
case Format.Raw:
52+
LogRawReport(report);
53+
break;
54+
}
55+
}
56+
57+
static void LogNormalReport(LineCountReport report)
4458
{
45-
if(report.Files == 1)
59+
if (report.Files == 1)
4660
{
4761
Console.WriteLine($"{report.Lines} lines have been found.");
4862
return;
4963
}
5064

5165
Console.WriteLine($"{report.Lines} lines have been found across {report.Files} files.");
5266
}
67+
68+
static void LogRawReport(LineCountReport report)
69+
{
70+
Console.WriteLine(report.Lines);
71+
}
5372
}

src/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848

4949
LineCountData data = new LineCountData(filter, lineFilter, exceptFilter, exceptLineFilter)
5050
{
51-
ListFiles = listFiles,
52-
Format = format
51+
ListFiles = listFiles
5352
};
5453

5554
var result = await LineCount.LineCount.Run(path, data, excludeDirectories ?? [], excludeFiles ?? []);
@@ -60,7 +59,7 @@
6059
}
6160

6261
result.Match(
63-
report => Logger.LogReport(report),
62+
report => Logger.LogReport(report, format),
6463
error => Logger.LogError(error)
6564
);
6665
});

0 commit comments

Comments
 (0)