stred

Stred: Streaming Tree Editor. Like sed but for JSON
git clone http://shtanton.xyz/git/repo/stred
Log | Files | Refs

commit 79ac135cee306cbcfa4b73f1b7c0b404712fee7b
parent 46720adb713a931447f4d899729b83b6171138db
Author: Charlie Stanton <charlie@shtanton.xyz>
Date:   Thu, 20 Apr 2023 14:48:50 +0100

Replaces the inflexible delete all with separate DeleteValue and DeletePath commands

Diffstat:
Mmain/command.go | 10+++++++---
Mmain/parse.go | 4+++-
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/main/command.go b/main/command.go @@ -43,12 +43,16 @@ func (cmd AppendNextCommand) exec(state *ProgramState) { state.path = nextItem.Path.ToWalkValues() } -type DeleteAllCommand struct {} -func (cmd DeleteAllCommand) exec(state *ProgramState) { - state.path = nil +type DeleteValueCommand struct {} +func (cmd DeleteValueCommand) exec(state *ProgramState) { state.value = nil } +type DeletePathCommand struct {} +func (cmd DeletePathCommand) exec(state *ProgramState) { + state.path = nil +} + func runSubex(state subex.SubexState, in []walk.WalkValue) (out []walk.WalkValue, error bool) { valueStream := make(chan walk.WalkValue) go func(in []walk.WalkValue, out chan<- walk.WalkValue) { diff --git a/main/parse.go b/main/parse.go @@ -63,7 +63,9 @@ func (p *parser) parseBasicCommand(commandChar rune) Command { case 'p': return PrintValueCommand{} case 'd': - return DeleteAllCommand{} + return DeleteValueCommand{} + case 'D': + return DeletePathCommand{} case 'n': return NextCommand{} case 'N':