Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OrderBy when iterating over tags and keys #2

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 6 additions & 0 deletions src/ARI/Commands/Settings/InventorySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ public class InventorySettings : CommandSettings

[CommandOption("--markdown-name")]
public string MarkdownName { get; set; } = "index";

[CommandOption("--avoid-generating-diffs")]
public bool AvoidGeneratingDiffs { get; set; }



}
47 changes: 32 additions & 15 deletions src/ARI/Extensions/TextWriterMarkdownExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,37 @@ 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.AvoidGeneratingDiffs)
{
await writer.WriteLineAsync(
FormattableString.Invariant(
$$"""
---
summary: {{summary}}
modifiedby: ARI
modified: {{lastUpdateTime:yyyy-MM-dd HH:mm}}
order: {{order}}
---
"""
)
);
}
else
{
await writer.WriteLineAsync(
FormattableString.Invariant(
$$"""
---
summary: {{summary}}
modifiedby: ARI
---
"""
)
);
}
}

public static async Task AddTenantOverview(
Expand Down Expand Up @@ -115,7 +132,7 @@ await writer.WriteLineAsync(
return;
}

foreach (var (key, value) in tags)
foreach (var (key, value) in tags.OrderBy(kv => kv.Key, StringComparer.OrdinalIgnoreCase))
{
await writer.WriteLineAsync(
FormattableString.Invariant(
Expand Down Expand Up @@ -146,7 +163,7 @@ await writer.WriteLineAsync(
)
);

foreach (var (key, value) in children)
foreach (var (key, value) in children.OrderBy(v => v.PublicId, StringComparer.OrdinalIgnoreCase))
{
await writer.WriteLineAsync(
FormattableString.Invariant(
Expand Down
Loading