A REPL is only useful if it does something! Our REPL will work using the concept of "commands". A command is a single word that maps to an action.
We're going to support two commands in this step:
help: prints a help message describing how to use the REPLexit: exits the programexport function commandExit();
This function should print Closing the Pokedex... Goodbye! then immediately exit the program. I used process.exit(0) to exit the program.
export type CLICommand = {
name: string;
description: string;
callback: (commands: Record<string, CLICommand>) => void;
};
Then I created an object literal of supported commands:
export function getCommands(): Record<string, CLICommand> {
return {
exit: {
name: "exit",
description: "Exits the pokedex",
callback: commandExit,
},
// can add more commands here
};
}
Welcome to the Pokedex!
Usage:
help: Displays a help message
exit: Exit the Pokedex
Generate the "usage" section by iterating over my registry of commands. That way the help command will always be up-to-date with the available commands. I recommend:
command_exit.ts, command_help.ts)exit will ignore it) like this export function commandHelp(commands: Record<string, CLICommand>)CLICommand type in its own file (e.g. command.ts)import type { CLICommand } from "./command.js";Run and submit the CLI tests from the root of the repo.