Add JSON output format for CLI commands

This commit is contained in:
2026-06-01 20:44:27 +00:00
parent 0382978af0
commit e51bc28b05
13 changed files with 849 additions and 48 deletions

View File

@@ -20,19 +20,28 @@ func runCommand(ctx context.Context, args []string, stdout, stderr io.Writer) in
configPath := flags.String("config", "", "path to config file")
dryRun := flags.Bool("dry-run", false, "load and validate config without publishing")
force := flags.Bool("force", false, "allow explicit destructive replacement for supported conflicts")
formatFlag := addFormatFlag(flags)
if err := flags.Parse(args); err != nil {
return exitUsage
}
if rejectPositionalArgs(stderr, "run", flags.Args()) {
return exitUsage
}
format, ok := parseOutputFormat(stderr, "run", *formatFlag)
if !ok {
return exitUsage
}
if err := app.Run(ctx, app.RunOptions{
ConfigPath: *configPath,
DryRun: *dryRun,
Force: *force,
Stdout: stdout,
ConfigPath: *configPath,
DryRun: *dryRun,
Force: *force,
Stdout: stdout,
OutputFormat: format,
}); err != nil {
if app.IsJSONOutput(format) && app.IsPartialResultError(err) {
return exitError
}
return fail(stderr, err)
}
return exitOK
@@ -40,12 +49,14 @@ func runCommand(ctx context.Context, args []string, stdout, stderr io.Writer) in
func printRunHelp(w io.Writer) {
fmt.Fprint(w, `Usage:
distributor run --config <path> [--dry-run] [--force]
distributor run --config <path> [--dry-run] [--force] [--format text|json]
Options:
--config <path> Path to config file
--dry-run Load and validate config without publishing
--force Allow explicit destructive replacement for supported conflicts
--format text|json
Output format
Run discovers configured source bundles, plans each destination, publishes
selected outputs unless --dry-run is set, and prints a final status summary.