MCPcopy
hub / github.com/wavetermdev/waveterm / GetAllVarsCommand

Method GetAllVarsCommand

pkg/wshrpc/wshserver/wshserver.go:1367–1390  ·  view source on GitHub ↗
(ctx context.Context, data wshrpc.CommandVarData)

Source from the content-addressed store, hash-verified

1365}
1366
1367func (ws *WshServer) GetAllVarsCommand(ctx context.Context, data wshrpc.CommandVarData) ([]wshrpc.CommandVarResponseData, error) {
1368 _, fileData, err := filestore.WFS.ReadFile(ctx, data.ZoneId, data.FileName)
1369 if err == fs.ErrNotExist {
1370 return []wshrpc.CommandVarResponseData{}, nil
1371 }
1372 if err != nil {
1373 return nil, fmt.Errorf("error reading blockfile: %w", err)
1374 }
1375 envMap := envutil.EnvToMap(string(fileData))
1376 keys := make([]string, 0, len(envMap))
1377 for k := range envMap {
1378 keys = append(keys, k)
1379 }
1380 sort.Strings(keys)
1381 result := make([]wshrpc.CommandVarResponseData, 0, len(keys))
1382 for _, k := range keys {
1383 result = append(result, wshrpc.CommandVarResponseData{
1384 Key: k,
1385 Val: envMap[k],
1386 Exists: true,
1387 })
1388 }
1389 return result, nil
1390}
1391
1392func (ws *WshServer) SetVarCommand(ctx context.Context, data wshrpc.CommandVarData) error {
1393 _, fileData, err := filestore.WFS.ReadFile(ctx, data.ZoneId, data.FileName)

Callers

nothing calls this directly

Calls 2

EnvToMapFunction · 0.92
ReadFileMethod · 0.80

Tested by

no test coverage detected