MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / getVarRun

Function getVarRun

cmd/wsh/cmd/wshcmd-getvar.go:54–108  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

52}
53
54func getVarRun(cmd *cobra.Command, args []string) error {
55 defer func() {
56 sendActivity("getvar", WshExitCode == 0)
57 }()
58
59 // Resolve block to get zoneId
60 if blockArg == "" {
61 if getVarLocal {
62 blockArg = "this"
63 } else {
64 blockArg = "client"
65 }
66 }
67 fullORef, err := resolveBlockArg()
68 if err != nil {
69 return err
70 }
71
72 if getVarAllVars {
73 if len(args) > 0 {
74 return fmt.Errorf("cannot specify key with --all")
75 }
76 return getAllVariables(fullORef.OID)
77 }
78
79 // Single variable case - existing logic
80 if len(args) != 1 {
81 OutputHelpMessage(cmd)
82 return fmt.Errorf("requires a key argument")
83 }
84
85 key := args[0]
86 commandData := wshrpc.CommandVarData{
87 Key: key,
88 ZoneId: fullORef.OID,
89 FileName: getVarFileName,
90 }
91
92 resp, err := wshclient.GetVarCommand(RpcClient, commandData, &wshrpc.RpcOpts{Timeout: 2000})
93 if err != nil {
94 return fmt.Errorf("getting variable: %w", err)
95 }
96
97 if !resp.Exists {
98 WshExitCode = 1
99 return nil
100 }
101
102 WriteStdout("%s", resp.Val)
103 if shouldPrintNewline() {
104 WriteStdout("\n")
105 }
106
107 return nil
108}
109
110func getAllVariables(zoneId string) error {
111 commandData := wshrpc.CommandVarData{

Callers

nothing calls this directly

Calls 7

GetVarCommandFunction · 0.92
sendActivityFunction · 0.85
resolveBlockArgFunction · 0.85
getAllVariablesFunction · 0.85
OutputHelpMessageFunction · 0.85
WriteStdoutFunction · 0.85
shouldPrintNewlineFunction · 0.85

Tested by

no test coverage detected