Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions util/SeederUtility/Commands/PresetArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

namespace Bit.SeederUtility.Commands;

public enum OutputFormat
Comment thread
mimartin12 marked this conversation as resolved.
Outdated
{
Text,
Json,
}

/// <summary>
/// CLI argument model for the preset command.
/// Supports loading presets from embedded resources.
Expand All @@ -14,6 +20,14 @@ public class PresetArgs : IArgumentModel
[Option('l', "list", Description = "List all available presets and fixtures")]
public bool List { get; set; }

[Option('o', "output", Description = "Output format for --list: text or json (default: text)")]
Comment thread
mimartin12 marked this conversation as resolved.
Outdated
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 +39,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
6 changes: 5 additions & 1 deletion util/SeederUtility/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ public class Program
{
private static int Main(string[] args)
{
PrintBanner();
// Skip the banner when stdout is piped or redirected
Comment thread
mimartin12 marked this conversation as resolved.
Outdated
if (!Console.IsOutputRedirected)
{
PrintBanner();
}

return new AppRunner<Program>()
.Run(args);
Expand Down
Loading