Skip to content

Commit

Permalink
cmd: handle replacements in --with
Browse files Browse the repository at this point in the history
Fixes #201
  • Loading branch information
mohammed90 committed Sep 11, 2024
1 parent ef41586 commit b72e330
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Flags:
return fmt.Errorf("unable to parse --replace arguments: %s", err.Error())
}
for _, withArg := range withArgs {
mod, ver, _, err := splitWith(withArg)
mod, ver, repl, err := splitWith(withArg)
if err != nil {
return err
}
Expand All @@ -83,22 +83,15 @@ Flags:
PackagePath: mod,
Version: ver,
})
handleReplace(withArg, mod, ver, repl, &replacements)
}

for _, withArg := range replaceArgs {
mod, ver, repl, err := splitWith(withArg)
if err != nil {
return err
}
// adjust relative replacements in current working directory since our temporary module is in a different directory
if strings.HasPrefix(repl, ".") {
repl, err = filepath.Abs(repl)
if err != nil {
log.Fatalf("[FATAL] %v", err)
}
log.Printf("[INFO] Resolved relative replacement %s to %s", withArg, repl)
}
replacements = append(replacements, xcaddy.NewReplace(xcaddy.Dependency{PackagePath: mod, Version: ver}.String(), repl))
handleReplace(withArg, mod, ver, repl, &replacements)
}

output, err = cmd.Flags().GetString("output")
Expand Down Expand Up @@ -187,3 +180,18 @@ Flags:
return nil
},
}

func handleReplace(orig, mod, ver, repl string, replacements *[]xcaddy.Replace) {
if repl != "" {
// adjust relative replacements in current working directory since our temporary module is in a different directory
if strings.HasPrefix(repl, ".") {
var err error
repl, err = filepath.Abs(repl)
if err != nil {
log.Fatalf("[FATAL] %v", err)
}
log.Printf("[INFO] Resolved relative replacement %s to %s", orig, repl)
}
*replacements = append(*replacements, xcaddy.NewReplace(xcaddy.Dependency{PackagePath: mod, Version: ver}.String(), repl))
}
}

0 comments on commit b72e330

Please sign in to comment.