- Set up cobra CLI with all commands (backup, restore, prune, verify, fetch) - Integrate uber/fx for dependency injection and lifecycle management - Add globals package with build-time variables (Version, Commit) - Implement config loading from YAML with validation - Create core data models (FileInfo, ChunkInfo, BlobInfo, Snapshot) - Add Makefile with build, test, lint, and clean targets - Include minimal test suite for compilation verification - Update documentation with --quick flag for verify command - Fix markdown numbering in implementation TODO
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.eeqj.de/sneak/vaultik/internal/globals"
|
|
"github.com/spf13/cobra"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
// PruneOptions contains options for the prune command
|
|
type PruneOptions struct {
|
|
Bucket string
|
|
Prefix string
|
|
DryRun bool
|
|
}
|
|
|
|
// NewPruneCommand creates the prune command
|
|
func NewPruneCommand() *cobra.Command {
|
|
opts := &PruneOptions{}
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "prune <bucket> <prefix>",
|
|
Short: "Remove unreferenced blobs",
|
|
Long: `Delete blobs that are no longer referenced by any snapshot`,
|
|
Args: cobra.ExactArgs(2),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
opts.Bucket = args[0]
|
|
opts.Prefix = args[1]
|
|
return runPrune(cmd.Context(), opts)
|
|
},
|
|
}
|
|
|
|
cmd.Flags().BoolVar(&opts.DryRun, "dry-run", false, "Show what would be deleted without actually deleting")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func runPrune(ctx context.Context, opts *PruneOptions) 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 prune logic
|
|
fmt.Printf("Pruning bucket %s with prefix %s\n", opts.Bucket, opts.Prefix)
|
|
if opts.DryRun {
|
|
fmt.Println("Running in dry-run mode")
|
|
}
|
|
return nil
|
|
}),
|
|
fx.NopLogger,
|
|
)
|
|
|
|
if err := app.Start(ctx); err != nil {
|
|
return fmt.Errorf("failed to start prune: %w", err)
|
|
}
|
|
defer func() {
|
|
if err := app.Stop(ctx); err != nil {
|
|
fmt.Printf("error stopping app: %v\n", err)
|
|
}
|
|
}()
|
|
|
|
return nil
|
|
} |