From a44e22ba6eb7e235b390e857f60bc16e1a8594b7 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 9 Apr 2024 14:35:37 -0500 Subject: [PATCH 1/5] chore: implement ISiteSettings --- source/Models/ISite.cs | 19 +++---------------- source/Models/ISiteSettings.cs | 32 ++++++++++++++++++++++++++++++++ source/Models/Site.cs | 20 +++++--------------- source/Models/SiteSettings.cs | 5 ++++- 4 files changed, 44 insertions(+), 32 deletions(-) create mode 100644 source/Models/ISiteSettings.cs diff --git a/source/Models/ISite.cs b/source/Models/ISite.cs index 5868b54..e1e97e6 100644 --- a/source/Models/ISite.cs +++ b/source/Models/ISite.cs @@ -9,27 +9,13 @@ namespace SuCoS.Models; /// /// The main configuration of the program, primarily extracted from the app.yaml file. /// -public interface ISite : IParams +public interface ISite : ISiteSettings, IParams { /// /// Command line options /// public IGenerateOptions Options { get; set; } - #region SiteSettings - - /// - /// Site Title. - /// - public string Title { get; } - - /// - /// The appearance of a URL is either ugly or pretty. - /// - public bool UglyURLs { get; } - - #endregion SiteSettings - /// /// The path of the content, based on the source path. /// @@ -48,7 +34,7 @@ public interface ISite : IParams /// /// The path of the static content (that will be copied as is), based on the theme path. /// - public string SourceThemeStaticPath => Path.Combine(SourceThemePath, "static"); + public string SourceThemeStaticPath { get; } /// /// List of all pages, including generated. @@ -84,6 +70,7 @@ public interface ISite : IParams /// The Fluid/Liquid template options. /// public TemplateOptions TemplateOptions { get; } + /// /// The logger instance. /// diff --git a/source/Models/ISiteSettings.cs b/source/Models/ISiteSettings.cs new file mode 100644 index 0000000..2bbda14 --- /dev/null +++ b/source/Models/ISiteSettings.cs @@ -0,0 +1,32 @@ +namespace SuCoS.Models; + +/// +/// The main configuration of the program, extracted from the app.yaml file. +/// +public interface ISiteSettings : IParams +{ + /// + /// Site Title/Name. + /// + public string Title { get; } + + /// + /// Site description + /// + public string? Description { get; } + + /// + /// Copyright information + /// + public string? Copyright { get; } + + /// + /// The base URL that will be used to build public links. + /// + public string BaseURL { get; } + + /// + /// The appearance of a URL is either ugly or pretty. + /// + public bool UglyURLs { get; } +} diff --git a/source/Models/Site.cs b/source/Models/Site.cs index 264efbc..70ac822 100644 --- a/source/Models/Site.cs +++ b/source/Models/Site.cs @@ -31,29 +31,19 @@ public class Site : ISite #region SiteSettings - /// - /// Site Title/Name - /// + /// public string Title => settings.Title; - /// - /// Site description - /// + /// public string? Description => settings.Description; - /// - /// Copyright information - /// + /// public string? Copyright => settings.Copyright; - /// - /// The base URL that will be used to build public links. - /// + /// public string BaseURL => settings.BaseURL; - /// - /// The appearance of a URL is either ugly or pretty. - /// + /// public bool UglyURLs => settings.UglyURLs; #endregion SiteSettings diff --git a/source/Models/SiteSettings.cs b/source/Models/SiteSettings.cs index 41b0b5f..796c046 100644 --- a/source/Models/SiteSettings.cs +++ b/source/Models/SiteSettings.cs @@ -6,8 +6,9 @@ namespace SuCoS.Models; /// The main configuration of the program, extracted from the app.yaml file. /// [YamlSerializable] -public class SiteSettings : IParams +public class SiteSettings : ISiteSettings { + #region ISiteSettings /// /// Site Title/Name. /// @@ -28,6 +29,8 @@ public class SiteSettings : IParams /// public string BaseURL { get; set; } = string.Empty; + #endregion ISiteSettings + /// /// The global site theme. /// -- GitLab From c8511ba6bf23fcd6db5eb80706b76c7bd575153e Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 9 Apr 2024 15:19:04 -0500 Subject: [PATCH 2/5] feat: Theme class --- source/BuildCommand.cs | 5 +- source/Helpers/SiteHelper.cs | 2 +- source/Models/ISite.cs | 5 -- source/Models/Site.cs | 13 ++-- source/Models/Theme.cs | 72 ++++++++++++++++++++++ source/Parser/IMetadataParser.cs | 6 +- source/Parser/YAMLParser.cs | 6 +- source/ServeCommand.cs | 2 +- source/ServerHandlers/StaticFileRequest.cs | 5 ++ test/Parser/YAMLParserTests.cs | 6 +- 10 files changed, 100 insertions(+), 22 deletions(-) create mode 100644 source/Models/Theme.cs diff --git a/source/BuildCommand.cs b/source/BuildCommand.cs index c4bda47..ae0f4d1 100644 --- a/source/BuildCommand.cs +++ b/source/BuildCommand.cs @@ -27,7 +27,10 @@ public class BuildCommand : BaseGeneratorCommand CreateOutputFiles(); // Copy theme static folder files into the root of the output folder - CopyFolder(site.SourceThemeStaticPath, options.Output); + if (site.Theme is not null) + { + CopyFolder(site.Theme.StaticFolder, options.Output); + } // Copy static folder files into the root of the output folder CopyFolder(site.SourceStaticPath, options.Output); diff --git a/source/Helpers/SiteHelper.cs b/source/Helpers/SiteHelper.cs index 858d05a..2dcf23e 100644 --- a/source/Helpers/SiteHelper.cs +++ b/source/Helpers/SiteHelper.cs @@ -108,7 +108,7 @@ public static class SiteHelper } var fileContent = File.ReadAllText(filePath); - var siteSettings = parser.ParseSiteSettings(fileContent) + var siteSettings = parser.Parse(fileContent) ?? throw new FormatException($"Error reading app config {configFile}"); return siteSettings; } diff --git a/source/Models/ISite.cs b/source/Models/ISite.cs index e1e97e6..0d5a7dd 100644 --- a/source/Models/ISite.cs +++ b/source/Models/ISite.cs @@ -31,11 +31,6 @@ public interface ISite : ISiteSettings, IParams /// public string SourceThemePath { get; } - /// - /// The path of the static content (that will be copied as is), based on the theme path. - /// - public string SourceThemeStaticPath { get; } - /// /// List of all pages, including generated. /// diff --git a/source/Models/Site.cs b/source/Models/Site.cs index 70ac822..6c90579 100644 --- a/source/Models/Site.cs +++ b/source/Models/Site.cs @@ -63,11 +63,6 @@ public class Site : ISite /// public string SourceThemePath => Path.Combine(Options.Source, settings.ThemeDir, settings.Theme ?? string.Empty); - /// - /// The path of the static content (that will be copied as is), based on the theme path. - /// - public string SourceThemeStaticPath => Path.Combine(SourceThemePath, "static"); - /// /// List of all basic source folders /// @@ -77,6 +72,11 @@ public class Site : ISite SourceThemePath ]; + /// + /// Theme used. + /// + public Theme? Theme { get; set; } + /// /// List of all pages, including generated. /// @@ -188,8 +188,11 @@ public class Site : ISite TemplateOptions.MemberAccessStrategy.Register(); TemplateOptions.MemberAccessStrategy.Register(); TemplateOptions.MemberAccessStrategy.Register(); + TemplateOptions.MemberAccessStrategy.Register(); this.clock = clock ?? new SystemClock(); + + Theme = Theme.CreateFromSite(this); } /// diff --git a/source/Models/Theme.cs b/source/Models/Theme.cs new file mode 100644 index 0000000..152b3b3 --- /dev/null +++ b/source/Models/Theme.cs @@ -0,0 +1,72 @@ +using SuCoS.Parser; +using YamlDotNet.Serialization; + +namespace SuCoS.Models; + +/// +/// Representation of the theme. +/// +[YamlSerializable] +public class Theme +{ + /// + /// Theme name + /// + public string Title { get; set; } = string.Empty; + + /// + /// Theme name + /// + public string Path { get; set; } = string.Empty; + + /// + /// The path of the static content (that will be copied as is) + /// + public string StaticFolder => System.IO.Path.Combine(Path, "static"); + + /// + /// folder that contains default layout files. + /// + public string DefaultLayoutFolder => System.IO.Path.Combine(Path, "_default"); + + /// + /// All default folders + /// + public IEnumerable Folders => [ + StaticFolder + ]; + + /// + /// Create a Theme from a given metadata content. + /// + /// + /// + /// + public static Theme Create(Site site, string data) + { + ArgumentNullException.ThrowIfNull(site); + + var theme = new YAMLParser().Parse(data); + theme.Path = site.SourceThemePath; + return theme; + } + + /// + /// Create a Theme from a given metadata file path. + /// + /// + /// + public static Theme? CreateFromSite(Site site) + { + ArgumentNullException.ThrowIfNull(site); + + var path = System.IO.Path.Combine(site.SourceThemePath, "config.yaml"); + + if (File.Exists(path)) + { + var data = File.ReadAllText(path); + return Create(site, data); + } + return null; + } +} diff --git a/source/Parser/IMetadataParser.cs b/source/Parser/IMetadataParser.cs index 57c0db7..84d2930 100644 --- a/source/Parser/IMetadataParser.cs +++ b/source/Parser/IMetadataParser.cs @@ -25,11 +25,11 @@ public interface IMetadataParser IFrontMatter? ParseFrontmatterAndMarkdown(in string fileFullPath, in string fileRelativePath, in string fileContent); /// - /// Parse the app config file. + /// Parse a string content to the T class. /// - /// + /// /// - SiteSettings ParseSiteSettings(string configFileContent); + T Parse(string content); /// /// Deserialized a object. diff --git a/source/Parser/YAMLParser.cs b/source/Parser/YAMLParser.cs index ac84d86..7c1fbd7 100644 --- a/source/Parser/YAMLParser.cs +++ b/source/Parser/YAMLParser.cs @@ -106,10 +106,10 @@ public class YAMLParser : IMetadataParser } /// - public SiteSettings ParseSiteSettings(string yaml) + public T Parse(string content) { - var settings = deserializer.Deserialize(yaml); - return settings; + var data = deserializer.Deserialize(content); + return data; } /// diff --git a/source/ServeCommand.cs b/source/ServeCommand.cs index 4dacbaf..0888784 100644 --- a/source/ServeCommand.cs +++ b/source/ServeCommand.cs @@ -89,7 +89,7 @@ public sealed class ServeCommand : BaseGeneratorCommand, IDisposable handlers = [ new PingRequests(), new StaticFileRequest(site.SourceStaticPath, false), - new StaticFileRequest(site.SourceThemeStaticPath, true), + new StaticFileRequest(site.Theme?.StaticFolder, true), new RegisteredPageRequest(site), new RegisteredPageResourceRequest(site) ]; diff --git a/source/ServerHandlers/StaticFileRequest.cs b/source/ServerHandlers/StaticFileRequest.cs index 1ca0203..eb148b5 100644 --- a/source/ServerHandlers/StaticFileRequest.cs +++ b/source/ServerHandlers/StaticFileRequest.cs @@ -26,6 +26,11 @@ public class StaticFileRequest : IServerHandlers { ArgumentNullException.ThrowIfNull(requestPath); + if (string.IsNullOrEmpty(basePath)) + { + return false; + } + var fileAbsolutePath = Path.Combine(basePath, requestPath.TrimStart('/')); return File.Exists(fileAbsolutePath); } diff --git a/test/Parser/YAMLParserTests.cs b/test/Parser/YAMLParserTests.cs index 8a4d577..dda4fa4 100644 --- a/test/Parser/YAMLParserTests.cs +++ b/test/Parser/YAMLParserTests.cs @@ -158,7 +158,7 @@ Title public void ParseSiteSettings_ShouldReturnSiteWithCorrectSettings() { // Act - var siteSettings = parser.ParseSiteSettings(siteContentCONST); + var siteSettings = parser.Parse(siteContentCONST); // Assert @@ -248,7 +248,7 @@ Title public void ParseSiteSettings_ShouldReturnSiteSettings() { // Arrange - var siteSettings = parser.ParseSiteSettings(siteContentCONST); + var siteSettings = parser.Parse(siteContentCONST); // Assert Assert.NotNull(siteSettings); @@ -277,7 +277,7 @@ Title public void SiteParams_ShouldPopulateParamsWithExtraFields() { // Arrange - var siteSettings = parser.ParseSiteSettings(siteContentCONST); + var siteSettings = parser.Parse(siteContentCONST); site = new Site(generateOptionsMock, siteSettings, frontMatterParser, loggerMock, systemClockMock); // Assert -- GitLab From 42db1fa47011cd23b6c7604f64eae44a9ec9d411 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 9 Apr 2024 15:29:14 -0500 Subject: [PATCH 3/5] chore: embed metadata parser into Site class --- source/BaseGeneratorCommand.cs | 4 ++-- source/Models/ISite.cs | 6 ++++++ source/Models/Site.cs | 12 +++++------- source/Models/Theme.cs | 2 +- source/NewSiteCommand.cs | 3 +-- source/ServeCommand.cs | 2 +- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/source/BaseGeneratorCommand.cs b/source/BaseGeneratorCommand.cs index 31710dd..254146c 100644 --- a/source/BaseGeneratorCommand.cs +++ b/source/BaseGeneratorCommand.cs @@ -26,7 +26,7 @@ public abstract class BaseGeneratorCommand /// /// The front matter parser instance. The default is YAML. /// - protected IMetadataParser frontMatterParser { get; } = new YAMLParser(); + protected IMetadataParser Parser { get; } = new YAMLParser(); /// /// The stopwatch reporter. @@ -52,7 +52,7 @@ public abstract class BaseGeneratorCommand logger.Information("Source path: {source}", propertyValue: options.Source); - site = SiteHelper.Init(configFile, options, frontMatterParser, WhereParamsFilter, logger, stopwatch); + site = SiteHelper.Init(configFile, options, Parser, WhereParamsFilter, logger, stopwatch); } /// diff --git a/source/Models/ISite.cs b/source/Models/ISite.cs index 0d5a7dd..fa40299 100644 --- a/source/Models/ISite.cs +++ b/source/Models/ISite.cs @@ -2,6 +2,7 @@ using Fluid; using Serilog; using SuCoS.Helpers; using SuCoS.Models.CommandLineOptions; +using SuCoS.Parser; using System.Collections.Concurrent; namespace SuCoS.Models; @@ -56,6 +57,11 @@ public interface ISite : ISiteSettings, IParams /// public SiteCacheManager CacheManager { get; } + /// + /// Metadata parser + /// + public IMetadataParser Parser { get; } + /// /// The Fluid parser instance. /// diff --git a/source/Models/Site.cs b/source/Models/Site.cs index 6c90579..53128c2 100644 --- a/source/Models/Site.cs +++ b/source/Models/Site.cs @@ -142,6 +142,9 @@ public class Site : ISite /// public int FilesParsedToReport => filesParsedToReport; + /// + public IMetadataParser Parser { get; init; } = new YAMLParser(); + private int filesParsedToReport; private const string indexLeafFileConst = "index.md"; @@ -153,11 +156,6 @@ public class Site : ISite /// private readonly object syncLockPostProcess = new(); - /// - /// The front matter parser instance. The default is YAML. - /// - private readonly IMetadataParser frontMatterParser; - private IEnumerable? pagesCache; private IEnumerable? regularPagesCache; @@ -181,7 +179,7 @@ public class Site : ISite Options = options; this.settings = settings; Logger = logger; - this.frontMatterParser = frontMatterParser; + Parser = frontMatterParser; // Liquid template options, needed to theme the content // but also parse URLs @@ -350,7 +348,7 @@ public class Site : ISite Page? page = null; try { - var frontMatter = frontMatterParser.ParseFrontmatterAndMarkdownFromFile(filePath, SourceContentPath) + var frontMatter = Parser.ParseFrontmatterAndMarkdownFromFile(filePath, SourceContentPath) ?? throw new FormatException($"Error parsing front matter for {filePath}"); if (IsValidPage(frontMatter, Options)) diff --git a/source/Models/Theme.cs b/source/Models/Theme.cs index 152b3b3..2e1b1a9 100644 --- a/source/Models/Theme.cs +++ b/source/Models/Theme.cs @@ -46,7 +46,7 @@ public class Theme { ArgumentNullException.ThrowIfNull(site); - var theme = new YAMLParser().Parse(data); + var theme = site.Parser.Parse(data); theme.Path = site.SourceThemePath; return theme; } diff --git a/source/NewSiteCommand.cs b/source/NewSiteCommand.cs index b46b991..d4ef862 100644 --- a/source/NewSiteCommand.cs +++ b/source/NewSiteCommand.cs @@ -41,8 +41,7 @@ public sealed partial class NewSiteCommand(NewSiteOptions options, ILogger logge try { - var parser = new YAMLParser(); - parser.Export(siteSettings, siteSettingsPath); + site.Parser.Export(siteSettings, siteSettingsPath); } catch (Exception ex) { diff --git a/source/ServeCommand.cs b/source/ServeCommand.cs index 0888784..6d77574 100644 --- a/source/ServeCommand.cs +++ b/source/ServeCommand.cs @@ -161,7 +161,7 @@ public sealed class ServeCommand : BaseGeneratorCommand, IDisposable } // Reinitialize the site - site = SiteHelper.Init(configFile, options, frontMatterParser, WhereParamsFilter, logger, stopwatch); + site = SiteHelper.Init(configFile, options, Parser, WhereParamsFilter, logger, stopwatch); StartServer(baseURLDefault, portDefault); }).ConfigureAwait(false); -- GitLab From 1eb04555e4532dbd980de31b22574ce2fbf981a7 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 9 Apr 2024 18:23:04 -0500 Subject: [PATCH 4/5] feat: new theme command --- .../Models/CommandLineOptions/NewOptions.cs | 11 +++ .../CommandLineOptions/NewSiteOptions.cs | 2 +- .../CommandLineOptions/NewThemeOptions.cs | 28 ++++++++ source/Models/Theme.cs | 7 +- source/NewSiteCommand.cs | 1 - source/NewThemeCommand.cs | 68 +++++++++++++++++++ source/Program.cs | 9 ++- 7 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 source/Models/CommandLineOptions/NewOptions.cs create mode 100644 source/Models/CommandLineOptions/NewThemeOptions.cs create mode 100644 source/NewThemeCommand.cs diff --git a/source/Models/CommandLineOptions/NewOptions.cs b/source/Models/CommandLineOptions/NewOptions.cs new file mode 100644 index 0000000..71d5be2 --- /dev/null +++ b/source/Models/CommandLineOptions/NewOptions.cs @@ -0,0 +1,11 @@ +using CommandLine; + +namespace SuCoS.Models.CommandLineOptions; + +/// +/// Command line options to generate a simple site from scratch. +/// +[Verb("new", false, HelpText = "Generate a simple theme from scratch")] +public class NewOptions +{ +} diff --git a/source/Models/CommandLineOptions/NewSiteOptions.cs b/source/Models/CommandLineOptions/NewSiteOptions.cs index c9fb348..f0dc375 100644 --- a/source/Models/CommandLineOptions/NewSiteOptions.cs +++ b/source/Models/CommandLineOptions/NewSiteOptions.cs @@ -5,7 +5,7 @@ namespace SuCoS.Models.CommandLineOptions; /// /// Command line options to generate a simple site from scratch. /// -[Verb("newsite", false, HelpText = "Generate a simple site from scratch")] +[Verb("new-site", false, HelpText = "Generate a simple site from scratch")] public class NewSiteOptions { /// diff --git a/source/Models/CommandLineOptions/NewThemeOptions.cs b/source/Models/CommandLineOptions/NewThemeOptions.cs new file mode 100644 index 0000000..f512afe --- /dev/null +++ b/source/Models/CommandLineOptions/NewThemeOptions.cs @@ -0,0 +1,28 @@ +using CommandLine; + +namespace SuCoS.Models.CommandLineOptions; + +/// +/// Command line options to generate a simple site from scratch. +/// +[Verb("new-theme", false, HelpText = "Generate a simple theme from scratch")] +public class NewThemeOptions +{ + /// + /// The path of the output files. + /// + [Option('o', "output", Required = false, HelpText = "Output directory path")] + public required string Output { get; init; } + + /// + /// Force theme creation. + /// + [Option('f', "force", Required = false, HelpText = "Force theme creation")] + public bool Force { get; init; } + + /// + /// Theme title. + /// + [Option("title", Required = false, HelpText = "Theme title")] + public required string Title { get; init; } = "My Theme"; +} diff --git a/source/Models/Theme.cs b/source/Models/Theme.cs index 2e1b1a9..21ab95b 100644 --- a/source/Models/Theme.cs +++ b/source/Models/Theme.cs @@ -1,4 +1,3 @@ -using SuCoS.Parser; using YamlDotNet.Serialization; namespace SuCoS.Models; @@ -17,21 +16,25 @@ public class Theme /// /// Theme name /// + [YamlIgnore] public string Path { get; set; } = string.Empty; /// /// The path of the static content (that will be copied as is) /// + [YamlIgnore] public string StaticFolder => System.IO.Path.Combine(Path, "static"); /// /// folder that contains default layout files. /// + [YamlIgnore] public string DefaultLayoutFolder => System.IO.Path.Combine(Path, "_default"); /// /// All default folders /// + [YamlIgnore] public IEnumerable Folders => [ StaticFolder ]; @@ -60,7 +63,7 @@ public class Theme { ArgumentNullException.ThrowIfNull(site); - var path = System.IO.Path.Combine(site.SourceThemePath, "config.yaml"); + var path = System.IO.Path.Combine(site.SourceThemePath, "sucos.yaml"); if (File.Exists(path)) { diff --git a/source/NewSiteCommand.cs b/source/NewSiteCommand.cs index d4ef862..e201071 100644 --- a/source/NewSiteCommand.cs +++ b/source/NewSiteCommand.cs @@ -1,7 +1,6 @@ using Serilog; using SuCoS.Models; using SuCoS.Models.CommandLineOptions; -using SuCoS.Parser; namespace SuCoS; diff --git a/source/NewThemeCommand.cs b/source/NewThemeCommand.cs new file mode 100644 index 0000000..d9fa17f --- /dev/null +++ b/source/NewThemeCommand.cs @@ -0,0 +1,68 @@ +using Serilog; +using SuCoS.Models; +using SuCoS.Models.CommandLineOptions; +using SuCoS.Parser; +using System.Reflection; + +namespace SuCoS; + +/// +/// Check links of a given site. +/// +public sealed partial class NewThemeCommand(NewThemeOptions options, ILogger logger) +{ + /// + /// Run the app + /// + /// + public int Run() + { + var theme = new Theme() + { + Title = options.Title, + Path = options.Output + }; + var outputPath = Path.GetFullPath(options.Output); + var themePath = Path.Combine(outputPath, "sucos.yaml"); + + if (File.Exists(themePath) && !options.Force) + { + logger.Error("{directoryPath} already exists", outputPath); + return 1; + } + + logger.Information("Creating a new site: {title} at {outputPath}", theme.Title, outputPath); + + CreateFolders(theme.Folders); + + foreach (var themeFolder in theme.Folders) + + try + { + new YAMLParser().Export(theme, themePath); + } + catch (Exception ex) + { + logger.Error("Failed to export site settings: {ex}", ex); + return 1; + } + + logger.Information("Done"); + return 0; + } + + /// + /// Create the standard folders + /// + /// + private void CreateFolders(IEnumerable folders) + { + foreach (var folder in folders) + { + logger.Information("Creating {folder}", folder); + Directory.CreateDirectory(folder); + } + } + + +} \ No newline at end of file diff --git a/source/Program.cs b/source/Program.cs index be6664d..53c15ff 100644 --- a/source/Program.cs +++ b/source/Program.cs @@ -44,11 +44,13 @@ public class Program(ILogger logger) [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(BuildOptions))] [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ServeOptions))] [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CheckLinkOptions))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(NewSiteOptions))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(NewThemeOptions))] public async Task RunCommandLine(string[] args) { OutputLogo(); OutputWelcome(); - return await CommandLine.Parser.Default.ParseArguments(args) + return await CommandLine.Parser.Default.ParseArguments(args) .WithParsed(options => { logger = CreateLogger(options.Verbose); @@ -103,6 +105,11 @@ public class Program(ILogger logger) { var command = new NewSiteCommand(options, logger); return Task.FromResult(command.Run()); + }, + (NewThemeOptions options) => + { + var command = new NewThemeCommand(options, logger); + return Task.FromResult(command.Run()); }, errs => Task.FromResult(0) ); -- GitLab From 516933f3dd8d148d30c32fb295e138f8539e25fe Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 9 Apr 2024 18:52:11 -0500 Subject: [PATCH 5/5] fix: removing unused using --- .editorconfig | 2 ++ source/NewThemeCommand.cs | 1 - source/ServerHandlers/StaticFileRequest.cs | 6 +++--- source/SuCoS.csproj | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.editorconfig b/.editorconfig index ca0a0b9..a02ffc7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -50,6 +50,8 @@ csharp_new_line_before_members_in_anonymous_types = true:error csharp_new_line_within_query_expression_clauses = true:error csharp_space_after_keywords_in_control_flow_statements = true +trim_trailing_whitespace = true + # Code quality dotnet_diagnostic.CA1062.severity = warning dotnet_diagnostic.CA1303.severity = error diff --git a/source/NewThemeCommand.cs b/source/NewThemeCommand.cs index d9fa17f..c138dc1 100644 --- a/source/NewThemeCommand.cs +++ b/source/NewThemeCommand.cs @@ -2,7 +2,6 @@ using Serilog; using SuCoS.Models; using SuCoS.Models.CommandLineOptions; using SuCoS.Parser; -using System.Reflection; namespace SuCoS; diff --git a/source/ServerHandlers/StaticFileRequest.cs b/source/ServerHandlers/StaticFileRequest.cs index eb148b5..6703a15 100644 --- a/source/ServerHandlers/StaticFileRequest.cs +++ b/source/ServerHandlers/StaticFileRequest.cs @@ -7,7 +7,7 @@ namespace SuCoS.ServerHandlers; /// public class StaticFileRequest : IServerHandlers { - private readonly string basePath; + private readonly string? basePath; private readonly bool inTheme; /// @@ -15,7 +15,7 @@ public class StaticFileRequest : IServerHandlers /// /// /// - public StaticFileRequest(string basePath, bool inTheme) + public StaticFileRequest(string? basePath, bool inTheme) { this.basePath = basePath; this.inTheme = inTheme; @@ -41,7 +41,7 @@ public class StaticFileRequest : IServerHandlers ArgumentNullException.ThrowIfNull(requestPath); ArgumentNullException.ThrowIfNull(response); - var fileAbsolutePath = Path.Combine(basePath, requestPath.TrimStart('/')); + var fileAbsolutePath = Path.Combine(basePath!, requestPath.TrimStart('/')); response.ContentType = GetContentType(fileAbsolutePath!); await using var fileStream = new FileStream(fileAbsolutePath!, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); response.ContentLength64 = fileStream.Length; diff --git a/source/SuCoS.csproj b/source/SuCoS.csproj index 32eb4dc..3d3430d 100644 --- a/source/SuCoS.csproj +++ b/source/SuCoS.csproj @@ -5,7 +5,7 @@ net8.0 enable enable - true + true true true -- GitLab