Skip to content
Merged
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
7 changes: 7 additions & 0 deletions util/SeederUtility/Commands/OutputFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ο»Ώnamespace Bit.SeederUtility.Commands;

public enum OutputFormat
{
Text,
Json,
}
14 changes: 14 additions & 0 deletions util/SeederUtility/Commands/PresetArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public class PresetArgs : IArgumentModel
[Option('l', "list", Description = "List all available presets and fixtures")]
public bool List { get; set; }

[Option("output", Description = "Output format for --list: text or json (default: text)")]
public string? Output { get; set; }

public OutputFormat GetOutputFormat() =>
string.IsNullOrWhiteSpace(Output)
? OutputFormat.Text
: Enum.Parse<OutputFormat>(Output, ignoreCase: true);

[Option("mangle", Description = "Enable mangling for test isolation")]
public bool Mangle { get; set; }

Expand All @@ -25,6 +33,12 @@ public class PresetArgs : IArgumentModel

public void Validate()
{
if (!string.IsNullOrWhiteSpace(Output)
&& !Enum.TryParse<OutputFormat>(Output, ignoreCase: true, out _))
{
throw new ArgumentException($"Unrecognized output format '{Output}'. Allowed: text, json.");
}

if (List)
{
return;
Expand Down
18 changes: 15 additions & 3 deletions util/SeederUtility/Commands/PresetCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ο»Ώusing Bit.Seeder.Recipes;
ο»Ώusing System.Text.Json;
using Bit.Seeder.Recipes;
using Bit.Seeder.Services;
using Bit.SeederUtility.Configuration;
using Bit.SeederUtility.Helpers;
Expand All @@ -18,7 +19,7 @@ public void Execute(PresetArgs args)

if (args.List)
{
PrintAvailablePresets();
PrintAvailablePresets(args.GetOutputFormat());
return;
}

Expand Down Expand Up @@ -89,7 +90,7 @@ private static void RunIndividualPreset(PresetArgs args)
ConsoleOutput.PrintMangleMap(deps);
}

private static void PrintAvailablePresets()
private static void PrintAvailablePresets(OutputFormat format = OutputFormat.Text)
{
var available = PresetCatalogService.ListAvailable();

Expand All @@ -108,6 +109,17 @@ private static void PrintAvailablePresets()
}
}

if (format == OutputFormat.Json)
{
var output = new
{
organization = orgPresets,
individual = individualPresets,
};
Console.WriteLine(JsonSerializer.Serialize(output, new JsonSerializerOptions { WriteIndented = true }));
return;
}

Console.WriteLine("Organization Presets:");
foreach (var preset in orgPresets)
{
Expand Down
8 changes: 4 additions & 4 deletions util/SeederUtility/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ private static void PrintBanner()
continue;
}

Console.WriteLine($"{color}{line[minIndent..]}{reset}");
Console.Error.WriteLine($"{color}{line[minIndent..]}{reset}");
}
}

Console.WriteLine($" {bold}{cyan}╔══════════════════════════════════════════╗{reset}");
Console.WriteLine($" {bold}{cyan}β•‘ SEEDER UTILITY β•‘{reset}");
Console.WriteLine($" {bold}{cyan}β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•{reset}");
Console.Error.WriteLine($" {bold}{cyan}╔══════════════════════════════════════════╗{reset}");
Console.Error.WriteLine($" {bold}{cyan}β•‘ SEEDER UTILITY β•‘{reset}");
Console.Error.WriteLine($" {bold}{cyan}β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•{reset}");
}

[Subcommand]
Expand Down
Loading