Initializing the CLI with Cobra
Explore how to initialize a command-line interface application using the Cobra framework in Go. Learn to handle command-line parameters, bind configuration options, and build an interactive Pomodoro timer app with customizable intervals and test it through the terminal.
We'll cover the following...
Now that the interface and the back-end code are ready, we need a way to launch our application. We’ll use the Cobra framework again to have a standard way to handle command-line parameters and configuration files.
Switch back to our application’s root directory and use the Cobra framework generator.
To start this application, we’ll need the instance of pomodoro.IntervalConfig, which
is required to create an instance of our app.App type. To create a new configuration, we also need an instance of pomodoro.Repository. To make this application extensive, let’s create a getRepo() function to get the repository. Later, we can implement different versions of this function to obtain different repositories.
Updating the repoinmemory.go file
Then we create and open the file repoinmemory.go. We add the package definition and import section; we’ll use our pomodoro ...