execute module replacement in a single command (#178)

* execute module replacement in a single command

* remove empty line
This commit is contained in:
WeidiDeng 2024-04-06 21:53:19 +08:00 committed by GitHub
parent dcaaa7302c
commit 743ce51c13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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