Created
May 26, 2020 04:59
-
-
Save pchinjr/bb499cc2578f94016416af126cea35d9 to your computer and use it in GitHub Desktop.
deno 1.0 command line test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://www.youtube.com/watch?v=hVqNwrpCtm4 | |
import { parse } from "https://deno.land/std/flags/mod.ts"; | |
import { TextProtoReader } from "https://deno.land/std/textproto/mod.ts"; | |
import { BufReader } from "https://deno.land/std/io/bufio.ts"; | |
const parsedArgs = parse(Deno.args); | |
async function main() { | |
if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) { | |
console.log("try saying 'hi'"); | |
} else { | |
const tpr = new TextProtoReader(new BufReader(Deno.stdin)); | |
while (true) { | |
const te = new TextEncoder(); | |
await Deno.stdout.write(te.encode("> ")); | |
const line = await tpr.readLine(); | |
if (line === "hi") { | |
console.log("hi"); | |
} else if (line === "close") { | |
break; | |
} else { | |
console.log("I dont know what you are saying, try 'hi' again, or 'close'"); | |
} | |
} | |
} | |
await new Promise((resolve): number => setTimeout(resolve, 0)); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment