Skip to content

Commit

Permalink
Add skip frontmatter settings
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Nov 28, 2023
1 parent 419f32b commit 14cf440
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
summary: Summary
modifiedby: ARI
modified: 9999-12-31 23:59
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
summary: Summary
modifiedby: ARI
order: 0
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
modifiedby: ARI
modified: 9999-12-31 23:59
order: 0
---
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
emptyString
24 changes: 21 additions & 3 deletions src/ARI.Tests/Unit/Extensions/TextWriterMarkdownExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
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();
var lastUpdateTime = DateTimeOffset.MaxValue;
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
Expand Down
15 changes: 10 additions & 5 deletions src/ARI/Commands/InventoryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public override async Task<int> ExecuteAsync(CommandContext context, InventorySe
await writer.AddFrontmatter(
modified,
$"Tenant {tenant.DisplayName} ({tenant.TenantId})",
1
1,
settings
);

await writer.AddTenantOverview(tenant);
Expand All @@ -51,7 +52,8 @@ await writer.AddFrontmatter(
await writer.AddFrontmatter(
modified,
"Azure Inventory",
1
1,
settings
);
}

Expand All @@ -72,7 +74,8 @@ await ForEachAsync(
await writer.AddFrontmatter(
modified,
$"Subscription {subscription.DisplayName} ({subscription.TenantId})",
subscription.Order
subscription.Order,
settings
);

await writer.AddSubscriptionOverview(subscription);
Expand All @@ -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);
Expand Down Expand Up @@ -157,7 +161,8 @@ await ForEachAsync(
await writer.AddFrontmatter(
modified,
$"Resource {resource.Name} ({subscription.SubscriptionId})",
resource.Order
resource.Order,
settings
);

await writer.AddResourceOverview(resource);
Expand Down
12 changes: 12 additions & 0 deletions src/ARI/Commands/Settings/InventorySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
41 changes: 28 additions & 13 deletions src/ARI/Extensions/TextWriterMarkdownExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 14cf440

Please sign in to comment.