mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 17:14:44 +01:00
bff702a6f1
This adds an additional parameter to the creation of each flag. This specifies one or more flag groups. This **must** be set for global flags and **must not** be set for local flags. This causes flags.md to be built with sections to aid comprehension and it causes the documentation pages for each command (and the `--help`) to be built showing the flags groups as specified in the `groups` annotation on the command. See: https://forum.rclone.org/t/make-docs-for-mortals-not-only-rclone-gurus/39476/
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
// Package deletefile provides the deletefile command.
|
|
package deletefile
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/rclone/rclone/cmd"
|
|
"github.com/rclone/rclone/fs"
|
|
"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.
|
|
`,
|
|
Annotations: map[string]string{
|
|
"versionIntroduced": "v1.42",
|
|
"groups": "Important",
|
|
},
|
|
Run: func(command *cobra.Command, args []string) {
|
|
cmd.CheckArgs(1, 1, command, args)
|
|
f, 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: %w", args[0], fs.ErrorObjectNotFound)
|
|
}
|
|
fileObj, err := f.NewObject(context.Background(), fileName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return operations.DeleteFile(context.Background(), fileObj)
|
|
})
|
|
},
|
|
}
|