From aec5a646c9218a0a0da62cbcd1f28bc23c242540 Mon Sep 17 00:00:00 2001 From: Andy Hayden Date: Sun, 27 Oct 2019 06:04:42 -0700 Subject: feat: top-level-for-await (#3212) --- std/examples/catj.ts | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'std/examples/catj.ts') diff --git a/std/examples/catj.ts b/std/examples/catj.ts index cbe06d4b8..87fd6a964 100644 --- a/std/examples/catj.ts +++ b/std/examples/catj.ts @@ -79,32 +79,28 @@ function print(data: any): void { } } -async function main(): Promise { - const parsedArgs = parse(Deno.args.slice(1)); - - if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) { - console.log("Usage: catj [-h|--help] [file...]"); - console.log(); - console.log("Examples:"); - console.log(); - console.log("// print file:\n catj file.json"); - console.log(); - console.log("// print multiple files:\n catj file1.json file2.json"); - console.log(); - console.log("// print from stdin:\n cat file.json | catj -"); - } +const parsedArgs = parse(Deno.args.slice(1)); + +if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) { + console.log("Usage: catj [-h|--help] [file...]"); + console.log(); + console.log("Examples:"); + console.log(); + console.log("// print file:\n catj file.json"); + console.log(); + console.log("// print multiple files:\n catj file1.json file2.json"); + console.log(); + console.log("// print from stdin:\n cat file.json | catj -"); +} - if (parsedArgs._[0] === "-") { - const contents = await Deno.readAll(Deno.stdin); - const json = JSON.parse(decoder.decode(contents)); +if (parsedArgs._[0] === "-") { + const contents = await Deno.readAll(Deno.stdin); + const json = JSON.parse(decoder.decode(contents)); + print(json); +} else { + for (const fileName of parsedArgs._) { + const fileContents = await Deno.readFile(fileName); + const json = JSON.parse(decoder.decode(fileContents)); print(json); - } else { - for (const fileName of parsedArgs._) { - const fileContents = await Deno.readFile(fileName); - const json = JSON.parse(decoder.decode(fileContents)); - print(json); - } } } - -main(); -- cgit v1.2.3