rcd: implement new command just to serve the remote control API

This commit is contained in:
Nick Craig-Wood 2018-10-27 16:02:45 +01:00
parent 75252e4a89
commit cff75db6a4
2 changed files with 43 additions and 0 deletions

View File

@ -43,6 +43,7 @@ import (
_ "github.com/ncw/rclone/cmd/purge"
_ "github.com/ncw/rclone/cmd/rc"
_ "github.com/ncw/rclone/cmd/rcat"
_ "github.com/ncw/rclone/cmd/rcd"
_ "github.com/ncw/rclone/cmd/reveal"
_ "github.com/ncw/rclone/cmd/rmdir"
_ "github.com/ncw/rclone/cmd/rmdirs"

42
cmd/rcd/rcd.go Normal file
View File

@ -0,0 +1,42 @@
package rcd
import (
"log"
"github.com/ncw/rclone/cmd"
"github.com/ncw/rclone/fs/rc"
"github.com/ncw/rclone/fs/rc/rcflags"
"github.com/spf13/cobra"
)
func init() {
cmd.Root.AddCommand(commandDefintion)
}
var commandDefintion = &cobra.Command{
Use: "rcd <path to files to serve>*",
Short: `Run rclone listening to remote control commands only.`,
Long: `
This runs rclone so that it only listents to remote control commands.
This is useful if you are controlling rclone via the rc API.
If you pass in a path to a directory, rclone will serve that directory
for GET requests on the URL passed in. It will also open the URL in
the browser when rclone is run.
`,
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(0, 1, command, args)
if rcflags.Opt.Enabled {
log.Fatalf("Don't supply --rc flag when using rcd")
}
// Start the rc
rcflags.Opt.Enabled = true
if len(args) > 0 {
rcflags.Opt.Files = args[0]
}
rc.Start(&rcflags.Opt)
// Run the rc forever
select {}
},
}