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

Function ApplyCommand

pkg/ijson/ijson.go:597–615  ·  view source on GitHub ↗
(data any, command Command, budget int)

Source from the content-addressed store, hash-verified

595}
596
597func ApplyCommand(data any, command Command, budget int) (any, error) {
598 commandType := getCommandType(command)
599 if commandType == "" {
600 return nil, fmt.Errorf("ApplyCommand: missing type field")
601 }
602 switch commandType {
603 case SetCommandStr:
604 path := getCommandPath(command)
605 return SetPath(data, path, command["data"], &SetPathOpts{Budget: budget})
606 case DelCommandStr:
607 path := getCommandPath(command)
608 return SetPath(data, path, nil, &SetPathOpts{Remove: true, Budget: budget})
609 case AppendCommandStr:
610 path := getCommandPath(command)
611 return SetPath(data, path, command["data"], &SetPathOpts{CombineFn: CombineFn_ArrayAppend, Budget: budget})
612 default:
613 return nil, fmt.Errorf("ApplyCommand: unknown command type %q", commandType)
614 }
615}
616
617func ApplyCommands(data any, commands []Command, budget int) (any, error) {
618 for _, command := range commands {

Callers 2

ApplyCommandsFunction · 0.85
CompactIJsonFunction · 0.85

Calls 3

getCommandTypeFunction · 0.85
SetPathFunction · 0.85
getCommandPathFunction · 0.70

Tested by

no test coverage detected