feat: top-level-for-await (#3212)

This commit is contained in:
Andy Hayden 2019-10-27 06:04:42 -07:00 committed by Ry Dahl
parent 51dd91a3cc
commit aec5a646c9
18 changed files with 257 additions and 263 deletions

View file

@ -79,32 +79,28 @@ function print(data: any): void {
}
}
async function main(): Promise<void> {
const parsedArgs = parse(Deno.args.slice(1));
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));
print(json);
} else {
for (const fileName of parsedArgs._) {
const fileContents = await Deno.readFile(fileName);
const json = JSON.parse(decoder.decode(fileContents));
print(json);
}
}
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 -");
}
main();
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);
}
}