Skip to content

Commit

Permalink
execute module replacement in a single command (#178)
Browse files Browse the repository at this point in the history
* execute module replacement in a single command

* remove empty line
  • Loading branch information
WeidiDeng authored Apr 6, 2024
1 parent dcaaa73 commit 743ce51
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,17 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) {
replaced := make(map[string]string)
for _, r := range b.Replacements {
log.Printf("[INFO] Replace %s => %s", r.Old.String(), r.New.String())
cmd := env.newGoModCommand(ctx, "edit",
"-replace", fmt.Sprintf("%s=%s", r.Old.Param(), r.New.Param()))
replaced[r.Old.String()] = r.New.String()
}
if len(replaced) > 0 {
cmd := env.newGoModCommand(ctx, "edit")
for o, n := range replaced {
cmd.Args = append(cmd.Args, "-replace", fmt.Sprintf("%s=%s", o, n))
}
err := env.runCommand(ctx, cmd)
if err != nil {
return nil, err
}
replaced[r.Old.String()] = r.New.String()
}

// check for early abort
Expand Down

0 comments on commit 743ce51

Please sign in to comment.