跳到主要内容

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

浏览文件

autostart_others.go

72 行 · 1.8 KB历史下载
1//go:build !darwin
2
3// SPDX-FileCopyrightText: Copyright The Lima Authors
4// SPDX-License-Identifier: Apache-2.0
5
6package main
7
8import (
9 "errors"
10 "fmt"
11 "os"
12
13 "github.com/sirupsen/logrus"
14 "github.com/spf13/cobra"
15
16 "github.com/lima-vm/lima/v2/pkg/autostart"
17 "github.com/lima-vm/lima/v2/pkg/store"
18)
19
20func autostartEnableAction(cmd *cobra.Command, args []string) error {
21 condition, err := cmd.Flags().GetString("condition")
22 if err != nil {
23 return err
24 }
25 if condition == "boot" {
26 return errors.New("--condition=boot is only supported on macOS")
27 }
28
29 ctx := cmd.Context()
30 inst, err := store.Inspect(ctx, args[0])
31 if err != nil {
32 if errors.Is(err, os.ErrNotExist) {
33 return fmt.Errorf("instance %q not found", args[0])
34 }
35 return err
36 }
37
38 keepAlive, err := cmd.Flags().GetBool("keep-alive")
39 if err != nil {
40 return err
41 }
42 mgr := autostart.ManagerWith(keepAlive)
43 if err := mgr.RegisterToStartAtLogin(ctx, inst); err != nil {
44 return fmt.Errorf("failed to register instance %#q to start at login: %w", inst.Name, err)
45 }
46 logrus.Infof("Instance %#q registered to start at login", inst.Name)
47 return nil
48}
49
50func autostartDisableAction(cmd *cobra.Command, args []string) error {
51 ctx := cmd.Context()
52 inst, err := store.Inspect(ctx, args[0])
53 if err != nil {
54 if errors.Is(err, os.ErrNotExist) {
55 return fmt.Errorf("instance %q not found", args[0])
56 }
57 return err
58 }
59
60 if registered, err := autostart.IsRegistered(ctx, inst); err != nil {
61 return err
62 } else if !registered {
63 logrus.Infof("Instance %#q is not registered for automatic startup", inst.Name)
64 return nil
65 }
66
67 if err := autostart.UnregisterFromStartAtLogin(ctx, inst); err != nil {
68 return fmt.Errorf("failed to unregister instance %#q from start at login: %w", inst.Name, err)
69 }
70 logrus.Infof("Instance %#q unregistered from start at login", inst.Name)
71 return nil
72}