跳到主要内容

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

浏览文件

unprotect.go

52 行 · 1.4 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 newUnprotectCommand() *cobra.Command {
17 unprotectCommand := &cobra.Command{
18 Use: "unprotect INSTANCE [INSTANCE, ...]",
19 Short: "Unprotect an instance",
20 Args: WrapArgsError(cobra.MinimumNArgs(1)),
21 RunE: unprotectAction,
22 ValidArgsFunction: unprotectBashComplete,
23 GroupID: advancedCommand,
24 }
25 return unprotectCommand
26}
27
28func unprotectAction(cmd *cobra.Command, args []string) error {
29 ctx := cmd.Context()
30 var errs []error
31 for _, instName := range args {
32 inst, err := store.Inspect(ctx, instName)
33 if err != nil {
34 errs = append(errs, fmt.Errorf("failed to inspect instance %#q: %w", instName, err))
35 continue
36 }
37 if !inst.Protected {
38 logrus.Warnf("Instance %#q isn't protected. Skipping.", instName)
39 continue
40 }
41 if err := inst.Unprotect(); err != nil {
42 errs = append(errs, fmt.Errorf("failed to unprotect instance %#q: %w", instName, err))
43 continue
44 }
45 logrus.Infof("Unprotected %#q", instName)
46 }
47 return errors.Join(errs...)
48}
49
50func unprotectBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
51 return bashCompleteInstanceNames(cmd)
52}