Two commonly used Go libraries, spf13/cobra and spf13/viper, are used for configuration programming. Together, these two libraries can be used to create CLI binaries that have many configurable options. Cobra allows you to generate applications and command files, while Viper helps to read and maintain complete configuration solutions for 12-factor Go applications. Cobra and Viper are used in some of the most commonly used Go projects, including Kubernetes and Docker.
To use these two libraries together to make a cmd library, we need to make sure we nest our project directory, as follows:
Once we have created our nested directory structure, we can start setting up our main program. In our main.go file, we have defined our date command—the main.go function for Cobra and Viper us deliberately simple so that we can...