-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull.go
More file actions
63 lines (55 loc) · 1.44 KB
/
pull.go
File metadata and controls
63 lines (55 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cli
import (
"context"
"fmt"
"io"
"os"
"github.com/spf13/cobra"
"codebox/internal/app"
)
type pullOpts struct {
commonOpts
instancePath string
localPath string
}
func newPullCmd() *cobra.Command {
var opts pullOpts
cmd := &cobra.Command{
Use: "pull INSTANCE",
Short: "Copy files from a sandbox instance to the local machine",
Long: "Copy a file or directory from a sandbox instance down to the local machine.",
Args: cobra.ExactArgs(1),
ValidArgsFunction: completeInstances,
RunE: func(cmd *cobra.Command, args []string) error {
opts.commonOpts = readCommonOpts(cmd)
return runPull(cmd.Context(),
cmd.OutOrStdout(), cmd.ErrOrStderr(), args[0], opts)
},
}
f := cmd.Flags()
f.SortFlags = false
f.StringVar(&opts.instancePath, "instance-path", "",
"File or directory on the instance to copy from")
f.StringVar(&opts.localPath, "local-path", "",
"Local directory to copy into")
return cmd
}
func runPull(
ctx context.Context,
stdout, stderr io.Writer,
instance string,
opts pullOpts,
) error {
home, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("locate home directory: %w", err)
}
return app.New(home).Pull(ctx, stdout, stderr, app.PullRequest{
Instance: instance,
Orchestrator: opts.orchestrator,
Remote: opts.remote,
InstanceKey: opts.instanceKey,
InstancePath: opts.instancePath,
LocalPath: opts.localPath,
})
}