mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
feat: top-level-for-await (#3212)
This commit is contained in:
parent
51dd91a3cc
commit
aec5a646c9
18 changed files with 257 additions and 263 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue