MCPcopy Create free account
hub / github.com/coder/wush / rsyncCmd

Function rsyncCmd

cmd/wush/rsync.go:17–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func rsyncCmd() *serpent.Command {
18 var (
19 verbose bool
20 logger = new(slog.Logger)
21 logf = func(str string, args ...any) {}
22
23 overlayOpts = new(sendOverlayOpts)
24 )
25 return &serpent.Command{
26 Use: "rsync [flags] -- [rsync args]",
27 Short: "Transfer files with rsync to/from a wush server.",
28 Long: "Use " + cliui.Code("wush serve") + " on the computer you would like to transfer files to." +
29 "\n\n" +
30 formatExamples(
31 example{
32 Description: "Upload a local file",
33 Command: "wush rsync /local/path :/remote/path",
34 },
35 example{
36 Description: "Download a remote file",
37 Command: "wush rsync :/remote/path /local/path",
38 },
39 example{
40 Description: "Add rsync flags",
41 Command: "wush rsync /local/path :/remote/path -- --progress --stats -avz --human-readable",
42 },
43 ),
44 Middleware: serpent.Chain(
45 initLogger(&verbose, ptr.To(false), logger, &logf),
46 initAuth(&overlayOpts.authKey, &overlayOpts.clientAuth),
47 ),
48 Handler: func(inv *serpent.Invocation) error {
49 ctx := inv.Context()
50
51 dm, err := tsserver.DERPMapTailscale(inv.Context())
52 if err != nil {
53 return err
54 }
55 overlayOpts.clientAuth.PrintDebug(logf, dm)
56
57 progPath := os.Args[0]
58 args := []string{
59 "-c",
60 fmt.Sprintf(`rsync -e "%s ssh --auth-key %s --quiet --" %s`,
61 progPath, overlayOpts.clientAuth.AuthKey(), strings.Join(inv.Args, " "),
62 ),
63 }
64 fmt.Println("Running rsync", strings.Join(inv.Args, " "))
65 cmd := exec.CommandContext(ctx, "sh", args...)
66 cmd.Stdin = inv.Stdin
67 cmd.Stdout = inv.Stdout
68 cmd.Stderr = inv.Stderr
69
70 return cmd.Run()
71 },
72 Options: []serpent.Option{
73 {
74 Flag: "auth-key",

Callers 1

mainFunction · 0.85

Calls 8

CodeFunction · 0.92
DERPMapTailscaleFunction · 0.92
formatExamplesFunction · 0.85
initLoggerFunction · 0.85
initAuthFunction · 0.85
PrintDebugMethod · 0.80
AuthKeyMethod · 0.80
RunMethod · 0.80

Tested by

no test coverage detected