Skip to content

Commit 75c42cc

Browse files
committed
Add -s seek option
1 parent 1bc1869 commit 75c42cc

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "basho-eval",
3-
"version": "0.0.13",
3+
"version": "0.0.14",
44
"author": "Isotropy Team<[email protected]>",
55
"contributors": [
66
"Jeswin Kumar<[email protected]>"

src/basho-eval.ts

+30-10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const options = [
2323
"-q", // quote expression as string
2424
"-p", // print
2525
"-r", // reduce
26+
"-s", // seek/recall a named result
2627
"-t", // terminate evaluation
2728
"-w", // Same as log, but without the newline
2829
"--error", // Error handling
@@ -431,16 +432,16 @@ async function evaluateInternal(
431432
async () =>
432433
await evalShorthand(
433434
args.slice(2),
434-
input.map(
435-
x =>
436-
new PipelineValue(
437-
args[1].split(",").map(name => {
438-
const item = findNamedValue(name, x);
439-
return item instanceof PipelineValue ? item.value : item;
440-
}),
441-
x
442-
)
443-
),
435+
input.map(x => {
436+
const streams = args[1].split(",");
437+
return new PipelineValue(
438+
streams.map(name => {
439+
const item = findNamedValue(name, x);
440+
return item instanceof PipelineValue ? item.value : item;
441+
}),
442+
x
443+
);
444+
}),
444445
false
445446
)
446447
],
@@ -606,6 +607,25 @@ async function evaluateInternal(
606607
}
607608
],
608609

610+
/* Seek a named result */
611+
[
612+
x => x === "-s",
613+
async () =>
614+
await evalShorthand(
615+
args.slice(2),
616+
input.map(x => {
617+
return new PipelineValue(
618+
(() => {
619+
const item = findNamedValue(args[1], x);
620+
return item instanceof PipelineValue ? item.value : item;
621+
})(),
622+
x
623+
);
624+
}),
625+
false
626+
)
627+
],
628+
609629
/* Terminate the pipeline */
610630
[
611631
x => x === "-t",

src/test/test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,26 @@ describe("basho", () => {
381381
});
382382
});
383383

384+
it(`Seek a named result`, async () => {
385+
const output = await evaluate([
386+
"[10,20,30,40]",
387+
"-j",
388+
"x+1",
389+
"-n",
390+
"add1",
391+
"-j",
392+
"x+2",
393+
"-n",
394+
"add2",
395+
"-s",
396+
"add1"
397+
]);
398+
(await toResult(output)).should.deepEqual({
399+
mustPrint: true,
400+
result: [11, 21, 31, 41]
401+
});
402+
});
403+
384404
it(`Captures an error`, async () => {
385405
const output = await evaluate([
386406
"['a,b', 10, 'c,d']",

0 commit comments

Comments
 (0)