Skip to content

Commit 4b85bb9

Browse files
committed
Updated with a simpler example!
Signed-off-by: hiren <20088337+hirenr@users.noreply.github.com>
1 parent fe19df8 commit 4b85bb9

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

examples/run-script-with-stdin-and-arguments.yaml

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,27 @@ document:
44
name: run-script-with-stdin-and-arguments
55
version: 1.0.0
66
do:
7-
- setInput:
8-
set:
9-
url: https://petstore.swagger.io/v2/pet/2
107
- runScript:
118
output:
129
as: "${ fromjson }"
1310
run:
1411
script:
1512
language: javascript
16-
stdin: ${ . }
13+
stdin: "Hello Workflow"
1714
environment:
18-
url: https://petstore.swagger.io/v2/pet/2
15+
foo: bar
1916
arguments:
20-
- https://petstore.swagger.io/v2/pet/2
17+
- hello
2118
code: |
2219
// Reading Input from STDIN
23-
const input = await new Promise((resolve) => {
24-
let data = '';
25-
process.stdin.setEncoding('utf8');
26-
process.stdin.on('data', chunk => data += chunk);
27-
process.stdin.on('end', () => {
28-
try {
29-
resolve(JSON.parse(data));
30-
} catch (error) {
31-
resolve({})
32-
}
33-
});
34-
});
35-
36-
const responseStdin = await fetch(input.url);
20+
import { readFileSync } from 'node:fs';
21+
const stdin = readFileSync(process.stdin.fd, 'utf8');
22+
console.log('stdin > ', stdin) // Output: stdin > Hello Workflow
3723
3824
// Reading from argv
39-
const [_, __, url] = process.argv;
40-
const responseArgv = await fetch(url);
25+
const [_, __, arg] = process.argv;
26+
console.log('arg > ', arg) // Output: arg > hello
4127
4228
// Reading from env
43-
const envUrl = process.env.url;
44-
const responseEnv = await fetch(envUrl);
45-
46-
console.log(JSON.stringify({responseStdin: responseStdin.data, responseArgv: responseArgv.data, responseEnv: responseEnv.data }))
29+
const foo = process.env.foo;
30+
console.log('env > ', foo) // Output: env > bar

0 commit comments

Comments
 (0)