Per the decision on the issue (option 1), --json no longer implies Quiet. Folding --json into Quiet pinned the stderr log level to WARN, so prune --json gave a machine consumer no record of the local index rows it deleted. The two effects are now split: a JSON field on log.Options drives only the stdout UI-quiet in setupGlobals, keeping the JSON document clean, while the stderr log level follows --verbose/--debug again (diagnostics have gone to stderr since #82). The same coupling is removed for snapshot verify, snapshot remove and remote info; snapshot list was already decoupled. Model: opus-4-8
108 lines
2.8 KiB
Go
108 lines
2.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/spf13/cobra"
|
|
"sneak.berlin/go/vaultik/internal/log"
|
|
"sneak.berlin/go/vaultik/internal/vaultik"
|
|
)
|
|
|
|
// errNukeNeedsForce guards the destructive 'remote nuke' subcommand.
|
|
var errNukeNeedsForce = errors.New(
|
|
"remote nuke requires --force (this deletes ALL remote snapshots and blobs)")
|
|
|
|
// NewRemoteCommand creates the remote command and subcommands
|
|
func NewRemoteCommand() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "remote",
|
|
Short: "Remote storage management commands",
|
|
Long: "Commands for inspecting and managing remote storage",
|
|
}
|
|
|
|
// Add subcommands
|
|
cmd.AddCommand(newRemoteInfoCommand())
|
|
cmd.AddCommand(newRemoteNukeCommand())
|
|
|
|
return cmd
|
|
}
|
|
|
|
// newRemoteNukeCommand creates the 'remote nuke' subcommand.
|
|
func newRemoteNukeCommand() *cobra.Command {
|
|
var force bool
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "nuke",
|
|
Short: "Delete ALL snapshot metadata and blobs from the backup destination store",
|
|
Long: `Removes every snapshot's metadata and every blob from remote
|
|
storage. After this command completes successfully the bucket prefix is
|
|
empty and the next backup starts from scratch.
|
|
|
|
This is destructive and irreversible. Requires --force.`,
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
if !force {
|
|
return errNukeNeedsForce
|
|
}
|
|
|
|
return runVaultikApp(cmd, false, false, "Remote nuke failed",
|
|
func(v *vaultik.Vaultik) error {
|
|
return v.NukeRemote(true)
|
|
})
|
|
},
|
|
}
|
|
|
|
cmd.Flags().BoolVar(&force, "force", false,
|
|
"Required: confirm destruction of ALL remote data")
|
|
|
|
return cmd
|
|
}
|
|
|
|
// newRemoteInfoCommand creates the 'remote info' subcommand
|
|
func newRemoteInfoCommand() *cobra.Command {
|
|
var jsonOutput bool
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "info",
|
|
Short: "Display remote storage information",
|
|
Long: `Shows detailed information about remote storage, including:
|
|
- Size of all snapshot metadata (per snapshot and total)
|
|
- Count and total size of all blobs
|
|
- Count and size of referenced blobs (from all manifests)
|
|
- Count and size of orphaned blobs (not referenced by any manifest)`,
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
// Use unified config resolution
|
|
configPath, err := ResolveConfigPath()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
rootFlags := GetRootFlags()
|
|
|
|
return RunOperation(cmd.Context(), AppOptions{
|
|
ConfigPath: configPath,
|
|
LogOptions: log.Options{
|
|
Verbose: rootFlags.Verbose,
|
|
Debug: rootFlags.Debug,
|
|
Quiet: rootFlags.Quiet,
|
|
JSON: jsonOutput,
|
|
},
|
|
}, func(v *vaultik.Vaultik) error {
|
|
return v.RemoteInfo(jsonOutput)
|
|
}, func(err error) {
|
|
if jsonOutput {
|
|
return
|
|
}
|
|
|
|
log.Error("Failed to get remote info", "error", err)
|
|
ReportErrorf("Failed to get remote info: %v", err)
|
|
})
|
|
},
|
|
}
|
|
|
|
cmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
|
|
|
|
return cmd
|
|
}
|