Files
distributor/internal/cli/run.go

63 lines
1.6 KiB
Go
Raw Normal View History

2026-05-31 01:47:39 +00:00
package cli
import (
"context"
"fmt"
"io"
"gitea.maximumdirect.net/eric/distributor/internal/app"
)
func runCommand(ctx context.Context, args []string, stdout, stderr io.Writer) int {
if hasHelp(args) {
printRunHelp(stdout)
return exitOK
}
2026-06-04 00:45:12 +00:00
flags := newFlagSet("run", stderr)
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
}
2026-05-31 03:31:57 +00:00
if rejectPositionalArgs(stderr, "run", flags.Args()) {
2026-05-31 01:47:39 +00:00
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,
OutputFormat: format,
}); err != nil {
if app.IsJSONOutput(format) && app.IsPartialResultError(err) {
return exitError
}
2026-05-31 01:47:39 +00:00
return fail(stderr, err)
}
return exitOK
}
func printRunHelp(w io.Writer) {
fmt.Fprint(w, `Usage:
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
2026-05-31 01:47:39 +00:00
Run discovers configured source bundles, plans each destination, publishes
2026-05-31 02:33:09 +00:00
selected outputs unless --dry-run is set, and prints a final status summary.
2026-05-31 01:47:39 +00:00
`)
}