rclone/cmd/deletefile/deletefile.go

39 lines
1.0 KiB
Go
Raw Permalink Normal View History

2018-06-09 18:22:25 +02:00
package deletefile
import (
"context"
2018-06-09 18:22:25 +02:00
"github.com/pkg/errors"
"github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs/operations"
2018-06-09 18:22:25 +02:00
"github.com/spf13/cobra"
)
func init() {
2019-10-11 17:58:11 +02:00
cmd.Root.AddCommand(commandDefinition)
2018-06-09 18:22:25 +02:00
}
2019-10-11 17:58:11 +02:00
var commandDefinition = &cobra.Command{
2018-06-09 18:22:25 +02:00
Use: "deletefile remote:path",
2018-06-17 17:58:37 +02:00
Short: `Remove a single file from remote.`,
2018-06-09 18:22:25 +02:00
Long: `
2018-06-17 17:58:37 +02:00
Remove a single file from remote. Unlike ` + "`" + `delete` + "`" + ` it cannot be used to
2018-06-09 18:22:25 +02:00
remove a directory and it doesn't obey include/exclude filters - if the specified file exists,
it will always be removed.
`,
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fs, fileName := cmd.NewFsFile(args[0])
cmd.Run(true, false, command, func() error {
if fileName == "" {
return errors.Errorf("%s is a directory or doesn't exist", args[0])
}
fileObj, err := fs.NewObject(context.Background(), fileName)
2018-06-09 18:22:25 +02:00
if err != nil {
return err
}
return operations.DeleteFile(context.Background(), fileObj)
2018-06-09 18:22:25 +02:00
})
},
}