跳到主要内容

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

浏览文件

protect.go

54 行 · 1.5 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package main
5
6import (
7 "errors"
8 "fmt"
9
10 "github.com/sirupsen/logrus"
11 "github.com/spf13/cobra"
12
13 "github.com/lima-vm/lima/v2/pkg/store"
14)
15
16func newProtectCommand() *cobra.Command {
17 protectCommand := &cobra.Command{
18 Use: "protect INSTANCE [INSTANCE, ...]",
19 Short: "Protect an instance to prohibit accidental removal",
20 Long: `Protect an instance to prohibit accidental removal via the 'limactl delete' command.
21The instance is not being protected against removal via '/bin/rm', Finder, etc.`,
22 Args: WrapArgsError(cobra.MinimumNArgs(1)),
23 RunE: protectAction,
24 ValidArgsFunction: protectBashComplete,
25 GroupID: advancedCommand,
26 }
27 return protectCommand
28}
29
30func protectAction(cmd *cobra.Command, args []string) error {
31 ctx := cmd.Context()
32 var errs []error
33 for _, instName := range args {
34 inst, err := store.Inspect(ctx, instName)
35 if err != nil {
36 errs = append(errs, fmt.Errorf("failed to inspect instance %#q: %w", instName, err))
37 continue
38 }
39 if inst.Protected {
40 logrus.Warnf("Instance %#q is already protected. Skipping.", instName)
41 continue
42 }
43 if err := inst.Protect(); err != nil {
44 errs = append(errs, fmt.Errorf("failed to protect instance %#q: %w", instName, err))
45 continue
46 }
47 logrus.Infof("Protected %#q", instName)
48 }
49 return errors.Join(errs...)
50}
51
52func protectBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
53 return bashCompleteInstanceNames(cmd)
54}