Gator is a CLI application, and like many CLI applications, it has a set of valid commands. For example:
gator login - sets the current user in the config
gator register - adds a new user to the database
gator users - lists all the users in the database
etc.
We'll be hand-rolling our CLI rather than using a framework like Cobra or Bubble Tea. This will give us a better understanding of how CLI applications work.
Assignment
Let's start with a simple login command. For now, all it will do is set the current user in the config file. Usage:
gator login <username>
We want to add many commands to our CLI, so let's build a flexible system that will allow us to register new commands easily.
func (c *commands) run(s *state, cmd command) error - This method runs a given command with the provided state if it exists.
func (c *commands) register(name string, f func(*state, command) error) - This method registers a new handler function for a command name.
If there are fewer than 2 arguments, print an error message to the terminal and exit. Why two? The first argument is automatically the program name, which we ignore, and we require a command name.
Run and submit the CLI tests from the root of your project.