...

/

Initializing the CLI with Cobra

Initializing the CLI with Cobra

Learn how to handle command-line parameters and configuration files by using Cobra.

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 ...