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

Help and Exit

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 REPL
  • exit: exits the program

Assignment

func commandExit() error

This function should print Closing the Pokedex... Goodbye! then immediately exit the program. I used os.Exit(0).

type cliCommand struct {
	name        string
	description string
	callback    func() error
}

Then I created a map of supported commands:

map[string]cliCommand{
    "exit": {
        name:        "exit",
        description: "Exit the Pokedex",
        callback:    commandExit,
    },
}
Welcome to the Pokedex!
Usage:

help: Displays a help message
exit: Exit the Pokedex

You can dynamically 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.

Run and submit the CLI tests from the root of the repo.