@@ -835,6 +835,12 @@ func (f *File) AddGoStmt(version string) error {
835
835
return nil
836
836
}
837
837
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.
838
844
func (f * File ) AddRequire (path , vers string ) error {
839
845
need := true
840
846
for _ , r := range f .Require {
@@ -856,12 +862,17 @@ func (f *File) AddRequire(path, vers string) error {
856
862
return nil
857
863
}
858
864
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.
859
867
func (f * File ) AddNewRequire (path , vers string , indirect bool ) {
860
868
line := f .Syntax .addLine (nil , "require" , AutoQuote (path ), vers )
861
869
setIndirect (line , indirect )
862
870
f .Require = append (f .Require , & Require {module.Version {Path : path , Version : vers }, indirect , line })
863
871
}
864
872
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.
865
876
func (f * File ) SetRequire (req []* Require ) {
866
877
need := make (map [string ]string )
867
878
indirect := make (map [string ]bool )
0 commit comments