We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

State

As we add more commands, the statefulness of our program is going to increase. We're going to shove all that state into a State object. There are a few goals for this object:

  • Give each command handler to the commands registry (looking at you help command)
  • Give the commands access to the readline interface created with createInterface so that the exit command can clean up after itself

In the future there will be even more shared state, and we want a simple function signature that all the callbacks can conform to, namely:

callback: (state: State) => void;

Assignment

import { createInterface, type Interface } from "readline";

Now that we've done all this... nothing's changed! Our code should still work the exact same way. Womp womp. Welcome to refactoring! Refactoring is actually a super important skill that you'll spend a lot of time doing as a developer. It's all about updating the structure (but not behavior) of your code to make it easier to read, maintain, and extend.

Run and submit the CLI tests.