Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept replacements with branches of github forks #51

Merged
merged 2 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cmd/xcaddy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func runBuild(ctx context.Context, args []string) error {
})
if repl != "" {
// adjust relative replacements in current working directory since our temporary module is in a different directory
if !filepath.IsAbs(repl) {
if strings.HasPrefix(repl, ".") {
repl, err = filepath.Abs(repl)
if err != nil {
log.Fatalf("[FATAL] %v", err)
Expand Down Expand Up @@ -288,9 +288,13 @@ func trapSignals(ctx context.Context, cancel context.CancelFunc) {
func splitWith(arg string) (module, version, replace string, err error) {
const versionSplit, replaceSplit = "@", "="

parts := strings.SplitN(arg, versionSplit, 2)
module = parts[0]
modules := strings.SplitN(arg, replaceSplit, 2)
if len(modules) > 1 {
replace = modules[1]
}

parts := strings.SplitN(modules[0], versionSplit, 2)
module = parts[0]
if len(parts) == 1 {
parts := strings.SplitN(module, replaceSplit, 2)
if len(parts) > 1 {
Expand Down
11 changes: 11 additions & 0 deletions cmd/xcaddy/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ func TestSplitWith(t *testing.T) {
expectModule: "module",
expectReplace: "replace",
},
{
input: "module=replace@version",
expectModule: "module",
expectReplace: "replace@version",
},
{
input: "module@version=replace@version",
expectModule: "module",
expectVersion: "version",
expectReplace: "replace@version",
},
{
input: "=replace",
expectErr: true,
Expand Down