mirror of
https://github.com/rclone/rclone.git
synced 2024-11-08 01:25:14 +01:00
e43b5ce5e5
This is possible now that we no longer support go1.12 and brings rclone into line with standard practices in the Go world. This also removes errors.New and errors.Errorf from lib/errors and prefers the stdlib errors package over lib/errors.
39 lines
1004 B
Go
39 lines
1004 B
Go
package deletefile
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/rclone/rclone/cmd"
|
|
"github.com/rclone/rclone/fs/operations"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
cmd.Root.AddCommand(commandDefinition)
|
|
}
|
|
|
|
var commandDefinition = &cobra.Command{
|
|
Use: "deletefile remote:path",
|
|
Short: `Remove a single file from remote.`,
|
|
Long: `
|
|
Remove a single file from remote. Unlike ` + "`" + `delete` + "`" + ` it cannot be used to
|
|
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 fmt.Errorf("%s is a directory or doesn't exist", args[0])
|
|
}
|
|
fileObj, err := fs.NewObject(context.Background(), fileName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return operations.DeleteFile(context.Background(), fileObj)
|
|
})
|
|
},
|
|
}
|