Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
ensure: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
darkowlzz committed Sep 22, 2017
1 parent 8711fc0 commit ebf6207
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,11 @@ func (e pkgtreeErrs) Error() string {
}

func validateUpdateArgs(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager, params *gps.SolveParameters) error {
// Channel for receiving all the valid arguments
validArgsCh := make(chan string, len(args))
// Channel for receiving all the valid arguments.
argsCh := make(chan string, len(args))

// Channel for receiving all the validation errors
errArgsValidationCh := make(chan error, len(args))
// Channel for receiving all the validation errors.
errCh := make(chan error, len(args))

var wg sync.WaitGroup

Expand All @@ -785,57 +785,57 @@ func validateUpdateArgs(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.Sour
go func(arg string) {
defer wg.Done()

// Ensure the provided path has a deducible project root
// Ensure the provided path has a deducible project root.
pc, path, err := getProjectConstraint(arg, sm)
if err != nil {
// TODO(sdboyer) ensure these errors are contextualized in a sensible way for -update
errArgsValidationCh <- err
errCh <- err
return
}
if path != string(pc.Ident.ProjectRoot) {
// TODO(sdboyer): does this really merit an abortive error?
errArgsValidationCh <- errors.Errorf("%s is not a project root, try %s instead", path, pc.Ident.ProjectRoot)
errCh <- errors.Errorf("%s is not a project root, try %s instead", path, pc.Ident.ProjectRoot)
return
}

if !p.Lock.HasProjectWithRoot(pc.Ident.ProjectRoot) {
errArgsValidationCh <- errors.Errorf("%s is not present in %s, cannot -update it", pc.Ident.ProjectRoot, dep.LockName)
errCh <- errors.Errorf("%s is not present in %s, cannot -update it", pc.Ident.ProjectRoot, dep.LockName)
return
}

if pc.Ident.Source != "" {
errArgsValidationCh <- errors.Errorf("cannot specify alternate sources on -update (%s)", pc.Ident.Source)
errCh <- errors.Errorf("cannot specify alternate sources on -update (%s)", pc.Ident.Source)
return
}

if !gps.IsAny(pc.Constraint) {
// TODO(sdboyer) constraints should be allowed to allow solves that
// target particular versions while remaining within declared constraints
errArgsValidationCh <- errors.Errorf("version constraint %s passed for %s, but -update follows constraints declared in %s, not CLI arguments", pc.Constraint, pc.Ident.ProjectRoot, dep.ManifestName)
// target particular versions while remaining within declared constraints.
errCh <- errors.Errorf("version constraint %s passed for %s, but -update follows constraints declared in %s, not CLI arguments", pc.Constraint, pc.Ident.ProjectRoot, dep.ManifestName)
return
}

// Valid argument
validArgsCh <- arg
// Valid argument.
argsCh <- arg
}(arg)
}

wg.Wait()
close(errArgsValidationCh)
close(validArgsCh)
close(errCh)
close(argsCh)

// Log all the errors
if len(errArgsValidationCh) > 0 {
// Log all the errors.
if len(errCh) > 0 {
ctx.Err.Printf("Invalid arguments passed to ensure -update:\n\n")
for err := range errArgsValidationCh {
for err := range errCh {
ctx.Err.Println(" ✗", err.Error())
}
ctx.Err.Println()
return errUpdateArgsValidation
}

// Add all the valid arguments to solve params
for arg := range validArgsCh {
// Add all the valid arguments to solve params.
for arg := range argsCh {
params.ToChange = append(params.ToChange, gps.ProjectRoot(arg))
}

Expand Down

0 comments on commit ebf6207

Please sign in to comment.