diff --git a/source/Models/CommandLineOptions/BuildOptions.cs b/source/Models/CommandLineOptions/BuildOptions.cs
index 9c51c14001210d03efc7940f5cf4eda43ea74926..5bf4b4685bfbd06283090f2dae33cfda679be1d4 100644
--- a/source/Models/CommandLineOptions/BuildOptions.cs
+++ b/source/Models/CommandLineOptions/BuildOptions.cs
@@ -5,7 +5,7 @@ namespace SuCoS.Models.CommandLineOptions;
///
/// Command line options for the build command.
///
-[Verb("build", HelpText = "Builds the site")]
+[Verb("build", true, HelpText = "Builds the site")]
public class BuildOptions : GenerateOptions
{
///
diff --git a/source/Models/CommandLineOptions/GenerateOptions.cs b/source/Models/CommandLineOptions/GenerateOptions.cs
index 704c3acb25e88d45209ae0de4f437fbaed47cb34..d7c22639b56df98a51ee52c5a072f663b7f69bd3 100644
--- a/source/Models/CommandLineOptions/GenerateOptions.cs
+++ b/source/Models/CommandLineOptions/GenerateOptions.cs
@@ -11,9 +11,16 @@ public class GenerateOptions : IGenerateOptions
[Option('v', "verbose", Required = false, HelpText = "How verbose it must be")]
public bool Verbose { get; init; }
+ ///
+ public string Source => string.IsNullOrEmpty(SourceOption) ? SourceArgument : SourceOption;
+
+ ///
+ [Value(0)]
+ public string SourceArgument { private get; init; } = "./";
+
///
[Option('s', "source", Required = false, HelpText = "Source directory path")]
- public required string Source { get; init; } = ".";
+ public string SourceOption { private get; init; } = string.Empty;
///
[Option('d', "draft", Required = false, HelpText = "Include draft content")]
diff --git a/source/Models/CommandLineOptions/IGenerateOptions.cs b/source/Models/CommandLineOptions/IGenerateOptions.cs
index 6aa93e0e7abc7440d6558b9eafc51a4b0137eae0..ddac589518751f129ae2f41662f42e3bad861edd 100644
--- a/source/Models/CommandLineOptions/IGenerateOptions.cs
+++ b/source/Models/CommandLineOptions/IGenerateOptions.cs
@@ -15,6 +15,16 @@ public interface IGenerateOptions
///
string Source { get; }
+ ///
+ /// The path of the source files
+ ///
+ string SourceArgument { init; }
+
+ ///
+ /// The path of the source files, as --source commandline option
+ ///
+ string SourceOption { init; }
+
///
/// Include draft content
///
diff --git a/source/Program.cs b/source/Program.cs
index 7464da1274231240dbe13d408f8e87df20d1fa2a..df5e474e96fed33c5932e22eae180c293850ddc4 100644
--- a/source/Program.cs
+++ b/source/Program.cs
@@ -28,14 +28,6 @@ public class Program(ILogger logger)
\/_____/\/___/ \/___/ \/___/ \/_____/
";
- private ILogger Logger { get; set; } = logger;
- private static readonly string[] aliases = ["--source", "-s"];
- private static readonly string[] aliasesArray = ["--draft", "-d"];
- private static readonly string[] aliasesArray0 = ["--future", "-f"];
- private static readonly string[] aliasesArray1 = ["--expired", "-e"];
- private static readonly string[] aliasesArray2 = ["--verbose", "-v"];
- private static readonly string[] aliasesArray3 = ["--output", "-o"];
-
///
/// Entry point of the program
///
@@ -57,7 +49,7 @@ public class Program(ILogger logger)
return await CommandLine.Parser.Default.ParseArguments(args)
.WithParsed(options =>
{
- Logger = CreateLogger(options.Verbose);
+ logger = CreateLogger(options.Verbose);
})
.WithParsed(options =>
{
@@ -68,11 +60,11 @@ public class Program(ILogger logger)
{
try
{
- _ = new BuildCommand(options, Logger);
+ _ = new BuildCommand(options, logger);
}
catch (Exception ex)
{
- Logger.Error($"Build failed: {ex.Message}");
+ logger.Error($"Build failed: {ex.Message}");
return Task.FromResult(1);
}
return Task.FromResult(0);
@@ -81,7 +73,7 @@ public class Program(ILogger logger)
{
try
{
- var serveCommand = new ServeCommand(options, Logger, new SourceFileWatcher());
+ var serveCommand = new ServeCommand(options, logger, new SourceFileWatcher());
serveCommand.StartServer();
await Task.Delay(-1).ConfigureAwait(false); // Wait forever.
}
@@ -89,11 +81,11 @@ public class Program(ILogger logger)
{
if (options.Verbose)
{
- Logger.Error(ex, "Serving failed");
+ logger.Error(ex, "Serving failed");
}
else
{
- Logger.Error($"Serving failed: {ex.Message}");
+ logger.Error($"Serving failed: {ex.Message}");
}
return 1;
}
@@ -108,14 +100,11 @@ public class Program(ILogger logger)
///
///
///
- public static ILogger CreateLogger(bool verbose = false)
- {
- return new LoggerConfiguration()
- .MinimumLevel.Is(verbose ? LogEventLevel.Debug : LogEventLevel.Information)
- // .WriteTo.Async(a => a.Console(formatProvider: System.Globalization.CultureInfo.CurrentCulture))
- .WriteTo.Console(formatProvider: System.Globalization.CultureInfo.CurrentCulture)
- .CreateLogger();
- }
+ public static ILogger CreateLogger(bool verbose = false) => new LoggerConfiguration()
+ .MinimumLevel.Is(verbose ? LogEventLevel.Debug : LogEventLevel.Information)
+ // .WriteTo.Async(a => a.Console(formatProvider: System.Globalization.CultureInfo.CurrentCulture))
+ .WriteTo.Console(formatProvider: System.Globalization.CultureInfo.CurrentCulture)
+ .CreateLogger();
///
/// Print the name and version of the program.
@@ -126,7 +115,7 @@ public class Program(ILogger logger)
var assemblyName = assembly?.GetName();
var appName = assemblyName?.Name;
var appVersion = assemblyName?.Version;
- Logger.Information("{name} v{version}", appName, appVersion);
+ logger.Information("{name} v{version}", appName, appVersion);
}
///
@@ -134,6 +123,6 @@ public class Program(ILogger logger)
///
public void OutputLogo()
{
- Logger.Information(helloWorld);
+ logger.Information(helloWorld);
}
}
diff --git a/test/BaseGeneratorCommandTests.cs b/test/BaseGeneratorCommandTests.cs
index e4f468189da6c08362d8f9fe54e5796d1834f767..ee68c57dc34292338b632e822c1e6aa63184a6e0 100644
--- a/test/BaseGeneratorCommandTests.cs
+++ b/test/BaseGeneratorCommandTests.cs
@@ -10,7 +10,7 @@ public class BaseGeneratorCommandTests
{
private static readonly IGenerateOptions testOptions = new GenerateOptions
{
- Source = "test_source"
+ SourceArgument = "test_source"
};
private static readonly ILogger testLogger = new LoggerConfiguration().CreateLogger();
diff --git a/test/Models/SiteTests.cs b/test/Models/SiteTests.cs
index e328aba3e28dd2036ec82b82603248f6de448ffb..123d3480c59a4b831a804045557ec41e7505c0a5 100644
--- a/test/Models/SiteTests.cs
+++ b/test/Models/SiteTests.cs
@@ -18,7 +18,7 @@ public class SiteTests : TestSetup
var siteFullPath = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST01));
site.Options = new GenerateOptions
{
- Source = siteFullPath
+ SourceArgument = siteFullPath
};
// Act
@@ -36,7 +36,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, sitePath))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, sitePath))
};
site.Options = options;
@@ -57,7 +57,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, sitePath))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, sitePath))
};
site.Options = options;
@@ -77,7 +77,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, sitePath))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, sitePath))
};
site.Options = options;
@@ -97,7 +97,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, sitePath))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, sitePath))
};
site.Options = options;
@@ -113,7 +113,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST03))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST03))
};
site.Options = options;
@@ -130,7 +130,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST01))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST01))
};
site.Options = options;
@@ -147,7 +147,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST04))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST04))
};
site.Options = options;
@@ -170,7 +170,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST04))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST04))
};
site.Options = options;
@@ -195,7 +195,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST04))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST04))
};
site.Options = options;
@@ -230,7 +230,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST05))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST05))
};
site.Options = options;
@@ -256,7 +256,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST07))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST07))
};
site.Options = options;
@@ -296,7 +296,7 @@ public class SiteTests : TestSetup
{
GenerateOptions options = new()
{
- Source = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST06))
+ SourceArgument = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST06))
};
site.Options = options;
diff --git a/test/ProgramTest.cs b/test/ProgramTest.cs
index 285f83ae825a8807ce8706c2ac792f1245e632a4..ae18ada644247451156d6338b73470a4c75af740 100644
--- a/test/ProgramTest.cs
+++ b/test/ProgramTest.cs
@@ -14,7 +14,7 @@ public class ProgramTests : TestSetup
{
// Act
var logger = Program.CreateLogger(verbose);
-
+
// Assert
Assert.True(logger.IsEnabled(expected));
}
diff --git a/test/ServerHandlers/RegisteredPageRequestHandlerTests.cs b/test/ServerHandlers/RegisteredPageRequestHandlerTests.cs
index 21fbf14145f87537890cf78bcb02dc7a17cc7512..e1b4fc83119d2561b8d36ed1b65938c19c644b01 100644
--- a/test/ServerHandlers/RegisteredPageRequestHandlerTests.cs
+++ b/test/ServerHandlers/RegisteredPageRequestHandlerTests.cs
@@ -16,7 +16,7 @@ public class RegisteredPageRequestHandlerTests : TestSetup
var siteFullPath = Path.GetFullPath(Path.Combine(testSitesPath, testSitePathCONST06));
site.Options = new GenerateOptions
{
- Source = siteFullPath
+ SourceArgument = siteFullPath
};
var registeredPageRequest = new RegisteredPageRequest(site);
@@ -36,7 +36,7 @@ public class RegisteredPageRequestHandlerTests : TestSetup
var siteFullPath = Path.GetFullPath(Path.Combine(testSitesPath, testSitePath));
site.Options = new GenerateOptions
{
- Source = siteFullPath
+ SourceArgument = siteFullPath
};
var registeredPageRequest = new RegisteredPageRequest(site);