Proposal Details

go.work:

replace gopkg.in/yaml.v2 => /some/path/1
replace gopkg.in/yaml.v2 => /some/path/2

main.go:

_, err = modfile.ParseWork(...)
fmt.Println(err == nil) // true

Thus, multiple replaces of the same source are allowed in the work file.

There are methods AddRequire and AddNewRequire for objects of struct modfile.File but there is only method AddReplace for objects of struct modfile.WorkFile. Please add AddNewReplace for modfile.WorkFile. Generally the same method can be added for objects of struct modfile.File also. After all, they have a common meaning. It's strange that they don't have a common inherited interface at all.

Comment From: seankhliao

This doesn't make any sense. Extra require lines can be remove through tidy by resolving the dependency graph, but duplicate replace lines will always result in an error later down the line. Being able to parse the file does not mean that it is well formed.

Comment From: mwriter

This doesn't make any sense. Extra require lines can be remove through tidy by resolving the dependency graph, but duplicate replace lines will always result in an error later down the line. Being able to parse the file does not mean that it is well formed.

You didn't understand anything you read at all. You're just in a hurry to close and report back. If you're so smart, why is there method AddNewRequire that adds repetitions too? Run faster and tell them to cancel it too, smartass.

through tidy

I'm sure you don't even begin to understand the sheer tasks volume tidy solves. This is the only way to explain that you don't understand my issue and immediately recommend it. One joy is that you are not allowed to write api methods. And someone still understands how everything works and why a large-scale api is needed.