diff --git a/examples/data/tweet.json b/examples/data/tweet.json new file mode 100644 index 00000000..f18cf47d --- /dev/null +++ b/examples/data/tweet.json @@ -0,0 +1 @@ +{"event": "tweet", "username": "floydophone", "text": "hello world!"} \ No newline at end of file diff --git a/examples/extract.sqrl b/examples/extract.sqrl new file mode 100644 index 00000000..edd9b2ee --- /dev/null +++ b/examples/extract.sqrl @@ -0,0 +1,4 @@ +LET EventData := input(); +LET EventType := jsonValue(EventData, "$.event"); +LET Username := jsonValue(EventData, "$.username"); +LET Text := jsonValue(EventData, "$.text"); \ No newline at end of file diff --git a/packages/sqrl-cli/__tests__/cli/run.spec.ts b/packages/sqrl-cli/__tests__/cli/run.spec.ts index fd3e0f34..64bb848b 100644 --- a/packages/sqrl-cli/__tests__/cli/run.spec.ts +++ b/packages/sqrl-cli/__tests__/cli/run.spec.ts @@ -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( diff --git a/packages/sqrl-cli/src/cli/readJsonFile.ts b/packages/sqrl-cli/src/cli/readJsonFile.ts index 6a384514..437cdc6b 100644 --- a/packages/sqrl-cli/src/cli/readJsonFile.ts +++ b/packages/sqrl-cli/src/cli/readJsonFile.ts @@ -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);