rclone/cmd/deletefile/deletefile.go

44 lines
1.2 KiB
Go
Raw Normal View History

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