Skip to content

Commit

Permalink
cmd/rc: add --unix-socket option
Browse files Browse the repository at this point in the history
This adds an additional StringVarP for unix-socket, and in case it's not
an empty string, uses fshttp.NewClientWithUnixSocket instead of
fshttp.NewClient.
  • Loading branch information
flokli committed Aug 14, 2024
1 parent 9cb774e commit 56d37bc
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions cmd/rc/rc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ import (
)

var (
noOutput = false
url = "http://localhost:5572/"
jsonInput = ""
authUser = ""
authPass = ""
loopback = false
options []string
arguments []string
noOutput = false
url = "http://localhost:5572/"
unixSocket = ""
jsonInput = ""
authUser = ""
authPass = ""
loopback = false
options []string
arguments []string
)

func init() {
cmd.Root.AddCommand(commandDefinition)
cmdFlags := commandDefinition.Flags()
flags.BoolVarP(cmdFlags, &noOutput, "no-output", "", noOutput, "If set, don't output the JSON result", "")
flags.StringVarP(cmdFlags, &url, "url", "", url, "URL to connect to rclone remote control", "")
flags.StringVarP(cmdFlags, &unixSocket, "unix-socket", "", unixSocket, "Path to a unix domain socket to dial to, instead of opening a TCP connection directly", "")
flags.StringVarP(cmdFlags, &jsonInput, "json", "", jsonInput, "Input JSON - use instead of key=value args", "")
flags.StringVarP(cmdFlags, &authUser, "user", "", "", "Username to use to rclone remote control", "")
flags.StringVarP(cmdFlags, &authPass, "pass", "", "", "Password to use to connect to rclone remote control", "")
Expand Down Expand Up @@ -201,7 +203,12 @@ func doCall(ctx context.Context, path string, in rc.Params) (out rc.Params, err
}

// Do HTTP request
client := fshttp.NewClient(ctx)
var client *http.Client
if unixSocket == "" {
client = fshttp.NewClient(ctx)
} else {
client = fshttp.NewClientWithUnixSocket(ctx, unixSocket)
}
url += path
data, err := json.Marshal(in)
if err != nil {
Expand Down

0 comments on commit 56d37bc

Please sign in to comment.