Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

local: implement backend command "noop" for testing purposes

Nick Craig-Woode2916f3a5537
diff --git a/backend/local/local.go b/backend/local/local.go
index 8d2128292..126edd4d0 100644
--- a/backend/local/local.go
+++ b/backend/local/local.go
@@ -41,6 +41,7 @@ func init() {
Name: "local",
Description: "Local Disk",
NewFs: NewFs,
+ CommandHelp: commandHelp,
Options: []fs.Option{{
Name: "nounc",
Help: "Disable UNC (long path names) conversion on Windows",
@@ -697,6 +698,50 @@ func (f *Fs) Hashes() hash.Set {
return hash.Supported()
}
+var commandHelp = []fs.CommandHelp{
+ {
+ Name: "noop",
+ Short: "A null operation for testing backend commands",
+ Long: `This is a test command which has some options
+you can try to change the output.`,
+ Opts: map[string]string{
+ "echo": "echo the input arguments",
+ "error": "return an error based on option value",
+ },
+ },
+}
+
+// Command the backend to run a named command
+//
+// The command run is name
+// args may be used to read arguments from
+// opts may be used to read optional arguments from
+//
+// The result should be capable of being JSON encoded
+// If it is a string or a []string it will be shown to the user
+// otherwise it will be JSON encoded and shown to the user like that
+func (f *Fs) Command(ctx context.Context, name string, arg []string, opt map[string]string) (interface{}, error) {
+ switch name {
+ case "noop":
+ if txt, ok := opt["error"]; ok {
+ if txt == "" {
+ txt = "unspecified error"
+ }
+ return nil, errors.New(txt)
+ }
+ if _, ok := opt["echo"]; ok {
+ out := map[string]interface{}{}
+ out["name"] = name
+ out["arg"] = arg
+ out["opt"] = opt
+ return out, nil
+ }
+ return nil, nil
+ default:
+ return nil, fs.ErrorCommandNotFound
+ }
+}
+
// ------------------------------------------------------------
// Fs returns the parent Fs
@@ -1164,6 +1209,7 @@ var (
_ fs.PutStreamer = &Fs{}
_ fs.Mover = &Fs{}
_ fs.DirMover = &Fs{}
+ _ fs.Commander = &Fs{}
_ fs.OpenWriterAter = &Fs{}
_ fs.Object = &Object{}
)
diff --git a/docs/content/local.md b/docs/content/local.md
index 6d6d806d1..1e62b5e1c 100644
--- a/docs/content/local.md
+++ b/docs/content/local.md
@@ -424,4 +424,34 @@ See: the [encoding section in the overview](/overview/#encoding) for more info.
- Type: MultiEncoder
- Default: Slash,Dot
+### Backend commands
+
+Here are the commands specific to the local backend.
+
+Run them with with
+
+ rclone backend COMMAND remote:
+
+The help below will explain what arguments each command takes.
+
+See [the "rclone backend" command](/commands/rclone_backend/) for more
+info on how to pass options and arguments.
+
+These can be run on a running backend using the rc command
+[backend/command](/rc/#backend/command).
+
+#### noop
+
+A null operation for testing backend commands
+
+ rclone backend noop remote: [options] [<arguments>+]
+
+This is a test command which has some options
+you can try to change the output.
+
+Options:
+
+- "echo": echo the input arguments
+- "error": return an error based on option value
+
<!--- autogenerated options stop -->