fix(cmd): add flag first-win
This commit is contained in:
parent
2ea83b7591
commit
4ad9da6d63
13
cmd/root.go
13
cmd/root.go
@ -42,6 +42,7 @@ dcmerge docker-compose.yml https://git.example.local/user/repo/docker-compose.ym
|
||||
RunE: run,
|
||||
Version: version,
|
||||
}
|
||||
rootCmd.Flags().BoolP("first-win", "f", false, "Add only missing attributes")
|
||||
rootCmd.Flags().BoolP("last-win", "l", false, "Overwrite existing attributes")
|
||||
rootCmd.Flags().StringP("output-file", "o", "", "Write instead on stdout into a file")
|
||||
rootCmd.AddCommand(completionCmd)
|
||||
@ -50,6 +51,11 @@ dcmerge docker-compose.yml https://git.example.local/user/repo/docker-compose.ym
|
||||
}
|
||||
|
||||
func run(cmd *cobra.Command, args []string) error {
|
||||
mergeFirstWin, err := cmd.Flags().GetBool("first-win")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to parse flag last-win: %s", err)
|
||||
}
|
||||
|
||||
mergeLastWin, err := cmd.Flags().GetBool("last-win")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to parse flag last-win: %s", err)
|
||||
@ -69,12 +75,15 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
|
||||
for _, config := range dockerComposeConfigs {
|
||||
switch {
|
||||
case mergeLastWin:
|
||||
case mergeFirstWin && mergeLastWin:
|
||||
return fmt.Errorf("Neither --first-win or --last-win can be specified - not booth.")
|
||||
case mergeFirstWin && !mergeLastWin:
|
||||
dockerComposeConfig.MergeFirstWin(config)
|
||||
case !mergeFirstWin && mergeLastWin:
|
||||
dockerComposeConfig.MergeLastWin(config)
|
||||
default:
|
||||
dockerComposeConfig.Merge(config)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch {
|
||||
|
Loading…
Reference in New Issue
Block a user