storj/cmd/uplink/cmd/rm.go
Cameron 555e7f1897 CLI commands with bucket store API (#304)
* add mb command

* forgot colon

* add command descriptions

* use utils.ParseURL in commands

* return error message instead of minio.BucketAlreadyExists in mb

* ls command with bucket store functionality

* rb command with bucket store functionality

* rm command with bucket store functionality

* newline

* use print rather than errs for messages, add no buckets messsage

* cp command with bucket store functionality

* remove deprecated getStorjObjects function

* defer utils.LogClose(f) on instead of defer f.Close()

* Check for no buckets after for loop

* add checks for unspecified bucket in bucket store methods

* fix incorrect return types

* add no path error messages in object store methods

* split copy into helpers

* srcObj scheme check in download

* print buckets instead of appending to slice

* check if destObj.Host != srcObj.Host

* better method of handling destination name if not specified

* uplink rename

* final cleanups

* trailing slash fixes

* linting

* more linting

* helpful error messages

* Adjust startAfter after merging #328

* Improve output messages

* Improved error check for empty bucket and path

* No page limit on client side. Rely on server side limit.

* Better time formatting

* Fix paths in recursive list results
2018-09-09 11:31:26 -06:00

58 lines
923 B
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"storj.io/storj/pkg/paths"
"storj.io/storj/pkg/process"
"storj.io/storj/pkg/utils"
)
func init() {
addCmd(&cobra.Command{
Use: "rm",
Short: "Delete an object",
RunE: delete,
})
}
func delete(cmd *cobra.Command, args []string) error {
ctx := process.Ctx(cmd)
if len(args) == 0 {
return fmt.Errorf("No object specified for deletion")
}
u, err := utils.ParseURL(args[0])
if err != nil {
return err
}
if u.Host == "" {
return fmt.Errorf("No bucket specified. Please use format sj://bucket/")
}
bs, err := cfg.BucketStore(ctx)
if err != nil {
return err
}
o, err := bs.GetObjectStore(ctx, u.Host)
if err != nil {
return err
}
err = o.Delete(ctx, paths.New(u.Path))
if err != nil {
return err
}
fmt.Printf("Deleted %s\n", u)
return nil
}