Introduce TermOperator helper and refactor execute()s to use replaceSubjectMatchingTerm
This commit is contained in:
@@ -28,13 +28,10 @@ export class Line extends Command<LineData> {
|
||||
|
||||
execute(vm: StrVM, data: LineData): Awaitable<StrVM> {
|
||||
// `line <cmd>` is equivalent to `lines` -> `each <cmd>` -> `join`, so just do that
|
||||
return vm.tapInPlace(ctx =>
|
||||
ctx.replaceSubject(async sub =>
|
||||
vm.runInChild(async (child, ctx) => {
|
||||
await (new Lines).execute(child, {})
|
||||
await (new Each).execute(child, { exec: data.exec })
|
||||
await (new Join).execute(child, {})
|
||||
return ctx.getSubject()
|
||||
})))
|
||||
return vm.replaceContextFromChild(async child => {
|
||||
await (new Lines).execute(child)
|
||||
await (new Each).execute(child, { exec: data.exec })
|
||||
await (new Join).execute(child, {})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user