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

Method SetVarCommand

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

Source from the content-addressed store, hash-verified

1390}
1391
1392func (ws *WshServer) SetVarCommand(ctx context.Context, data wshrpc.CommandVarData) error {
1393 _, fileData, err := filestore.WFS.ReadFile(ctx, data.ZoneId, data.FileName)
1394 if err == fs.ErrNotExist {
1395 fileData = []byte{}
1396 err = filestore.WFS.MakeFile(ctx, data.ZoneId, data.FileName, nil, wshrpc.FileOpts{})
1397 if err != nil {
1398 return fmt.Errorf("error creating blockfile: %w", err)
1399 }
1400 } else if err != nil {
1401 return fmt.Errorf("error reading blockfile: %w", err)
1402 }
1403 envMap := envutil.EnvToMap(string(fileData))
1404 if data.Remove {
1405 delete(envMap, data.Key)
1406 } else {
1407 envMap[data.Key] = data.Val
1408 }
1409 envStr := envutil.MapToEnv(envMap)
1410 return filestore.WFS.WriteFile(ctx, data.ZoneId, data.FileName, []byte(envStr))
1411}
1412
1413func (ws *WshServer) PathCommand(ctx context.Context, data wshrpc.PathCommandData) (string, error) {
1414 pathType := data.PathType

Callers

nothing calls this directly

Calls 5

EnvToMapFunction · 0.92
MapToEnvFunction · 0.92
ReadFileMethod · 0.80
MakeFileMethod · 0.80
WriteFileMethod · 0.80

Tested by

no test coverage detected