Skip to content

Commit

Permalink
pkgset: add :main selector
Browse files Browse the repository at this point in the history
Fixes #50
  • Loading branch information
egonelbre committed Mar 24, 2021
1 parent 8a5165e commit d33a4f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkgset/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ func Calc(parentContext context.Context, expr []string) (Set, error) {

return Subtract(set, Sources(set)), nil

case "main":
set, err := eval(ctx, e.Expr)
if err != nil {
return nil, err
}
return Main(set), nil

default:
return nil, fmt.Errorf("unknown selector %v: %v", e.Selector, e)
}
Expand Down
11 changes: 11 additions & 0 deletions pkgset/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,14 @@ func Dependencies(a Set) Set {
}
return result
}

// Main returns main pacakges.
func Main(a Set) Set {
rs := Set{}
for pid, pkg := range a {
if pkg.Name == "main" {
rs[pid] = pkg
}
}
return rs
}

0 comments on commit d33a4f6

Please sign in to comment.