package cli import ( "context" "fmt" "os" "git.eeqj.de/sneak/vaultik/internal/globals" "github.com/spf13/cobra" "go.uber.org/fx" ) // VerifyOptions contains options for the verify command type VerifyOptions struct { Bucket string Prefix string SnapshotID string Quick bool } // NewVerifyCommand creates the verify command func NewVerifyCommand() *cobra.Command { opts := &VerifyOptions{} cmd := &cobra.Command{ Use: "verify", Short: "Verify backup integrity", Long: `Check that all referenced blobs exist and verify metadata integrity`, Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { // Validate required flags if opts.Bucket == "" { return fmt.Errorf("--bucket is required") } if opts.Prefix == "" { return fmt.Errorf("--prefix is required") } return runVerify(cmd.Context(), opts) }, } cmd.Flags().StringVar(&opts.Bucket, "bucket", "", "S3 bucket name") cmd.Flags().StringVar(&opts.Prefix, "prefix", "", "S3 prefix") cmd.Flags().StringVar(&opts.SnapshotID, "snapshot", "", "Snapshot ID to verify (optional, defaults to latest)") cmd.Flags().BoolVar(&opts.Quick, "quick", false, "Perform quick verification by checking blob existence and S3 content hashes without downloading") return cmd } func runVerify(ctx context.Context, opts *VerifyOptions) error { if os.Getenv("VAULTIK_PRIVATE_KEY") == "" { return fmt.Errorf("VAULTIK_PRIVATE_KEY environment variable must be set") } app := fx.New( fx.Supply(opts), fx.Provide(globals.New), // Additional modules will be added here fx.Invoke(func(g *globals.Globals) error { // TODO: Implement verify logic if opts.SnapshotID == "" { fmt.Printf("Verifying latest snapshot in bucket %s with prefix %s\n", opts.Bucket, opts.Prefix) } else { fmt.Printf("Verifying snapshot %s in bucket %s with prefix %s\n", opts.SnapshotID, opts.Bucket, opts.Prefix) } if opts.Quick { fmt.Println("Performing quick verification") } else { fmt.Println("Performing deep verification") } return nil }), fx.NopLogger, ) if err := app.Start(ctx); err != nil { return fmt.Errorf("failed to start verify: %w", err) } defer func() { if err := app.Stop(ctx); err != nil { fmt.Printf("error stopping app: %v\n", err) } }() return nil }