forked from paketo-buildpacks/packit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.go
36 lines (28 loc) · 821 Bytes
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package packit
import (
"fmt"
"os"
"path/filepath"
"github.com/paketo-buildpacks/packit/internal"
)
// Run combines the invocation of both build and detect into a single entry
// point. Calling Run from an executable with a name matching "build" or
// "detect" will result in the matching DetectFunc or BuildFunc being called.
func Run(detect DetectFunc, build BuildFunc, options ...Option) {
config := OptionConfig{
exitHandler: internal.NewExitHandler(),
args: os.Args,
}
for _, option := range options {
config = option(config)
}
phase := filepath.Base(config.args[0])
switch phase {
case "detect":
Detect(detect, options...)
case "build":
Build(build, options...)
default:
config.exitHandler.Error(fmt.Errorf("failed to run buildpack: unknown lifecycle phase %q", phase))
}
}