rclone/cmd/deletefile/deletefile.go

38 lines
962 B
Go
Raw Normal View History

2018-06-09 16:22:25 +00:00
package deletefile
import (
"github.com/ncw/rclone/cmd"
"github.com/ncw/rclone/fs/operations"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func init() {
cmd.Root.AddCommand(commandDefintion)
}
var commandDefintion = &cobra.Command{
Use: "deletefile remote:path",
2018-06-17 15:58:37 +00:00
Short: `Remove a single file from remote.`,
2018-06-09 16:22:25 +00:00
Long: `
2018-06-17 15:58:37 +00:00
Remove a single file from remote. Unlike ` + "`" + `delete` + "`" + ` it cannot be used to
2018-06-09 16:22:25 +00: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(fileName)
if err != nil {
return err
}
return operations.DeleteFile(fileObj)
})
},
}