Search⌘ K

Refactoring Multi-git to use Viper

Explore how to refactor the multi-git program to incorporate Viper alongside Cobra for advanced configuration management. Understand binding command-line flags to Viper to centralize settings, enable configuration files, and support multiple project repos more efficiently.

In this lesson, we will refactor the multi-git program to use Viper in addition to Cobra. Along the way, we will change some design choices regarding configuration and consider alternative forms of configuration. At the end of the day, incorporating Viper is a relatively simple and streamlined process that brings a lot of value and flexibility to multi-git.

Overview

Let’s rethink the configuration of multi-git and use our new shiny toy Viper to make it better. We will look at binding the Cobra command lines into Viper in addition to adding a configuration file. However, it’s also important to consider backwards compatibility when making changes that can potentially break a user’s code or even habits.

Re-designing the multi-git user experience

As you recall multi-git operates on a root directory and set of repos and executes a set of identical git commands on all the repos.

The use case is a set of related git repos where you often need to make changes across the same repos. With multi-git, you can create a branch across all the repos, make changes, commit ...