Created
December 18, 2023 00:50
-
-
Save garrettjoecox/e0977e8e067ba907eb7bb5105e92b724 to your computer and use it in GitHub Desktop.
readLines usage
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
import { readLines } from "https://deno.land/[email protected]/io/read_lines.ts"; | |
(async function processStdin() { | |
try { | |
for await (const line of readLines(Deno.stdin)) { | |
const [command, ...args] = line.split(" "); | |
switch (command) { | |
default: | |
case "help": { | |
console.log( | |
`Available commands: | |
help: Show this help message | |
stop: Stop the server`, | |
); | |
break; | |
} | |
case "stop": { | |
Deno.exit(); | |
break; | |
} | |
} | |
} | |
} catch (error) { | |
console.error("Error reading from stdin: ", error.message); | |
processStdin(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment