跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

copy.go

108 行 · 2.7 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package main
5
6import (
7 "github.com/sirupsen/logrus"
8 "github.com/spf13/cobra"
9
10 "github.com/lima-vm/lima/v2/pkg/copytool"
11)
12
13const copyHelp = `Copy files between host and guest
14
15Prefix guest filenames with the instance name and a colon.
16
17Backends:
18 auto - Automatically selects the best available backend (rsync preferred, falls back to scp)
19 rsync - Uses rsync for faster transfers with resume capability (requires rsync on both host and guest)
20 scp - Uses scp for reliable transfers (always available)
21
22Not to be confused with 'limactl clone'.
23`
24
25const copyExample = `
26 # Copy file from guest to host (auto backend)
27 limactl copy default:/etc/os-release .
28
29 # Copy file from host to guest with verbose output
30 limactl copy -v myfile.txt default:/tmp/
31
32 # Copy directory recursively using rsync backend
33 limactl copy --backend=rsync -r ./mydir default:/tmp/
34
35 # Copy using scp backend specifically
36 limactl copy --backend=scp default:/var/log/app.log ./logs/
37
38 # Copy multiple files
39 limactl copy file1.txt file2.txt default:/tmp/
40`
41
42func newCopyCommand() *cobra.Command {
43 copyCommand := &cobra.Command{
44 Use: "copy SOURCE ... TARGET",
45 Aliases: []string{"cp"},
46 Short: "Copy files between host and guest",
47 Long: copyHelp,
48 Example: copyExample,
49 Args: WrapArgsError(cobra.MinimumNArgs(2)),
50 RunE: copyAction,
51 GroupID: advancedCommand,
52 }
53
54 copyCommand.Flags().BoolP("recursive", "r", false, "Copy directories recursively")
55 copyCommand.Flags().BoolP("verbose", "v", false, "Enable verbose output")
56 copyCommand.Flags().String("backend", "auto", "Copy backend (scp|rsync|auto)")
57
58 return copyCommand
59}
60
61func copyAction(cmd *cobra.Command, args []string) error {
62 ctx := cmd.Context()
63 recursive, err := cmd.Flags().GetBool("recursive")
64 if err != nil {
65 return err
66 }
67
68 verbose, err := cmd.Flags().GetBool("verbose")
69 if err != nil {
70 return err
71 }
72
73 debug, err := cmd.Flags().GetBool("debug")
74 if err != nil {
75 return err
76 }
77
78 if debug {
79 verbose = true
80 }
81
82 backend, err := cmd.Flags().GetString("backend")
83 if err != nil {
84 return err
85 }
86
87 cpTool, err := copytool.New(ctx, backend, args, &copytool.Options{
88 Recursive: recursive,
89 Verbose: verbose,
90 })
91 if err != nil {
92 return err
93 }
94 logrus.Debugf("using copy tool %#q", cpTool.Name())
95
96 copyCmd, err := cpTool.Command(ctx, args, nil)
97 if err != nil {
98 return err
99 }
100
101 copyCmd.Stdin = cmd.InOrStdin()
102 copyCmd.Stdout = cmd.OutOrStdout()
103 copyCmd.Stderr = cmd.ErrOrStderr()
104 logrus.Debugf("executing %v (may take a long time)", copyCmd)
105
106 // TODO: use syscall.Exec directly (results in losing tty?)
107 return copyCmd.Run()
108}