github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/cmd/rcd/rcd.go (about) 1 package rcd 2 3 import ( 4 "log" 5 6 "github.com/ncw/rclone/cmd" 7 "github.com/ncw/rclone/fs/rc/rcflags" 8 "github.com/ncw/rclone/fs/rc/rcserver" 9 "github.com/spf13/cobra" 10 ) 11 12 func init() { 13 cmd.Root.AddCommand(commandDefintion) 14 } 15 16 var commandDefintion = &cobra.Command{ 17 Use: "rcd <path to files to serve>*", 18 Short: `Run rclone listening to remote control commands only.`, 19 Long: ` 20 This runs rclone so that it only listens to remote control commands. 21 22 This is useful if you are controlling rclone via the rc API. 23 24 If you pass in a path to a directory, rclone will serve that directory 25 for GET requests on the URL passed in. It will also open the URL in 26 the browser when rclone is run. 27 28 See the [rc documentation](/rc/) for more info on the rc flags. 29 `, 30 Run: func(command *cobra.Command, args []string) { 31 cmd.CheckArgs(0, 1, command, args) 32 if rcflags.Opt.Enabled { 33 log.Fatalf("Don't supply --rc flag when using rcd") 34 } 35 // Start the rc 36 rcflags.Opt.Enabled = true 37 if len(args) > 0 { 38 rcflags.Opt.Files = args[0] 39 } 40 s, err := rcserver.Start(&rcflags.Opt) 41 if err != nil { 42 log.Fatalf("Failed to start remote control: %v", err) 43 } 44 if s == nil { 45 log.Fatal("rc server not configured") 46 } 47 s.Wait() 48 }, 49 }