Expose reconcile state command
This commit is contained in:
84
internal/cli/reconcile_state.go
Normal file
84
internal/cli/reconcile_state.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"gitea.maximumdirect.net/eric/distributor/internal/app"
|
||||
)
|
||||
|
||||
func reconcileStateCommand(ctx context.Context, args []string, stdout, stderr io.Writer) int {
|
||||
if hasHelp(args) {
|
||||
printReconcileStateHelp(stdout)
|
||||
return exitOK
|
||||
}
|
||||
|
||||
flags := newFlagSet("reconcile-state", stderr)
|
||||
configPath := flags.String("config", "", "path to config file")
|
||||
pipelineID := flags.String("pipeline", "", "pipeline id")
|
||||
destinationID := flags.String("destination", "", "destination id")
|
||||
allOwners := flags.Bool("all-owners", false, "repair all shared-root owners in the selected destination root")
|
||||
dryRun := flags.Bool("dry-run", false, "report repairs without rewriting state")
|
||||
formatFlag := addFormatFlag(flags)
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return exitUsage
|
||||
}
|
||||
if rejectPositionalArgs(stderr, "reconcile-state", flags.Args()) {
|
||||
return exitUsage
|
||||
}
|
||||
format, ok := parseOutputFormat(stderr, "reconcile-state", *formatFlag)
|
||||
if !ok {
|
||||
return exitUsage
|
||||
}
|
||||
if !validateReconcileStateFlags(stderr, *configPath, *pipelineID, *destinationID) {
|
||||
return exitUsage
|
||||
}
|
||||
|
||||
if _, err := app.ReconcileState(ctx, app.ReconcileStateOptions{
|
||||
ConfigPath: *configPath,
|
||||
PipelineID: *pipelineID,
|
||||
DestinationID: *destinationID,
|
||||
AllOwners: *allOwners,
|
||||
DryRun: *dryRun,
|
||||
Stdout: stdout,
|
||||
OutputFormat: format,
|
||||
}); err != nil {
|
||||
return fail(stderr, err)
|
||||
}
|
||||
return exitOK
|
||||
}
|
||||
|
||||
func validateReconcileStateFlags(stderr io.Writer, configPath, pipelineID, destinationID string) bool {
|
||||
if configPath == "" {
|
||||
fmt.Fprintf(stderr, "%s: reconcile-state requires --config\n", app.Name)
|
||||
return false
|
||||
}
|
||||
if pipelineID == "" {
|
||||
fmt.Fprintf(stderr, "%s: reconcile-state requires --pipeline\n", app.Name)
|
||||
return false
|
||||
}
|
||||
if destinationID == "" {
|
||||
fmt.Fprintf(stderr, "%s: reconcile-state requires --destination\n", app.Name)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func printReconcileStateHelp(w io.Writer) {
|
||||
fmt.Fprint(w, `Usage:
|
||||
distributor reconcile-state --config <path> --pipeline <id> --destination <id> [--all-owners] [--dry-run] [--format text|json]
|
||||
|
||||
Options:
|
||||
--config <path> Path to config file
|
||||
--pipeline <id> Pipeline id that selects the destination root
|
||||
--destination <id> Destination id that selects the destination root
|
||||
--all-owners Repair all shared-root owners in the selected destination root
|
||||
--dry-run Report repairs without rewriting state
|
||||
--format text|json Output format
|
||||
|
||||
Reconcile-state checks managed output records against destination storage and
|
||||
removes records for missing managed outputs unless --dry-run is set. It reports
|
||||
unmanaged entries but does not delete or adopt destination files.
|
||||
`)
|
||||
}
|
||||
Reference in New Issue
Block a user