63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
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
|
|
}
|
|
|
|
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
|
|
}
|
|
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,
|
|
OutputFormat: format,
|
|
}); err != nil {
|
|
if app.IsJSONOutput(format) && app.IsPartialResultError(err) {
|
|
return exitError
|
|
}
|
|
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
|
|
|
|
Run discovers configured source bundles, plans each destination, publishes
|
|
selected outputs unless --dry-run is set, and prints a final status summary.
|
|
`)
|
|
}
|