跳到主要内容

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

浏览文件

info.go

57 行 · 1.3 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package main
5
6import (
7 "encoding/json"
8 "fmt"
9
10 "github.com/mikefarah/yq/v4/pkg/yqlib"
11 "github.com/spf13/cobra"
12
13 "github.com/lima-vm/lima/v2/pkg/limainfo"
14 "github.com/lima-vm/lima/v2/pkg/uiutil"
15 "github.com/lima-vm/lima/v2/pkg/yqutil"
16)
17
18func newInfoCommand() *cobra.Command {
19 infoCommand := &cobra.Command{
20 Use: "info",
21 Short: "Show diagnostic information",
22 Args: WrapArgsError(cobra.NoArgs),
23 RunE: infoAction,
24 GroupID: advancedCommand,
25 }
26 infoCommand.Flags().String("yq", ".", "Apply yq expression to output")
27
28 return infoCommand
29}
30
31func infoAction(cmd *cobra.Command, _ []string) error {
32 ctx := cmd.Context()
33
34 yq, err := cmd.Flags().GetString("yq")
35 if err != nil {
36 return err
37 }
38
39 info, err := limainfo.New(ctx)
40 if err != nil {
41 return err
42 }
43 j, err := json.MarshalIndent(info, "", " ")
44 if err != nil {
45 return err
46 }
47
48 encoderPrefs := yqlib.ConfiguredJSONPreferences.Copy()
49 encoderPrefs.Indent = 4
50 encoderPrefs.ColorsEnabled = uiutil.OutputIsTTY(cmd.OutOrStdout())
51 encoder := yqlib.NewJSONEncoder(encoderPrefs)
52 str, err := yqutil.EvaluateExpressionWithEncoder(yq, string(j), encoder)
53 if err == nil {
54 _, err = fmt.Fprint(cmd.OutOrStdout(), str)
55 }
56 return err
57}