passing -r will repeat parsing the set n times, -f will run a single file

This commit is contained in:
EliotJones 2025-07-26 17:30:43 -05:00
parent 52c0635273
commit 3131dae49e

View File

@ -30,6 +30,9 @@ namespace UglyToad.PdfPig.ConsoleRunner
public required string SuppliedDirectoryPath { get; init; }
}
private const string FileSymbol = "f";
private const string RepeatSymbol = "r";
private static IReadOnlyList<OptionalArg> GetSupportedArgs() =>
[
new OptionalArg
@ -49,6 +52,18 @@ namespace UglyToad.PdfPig.ConsoleRunner
SupportsValue = true,
ShortSymbol = "l",
Symbol = "limit"
},
new OptionalArg
{
SupportsValue = true,
ShortSymbol = "f",
Symbol = "file"
},
new OptionalArg
{
SupportsValue = true,
ShortSymbol = "r",
Symbol = "repeats"
}
];
@ -151,6 +166,8 @@ namespace UglyToad.PdfPig.ConsoleRunner
var noRecursionMode = parsed.SuppliedArgs.Any(x => x.ShortSymbol == "nr");
var outputOpt = parsed.SuppliedArgs.SingleOrDefault(x => x.ShortSymbol == "o" && x.Value != null);
var fileOpt = parsed.SuppliedArgs.SingleOrDefault(x => x.ShortSymbol == FileSymbol && x.Value != null);
var hasError = false;
var errorBuilder = new StringBuilder();
var fileList = Directory.GetFiles(
@ -160,6 +177,18 @@ namespace UglyToad.PdfPig.ConsoleRunner
.OrderBy(x => x).ToList();
var runningCount = 0;
if (fileOpt?.Value != null)
{
fileList = fileList.Where(x => x.EndsWith(fileOpt.Value, StringComparison.OrdinalIgnoreCase)).ToList();
}
var repeatOpt = parsed.SuppliedArgs.SingleOrDefault(x => x.ShortSymbol == RepeatSymbol);
var repeats = 1;
if (repeatOpt?.Value != null && int.TryParse(repeatOpt.Value, CultureInfo.InvariantCulture, out repeats))
{
}
Console.WriteLine($"Found {fileList.Count} files.");
Console.WriteLine();
@ -168,6 +197,8 @@ namespace UglyToad.PdfPig.ConsoleRunner
var dataList = new List<DataRecord>();
var sw = new Stopwatch();
for (int i = 0; i < repeats; i++)
{
foreach (var file in fileList)
{
if (maxCount.HasValue && runningCount >= maxCount)
@ -245,6 +276,7 @@ namespace UglyToad.PdfPig.ConsoleRunner
runningCount++;
}
}
if (hasError)
{