@@ -162,6 +162,10 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
162
162
params .TraceLogger = ctx .Err
163
163
}
164
164
165
+ if cmd .vendorOnly {
166
+ return cmd .runVendorOnly (ctx , args , p , sm , params )
167
+ }
168
+
165
169
params .RootPackageTree , err = pkgtree .ListPackages (p .ResolvedAbsRoot , string (p .ImportRoot ))
166
170
if err != nil {
167
171
return errors .Wrap (err , "ensure ListPackage for project" )
@@ -202,31 +206,9 @@ func (cmd *ensureCommand) validateFlags() error {
202
206
func (cmd * ensureCommand ) runDefault (ctx * dep.Ctx , args []string , p * dep.Project , sm gps.SourceManager , params gps.SolveParameters ) error {
203
207
// Bare ensure doesn't take any args.
204
208
if len (args ) != 0 {
205
- if cmd .vendorOnly {
206
- return errors .Errorf ("dep ensure -vendor-only only populates vendor/ from %s; it takes no spec arguments" , dep .LockName )
207
- }
208
209
return errors .New ("dep ensure only takes spec arguments with -add or -update" )
209
210
}
210
211
211
- if cmd .vendorOnly {
212
- if p .Lock == nil {
213
- return errors .Errorf ("no %s exists from which to populate vendor/" , dep .LockName )
214
- }
215
- // Pass the same lock as old and new so that the writer will observe no
216
- // difference and choose not to write it out.
217
- sw , err := dep .NewSafeWriter (nil , p .Lock , p .Lock , dep .VendorAlways )
218
- if err != nil {
219
- return err
220
- }
221
-
222
- if cmd .dryRun {
223
- ctx .Out .Printf ("Would have populated vendor/ directory from %s" , dep .LockName )
224
- return nil
225
- }
226
-
227
- return errors .WithMessage (sw .Write (p .AbsRoot , sm , true ), "grouped write of manifest, lock and vendor" )
228
- }
229
-
230
212
solver , err := gps .Prepare (params , sm )
231
213
if err != nil {
232
214
return errors .Wrap (err , "prepare solver" )
@@ -279,6 +261,29 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
279
261
return errors .Wrap (sw .Write (p .AbsRoot , sm , false ), "grouped write of manifest, lock and vendor" )
280
262
}
281
263
264
+ func (cmd * ensureCommand ) runVendorOnly (ctx * dep.Ctx , args []string , p * dep.Project , sm gps.SourceManager , params gps.SolveParameters ) error {
265
+ if len (args ) != 0 {
266
+ return errors .Errorf ("dep ensure -vendor-only only populates vendor/ from %s; it takes no spec arguments" , dep .LockName )
267
+ }
268
+
269
+ if p .Lock == nil {
270
+ return errors .Errorf ("no %s exists from which to populate vendor/" , dep .LockName )
271
+ }
272
+ // Pass the same lock as old and new so that the writer will observe no
273
+ // difference and choose not to write it out.
274
+ sw , err := dep .NewSafeWriter (nil , p .Lock , p .Lock , dep .VendorAlways )
275
+ if err != nil {
276
+ return err
277
+ }
278
+
279
+ if cmd .dryRun {
280
+ ctx .Out .Printf ("Would have populated vendor/ directory from %s" , dep .LockName )
281
+ return nil
282
+ }
283
+
284
+ return errors .WithMessage (sw .Write (p .AbsRoot , sm , true ), "grouped write of manifest, lock and vendor" )
285
+ }
286
+
282
287
func (cmd * ensureCommand ) runUpdate (ctx * dep.Ctx , args []string , p * dep.Project , sm gps.SourceManager , params gps.SolveParameters ) error {
283
288
if p .Lock == nil {
284
289
return errors .Errorf ("-update works by updating the versions recorded in %s, but %s does not exist" , dep .LockName , dep .LockName )
0 commit comments