mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 07:29:35 +01:00
rc: add --loopback flag to run commands directly without a server
This commit is contained in:
parent
1aa65d60e1
commit
bd10344d65
17
cmd/rc/rc.go
17
cmd/rc/rc.go
@ -24,6 +24,7 @@ var (
|
||||
jsonInput = ""
|
||||
authUser = ""
|
||||
authPass = ""
|
||||
loopback = false
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -33,6 +34,7 @@ func init() {
|
||||
commandDefintion.Flags().StringVarP(&jsonInput, "json", "", jsonInput, "Input JSON - use instead of key=value args.")
|
||||
commandDefintion.Flags().StringVarP(&authUser, "user", "", "", "Username to use to rclone remote control.")
|
||||
commandDefintion.Flags().StringVarP(&authPass, "pass", "", "", "Password to use to connect to rclone remote control.")
|
||||
commandDefintion.Flags().BoolVarP(&loopback, "loopback", "", false, "If set connect to this rclone instance not via HTTP.")
|
||||
}
|
||||
|
||||
var commandDefintion = &cobra.Command{
|
||||
@ -58,6 +60,12 @@ The --json parameter can be used to pass in a JSON blob as an input
|
||||
instead of key=value arguments. This is the only way of passing in
|
||||
more complicated values.
|
||||
|
||||
Use --loopback to connect to the rclone instance running "rclone rc".
|
||||
This is very useful for testing commands without having to run an
|
||||
rclone rc server, eg:
|
||||
|
||||
rclone rc --loopback operations/about fs=/
|
||||
|
||||
Use "rclone rc" to see a list of all possible commands.`,
|
||||
Run: func(command *cobra.Command, args []string) {
|
||||
cmd.CheckArgs(0, 1E9, command, args)
|
||||
@ -102,6 +110,15 @@ func setAlternateFlag(flagName string, output *string) {
|
||||
//
|
||||
// if err is set, out may be a valid error return or it may be nil
|
||||
func doCall(path string, in rc.Params) (out rc.Params, err error) {
|
||||
// If loopback set, short circuit HTTP request
|
||||
if loopback {
|
||||
call := rc.Calls.Get(path)
|
||||
if call == nil {
|
||||
return nil, errors.Errorf("method %q not found", path)
|
||||
}
|
||||
return call.Fn(in)
|
||||
}
|
||||
|
||||
// Do HTTP request
|
||||
client := fshttp.NewClient(fs.Config)
|
||||
url += path
|
||||
|
Loading…
Reference in New Issue
Block a user