Skip to content

Commit ad21a28

Browse files
author
Bryan C. Mills
committed
modfile: document (*File).*Require methods
For golang/go#45965 Change-Id: If3c7255f44adc81b69e8109a5d9d62f116579bbd Reviewed-on: https://go-review.googlesource.com/c/mod/+/323171 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent e953053 commit ad21a28

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

modfile/rule.go

+11
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,12 @@ func (f *File) AddGoStmt(version string) error {
835835
return nil
836836
}
837837

838+
// AddRequire sets the first require line for path to version vers,
839+
// preserving any existing comments for that line and removing all
840+
// other lines for path.
841+
//
842+
// If no line currently exists for path, AddRequire adds a new line
843+
// at the end of the last require block.
838844
func (f *File) AddRequire(path, vers string) error {
839845
need := true
840846
for _, r := range f.Require {
@@ -856,12 +862,17 @@ func (f *File) AddRequire(path, vers string) error {
856862
return nil
857863
}
858864

865+
// AddNewRequire adds a new require line for path at version vers at the end of
866+
// the last require block, regardless of any existing require lines for path.
859867
func (f *File) AddNewRequire(path, vers string, indirect bool) {
860868
line := f.Syntax.addLine(nil, "require", AutoQuote(path), vers)
861869
setIndirect(line, indirect)
862870
f.Require = append(f.Require, &Require{module.Version{Path: path, Version: vers}, indirect, line})
863871
}
864872

873+
// SetRequire sets the requirements of f to contain exactly req, preserving
874+
// any existing line comments contents (except for 'indirect' markings)
875+
// for the module versions named in req.
865876
func (f *File) SetRequire(req []*Require) {
866877
need := make(map[string]string)
867878
indirect := make(map[string]bool)

0 commit comments

Comments
 (0)