Skip to content

Instantly share code, notes, and snippets.

@garrettjoecox
Created December 18, 2023 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garrettjoecox/e0977e8e067ba907eb7bb5105e92b724 to your computer and use it in GitHub Desktop.
Save garrettjoecox/e0977e8e067ba907eb7bb5105e92b724 to your computer and use it in GitHub Desktop.
readLines usage
import { readLines } from "https://deno.land/std@0.208.0/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