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 configgator register - adds a new user to the databasegator users - lists all the users in the databaseWe'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.
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.
The Boot.dev CLI requires you to be signed in to submit your solution!
Copy/paste one of the following commands into your terminal:
Run
bootdev run dca1352a-7600-4d1d-bfdf-f9d741282e55
Submit
bootdev run dca1352a-7600-4d1d-bfdf-f9d741282e55 -s
Run the CLI commands to test your solution.
Login to view solution
Using the Bootdev CLI
The Bootdev CLI is the only way to submit your solution for this type of lesson. We need to be able to run commands in your environment to verify your solution.
You can install it here. It's a Go program hosted on GitHub, so you'll need Go installed as well. Instructions are on the GitHub page.