@@ -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.
838844func (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.
859867func (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.
865876func (f * File ) SetRequire (req []* Require ) {
866877 need := make (map [string ]string )
867878 indirect := make (map [string ]bool )
0 commit comments