Files
kopia/cli/command_blob_delete.go
Jarek Kowalski 6a14ac8a2a cli: ensure advanced commands are not accidentally used (#611)
* cli: ensure advanced commands are not accidentally used

This prints an error when a dangerous command is used without
first setting KOPIA_ADVANCED_COMMANDS=enabled environment variable.

Co-authored-by: Julio López <julio+gh@kasten.io>
2020-09-12 20:31:25 -07:00

33 lines
671 B
Go

package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/repo/blob"
)
var (
blobDeleteCommand = blobCommands.Command("delete", "Delete blobs by ID").Alias("rm")
blobDeleteBlobIDs = blobDeleteCommand.Arg("blobIDs", "Blob IDs").Required().Strings()
)
func runDeleteBlobs(ctx context.Context, rep *repo.DirectRepository) error {
advancedCommand()
for _, b := range *blobDeleteBlobIDs {
err := rep.Blobs.DeleteBlob(ctx, blob.ID(b))
if err != nil {
return errors.Wrapf(err, "error deleting %v", b)
}
}
return nil
}
func init() {
blobDeleteCommand.Action(directRepositoryAction(runDeleteBlobs))
}