Skip to content

Commit

Permalink
Fix sqrl-cli run with JSON file inputs (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
qix committed Nov 21, 2022
1 parent c6507d4 commit 37242e0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/data/tweet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"event": "tweet", "username": "floydophone", "text": "hello world!"}
4 changes: 4 additions & 0 deletions examples/extract.sqrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LET EventData := input();
LET EventType := jsonValue(EventData, "$.event");
LET Username := jsonValue(EventData, "$.username");
LET Text := jsonValue(EventData, "$.text");
15 changes: 15 additions & 0 deletions packages/sqrl-cli/__tests__/cli/run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ test("works", async () => {
);
});

test("works with file inputs", async () => {
const stdout = await runCli([
"run",
examplePath("extract.sqrl"),
"-s",
'EventData=@' + examplePath("data/tweet.json"),
"Text",
"Username",
]);

expect(stripAnsi(stdout).replace(/[0-9]/g, "x")).toEqual(
"✓ xxxx-xx-xx xx:xx action was allowed.\n" + 'Text="hello world!"\n' + 'Username="floydophone"\n'
);
});

test("does not work with set after text", async () => {
// @todo: it would be nice if this worked, but seems like a docopt bug
await expect(
Expand Down
2 changes: 1 addition & 1 deletion packages/sqrl-cli/src/cli/readJsonFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function readJsonFile(path: string) {
}
}

export async function readJsonFileSync(path: string) {
export function readJsonFileSync(path: string) {
let data: Buffer;
try {
data = readFileSync(path);
Expand Down

0 comments on commit 37242e0

Please sign in to comment.