mirror of
https://github.com/rclone/rclone.git
synced 2024-12-21 02:44:02 +08:00
bcdfad3c83
This changes log statements from log to fs package, which is required for --use-json-log to properly make log output in JSON format. The recently added custom linting rule, handled by ruleguard via gocritic via golangci-lint, warns about these and suggests the alternative. Fixing was therefore basically running "golangci-lint run --fix", although some manual fixup of mainly imports are necessary following that.
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
// Package rcd provides the rcd command.
|
|
package rcd
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/rclone/rclone/cmd"
|
|
"github.com/rclone/rclone/fs"
|
|
"github.com/rclone/rclone/fs/rc"
|
|
"github.com/rclone/rclone/fs/rc/rcflags"
|
|
"github.com/rclone/rclone/fs/rc/rcserver"
|
|
libhttp "github.com/rclone/rclone/lib/http"
|
|
"github.com/rclone/rclone/lib/systemd"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
cmd.Root.AddCommand(commandDefinition)
|
|
}
|
|
|
|
var commandDefinition = &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 listens 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.
|
|
|
|
See the [rc documentation](/rc/) for more info on the rc flags.
|
|
|
|
` + libhttp.Help(rcflags.FlagPrefix) + libhttp.TemplateHelp(rcflags.FlagPrefix) + libhttp.AuthHelp(rcflags.FlagPrefix),
|
|
Annotations: map[string]string{
|
|
"versionIntroduced": "v1.45",
|
|
"groups": "RC",
|
|
},
|
|
Run: func(command *cobra.Command, args []string) {
|
|
cmd.CheckArgs(0, 1, command, args)
|
|
if rc.Opt.Enabled {
|
|
fs.Fatalf(nil, "Don't supply --rc flag when using rcd")
|
|
}
|
|
|
|
// Start the rc
|
|
rc.Opt.Enabled = true
|
|
if len(args) > 0 {
|
|
rc.Opt.Files = args[0]
|
|
}
|
|
|
|
s, err := rcserver.Start(context.Background(), &rc.Opt)
|
|
if err != nil {
|
|
fs.Fatalf(nil, "Failed to start remote control: %v", err)
|
|
}
|
|
if s == nil {
|
|
fs.Fatal(nil, "rc server not configured")
|
|
}
|
|
|
|
// Notify stopping on exit
|
|
defer systemd.Notify()()
|
|
|
|
s.Wait()
|
|
},
|
|
}
|