From d51647ae330f288e6504f90d4b851f4b86543660 Mon Sep 17 00:00:00 2001 From: mpl Date: Fri, 29 Nov 2013 00:19:04 +0100 Subject: [PATCH] camput: delete command, to send a delete claim http://camlistore.org/issue/191 Change-Id: I053ab468420cc173e6122909bf3a0b16e4d43224 --- cmd/camput/delete.go | 70 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 cmd/camput/delete.go diff --git a/cmd/camput/delete.go b/cmd/camput/delete.go new file mode 100644 index 000000000..4efa0b7f4 --- /dev/null +++ b/cmd/camput/delete.go @@ -0,0 +1,70 @@ +/* +Copyright 2013 The Camlistore Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "flag" + "fmt" + + "camlistore.org/pkg/blob" + "camlistore.org/pkg/cmdmain" + "camlistore.org/pkg/schema" +) + +type deleteCmd struct { + up *Uploader +} + +func init() { + cmdmain.RegisterCommand("delete", func(flags *flag.FlagSet) cmdmain.CommandRunner { + cmd := new(deleteCmd) + return cmd + }) +} + +func (c *deleteCmd) Describe() string { + return "Create and upload a delete claim." +} + +func (c *deleteCmd) Usage() { + cmdmain.Errorf("Usage: camput [globalopts] delete [blobref2]...") +} + +func (c *deleteCmd) RunCommand(args []string) error { + if len(args) < 1 { + return cmdmain.UsageError("Need at least one blob to delete.") + } + if err := delete(args); err != nil { + return err + } + return nil +} + +func delete(args []string) error { + for _, arg := range args { + br, ok := blob.Parse(arg) + if !ok { + return fmt.Errorf("Error parsing blobref %q", arg) + } + bb := schema.NewDeleteClaim(br) + put, err := getUploader().UploadAndSignBlob(bb) + if err := handleResult(bb.Type(), put, err); err != nil { + return err + } + } + return nil +}