General Work

This commit is ugly. but probably doesn't break anything
This commit is contained in:
Robert Morrison 2022-06-20 02:57:40 +01:00
parent 2c82979454
commit 0e7bd12c4f
Signed by: robert
GPG Key ID: 73E012EB3F4EC696

View File

@ -18,6 +18,9 @@
using Serilog; using Serilog;
using System.Reflection; using System.Reflection;
using System.Text.RegularExpressions;
using System.Diagnostics;
// using System.Text.Json;
namespace csSiteGen; namespace csSiteGen;
@ -29,6 +32,7 @@ class Program
// Get the current versiion number // Get the current versiion number
string? version = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion; string? version = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
// Configure logger
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug() .MinimumLevel.Debug()
.WriteTo.Console() .WriteTo.Console()
@ -46,6 +50,7 @@ class Program
Log.Error("Cannot get Version Information"); Log.Error("Cannot get Version Information");
} }
// Exit on argument errors
if (args.Length < 2) if (args.Length < 2)
{ {
Log.Error("Too Few Args: Expected at least 2 but received {Count}",args.Length); Log.Error("Too Few Args: Expected at least 2 but received {Count}",args.Length);
@ -57,10 +62,10 @@ class Program
{ {
Log.Warning("This program has only been tested on linux and cannot be assumed to work on other Operating Systems"); Log.Warning("This program has only been tested on linux and cannot be assumed to work on other Operating Systems");
} }
string _inputDirectory = args[0]; string _inputDirectory = args[0];
string _outputDirectory = args[1]; string _outputDirectory = args[1];
if (!Directory.Exists(_inputDirectory)) if (!Directory.Exists(_inputDirectory))
{ {
Log.Error("Input directory '{i}' Does not exist or is not a directory you have access to" , _inputDirectory); Log.Error("Input directory '{i}' Does not exist or is not a directory you have access to" , _inputDirectory);
@ -69,7 +74,6 @@ class Program
if (!Directory.Exists(_outputDirectory)) if (!Directory.Exists(_outputDirectory))
{ {
Log.Error("Output directory '{o}' Does not exist or is not a directory you have access to" , _outputDirectory); Log.Error("Output directory '{o}' Does not exist or is not a directory you have access to" , _outputDirectory);
Environment.Exit(1); Environment.Exit(1);
} }
@ -104,7 +108,6 @@ class Program
Log.Debug("Dirs Starting as: {DirStack}",dirs ); Log.Debug("Dirs Starting as: {DirStack}",dirs );
Stopwatch timer = new(); Stopwatch timer = new();
timer.Start(); timer.Start();
while (dirs.Count > 0) while (dirs.Count > 0)
{ {
var dir = dirs.Pop(); var dir = dirs.Pop();
@ -127,7 +130,6 @@ class Program
} }
timer.Stop(); timer.Stop();
Log.Information("Crawled {directory} in {time}ms with {number} results",directory,timer.ElapsedMilliseconds,res.Count()); Log.Information("Crawled {directory} in {time}ms with {number} results",directory,timer.ElapsedMilliseconds,res.Count());
return res; return res;
} }
@ -142,6 +144,8 @@ class Program
res = files.FindAll( x => expression.IsMatch(x)); // Here a lambda function is used as a predicate to do regex across the whole file list res = files.FindAll( x => expression.IsMatch(x)); // Here a lambda function is used as a predicate to do regex across the whole file list
return res; return res;
}
void Usage() void Usage()
{ {
/* /*
@ -152,6 +156,7 @@ class Program
*/ */
throw new NotImplementedException(); throw new NotImplementedException();
} }
static Tuple<bool,Dictionary<string,string>?> CheckDeps(List<string>? dependencies) static Tuple<bool,Dictionary<string,string>?> CheckDeps(List<string>? dependencies)
{ {
bool success = true; bool success = true;