From 14cf440476ca084710cff3143cf2abd52ee7c8ff Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Tue, 28 Nov 2023 17:15:51 +0100 Subject: [PATCH] Add skip frontmatter settings --- ...e_skipFrontmatterOrder=False.verified.txt} | 0 ...lse_skipFrontmatterOrder=True.verified.txt | 5 +++ ...ue_skipFrontmatterOrder=False.verified.txt | 5 +++ ...se_skipFrontmatterOrder=False.verified.txt | 5 +++ ...se_skipFrontmatterOrder=False.verified.txt | 1 + .../TextWriterMarkdownExtensionsTests.cs | 24 +++++++++-- src/ARI/Commands/InventoryCommand.cs | 15 ++++--- .../Commands/Settings/InventorySettings.cs | 12 ++++++ .../TextWriterMarkdownExtensions.cs | 41 +++++++++++++------ 9 files changed, 87 insertions(+), 21 deletions(-) rename src/ARI.Tests/Unit/Extensions/{TextWriterMarkdownExtensionsTests.AddFrontmatter.verified.txt => TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=False_skipFrontmatterModified=False_skipFrontmatterOrder=False.verified.txt} (100%) create mode 100644 src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=False_skipFrontmatterModified=False_skipFrontmatterOrder=True.verified.txt create mode 100644 src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=False_skipFrontmatterModified=True_skipFrontmatterOrder=False.verified.txt create mode 100644 src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=True_skipFrontmatterModified=False_skipFrontmatterOrder=False.verified.txt create mode 100644 src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=True_skipFrontmatterSummary=False_skipFrontmatterModified=False_skipFrontmatterOrder=False.verified.txt diff --git a/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter.verified.txt b/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=False_skipFrontmatterModified=False_skipFrontmatterOrder=False.verified.txt similarity index 100% rename from src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter.verified.txt rename to src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=False_skipFrontmatterModified=False_skipFrontmatterOrder=False.verified.txt diff --git a/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=False_skipFrontmatterModified=False_skipFrontmatterOrder=True.verified.txt b/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=False_skipFrontmatterModified=False_skipFrontmatterOrder=True.verified.txt new file mode 100644 index 0000000..c165578 --- /dev/null +++ b/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=False_skipFrontmatterModified=False_skipFrontmatterOrder=True.verified.txt @@ -0,0 +1,5 @@ +--- +summary: Summary +modifiedby: ARI +modified: 9999-12-31 23:59 +--- diff --git a/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=False_skipFrontmatterModified=True_skipFrontmatterOrder=False.verified.txt b/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=False_skipFrontmatterModified=True_skipFrontmatterOrder=False.verified.txt new file mode 100644 index 0000000..eb324e0 --- /dev/null +++ b/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=False_skipFrontmatterModified=True_skipFrontmatterOrder=False.verified.txt @@ -0,0 +1,5 @@ +--- +summary: Summary +modifiedby: ARI +order: 0 +--- diff --git a/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=True_skipFrontmatterModified=False_skipFrontmatterOrder=False.verified.txt b/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=True_skipFrontmatterModified=False_skipFrontmatterOrder=False.verified.txt new file mode 100644 index 0000000..827808d --- /dev/null +++ b/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=False_skipFrontmatterSummary=True_skipFrontmatterModified=False_skipFrontmatterOrder=False.verified.txt @@ -0,0 +1,5 @@ +--- +modifiedby: ARI +modified: 9999-12-31 23:59 +order: 0 +--- diff --git a/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=True_skipFrontmatterSummary=False_skipFrontmatterModified=False_skipFrontmatterOrder=False.verified.txt b/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=True_skipFrontmatterSummary=False_skipFrontmatterModified=False_skipFrontmatterOrder=False.verified.txt new file mode 100644 index 0000000..c1b8d74 --- /dev/null +++ b/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.AddFrontmatter_skipFrontmatter=True_skipFrontmatterSummary=False_skipFrontmatterModified=False_skipFrontmatterOrder=False.verified.txt @@ -0,0 +1 @@ +emptyString \ No newline at end of file diff --git a/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.cs b/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.cs index 860891b..f16ac8f 100644 --- a/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.cs +++ b/src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.cs @@ -1,14 +1,24 @@ using ARI.Models.Tenant; using ARI.Models.Tenant.Subscription; using ARI.Models.Tenant.Subscription.ResourceGroup; +using Spectre.Console.Cli; namespace ARI.Tests.Unit.Extensions; [TestFixture] public class TextWriterMarkdownExtensionsTests { - [Test] - public async Task AddFrontmatter() + [TestCase(false, false, false, false)] + [TestCase(true, false, false, false)] + [TestCase(false, true, false, false)] + [TestCase(false, false, true, false)] + [TestCase(false, false, false, true)] + public async Task AddFrontmatter( + bool skipFrontmatter, + bool skipFrontmatterSummary, + bool skipFrontmatterModified, + bool skipFrontmatterOrder + ) { // Given var sw = new StringWriter(); @@ -16,11 +26,19 @@ public async Task AddFrontmatter() var summary = "Summary"; var order = 0; + var settings = new ARI.Commands.Settings.InventorySettings + { + SkipFrontmatter = skipFrontmatter, + SkipFrontmatterSummary = skipFrontmatterSummary, + SkipFrontmatterModified = skipFrontmatterModified, + SkipFrontmatterOrder = skipFrontmatterOrder + }; // When await sw.AddFrontmatter( lastUpdateTime, summary, - order + order, + settings ); // Then diff --git a/src/ARI/Commands/InventoryCommand.cs b/src/ARI/Commands/InventoryCommand.cs index 00713bf..082cfb0 100644 --- a/src/ARI/Commands/InventoryCommand.cs +++ b/src/ARI/Commands/InventoryCommand.cs @@ -41,7 +41,8 @@ public override async Task ExecuteAsync(CommandContext context, InventorySe await writer.AddFrontmatter( modified, $"Tenant {tenant.DisplayName} ({tenant.TenantId})", - 1 + 1, + settings ); await writer.AddTenantOverview(tenant); @@ -51,7 +52,8 @@ await writer.AddFrontmatter( await writer.AddFrontmatter( modified, "Azure Inventory", - 1 + 1, + settings ); } @@ -72,7 +74,8 @@ await ForEachAsync( await writer.AddFrontmatter( modified, $"Subscription {subscription.DisplayName} ({subscription.TenantId})", - subscription.Order + subscription.Order, + settings ); await writer.AddSubscriptionOverview(subscription); @@ -97,7 +100,8 @@ await ForEachAsync( await writer.AddFrontmatter( modified, $"Resource Group {resourceGroup.Name} ({subscription.SubscriptionId})", - resourceGroup.Order + resourceGroup.Order, + settings ); await writer.AddResourceGroupOverview(resourceGroup); @@ -157,7 +161,8 @@ await ForEachAsync( await writer.AddFrontmatter( modified, $"Resource {resource.Name} ({subscription.SubscriptionId})", - resource.Order + resource.Order, + settings ); await writer.AddResourceOverview(resource); diff --git a/src/ARI/Commands/Settings/InventorySettings.cs b/src/ARI/Commands/Settings/InventorySettings.cs index a0cb588..5eddf51 100644 --- a/src/ARI/Commands/Settings/InventorySettings.cs +++ b/src/ARI/Commands/Settings/InventorySettings.cs @@ -22,4 +22,16 @@ public class InventorySettings : CommandSettings [CommandOption("--markdown-name")] public string MarkdownName { get; set; } = "index"; + + [CommandOption("--skip-frontmatter")] + public bool SkipFrontmatter { get; set; } + + [CommandOption("--skip-frontmatter-summary")] + public bool SkipFrontmatterSummary { get; set; } + + [CommandOption("--skip-frontmatter-modifed")] + public bool SkipFrontmatterModified { get; set; } + + [CommandOption("--skip-frontmatter-order")] + public bool SkipFrontmatterOrder { get; set; } } \ No newline at end of file diff --git a/src/ARI/Extensions/TextWriterMarkdownExtensions.cs b/src/ARI/Extensions/TextWriterMarkdownExtensions.cs index faa2009..2e95070 100644 --- a/src/ARI/Extensions/TextWriterMarkdownExtensions.cs +++ b/src/ARI/Extensions/TextWriterMarkdownExtensions.cs @@ -15,20 +15,35 @@ public static async Task AddFrontmatter( this TextWriter writer, DateTimeOffset lastUpdateTime, string summary, - int order) + int order, + InventorySettings settings + ) { - await writer.WriteLineAsync( - FormattableString.Invariant( - $$""" - --- - summary: {{summary}} - modifiedby: ARI - modified: {{lastUpdateTime:yyyy-MM-dd HH:mm}} - order: {{order}} - --- - """ - ) - ); + if (settings.SkipFrontmatter) + { + return; + } + + await writer.WriteLineAsync("---"); + + if (!settings.SkipFrontmatterSummary) + { + await writer.WriteLineAsync(FormattableString.Invariant($"summary: {summary}")); + } + + await writer.WriteLineAsync(FormattableString.Invariant($"modifiedby: ARI")); + + if (!settings.SkipFrontmatterModified) + { + await writer.WriteLineAsync(FormattableString.Invariant($"modified: {lastUpdateTime:yyyy-MM-dd HH:mm}")); + } + + if (!settings.SkipFrontmatterOrder) + { + await writer.WriteLineAsync(FormattableString.Invariant($"order: {order}")); + } + + await writer.WriteLineAsync("---"); } public static async Task AddTenantOverview(