-
Notifications
You must be signed in to change notification settings - Fork 26
/
run.go
61 lines (49 loc) · 1.54 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package packit
import (
"fmt"
"os"
"path/filepath"
"github.com/paketo-buildpacks/packit/v2/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))
}
}
// RunExtension combines the invocation of both generate and detect into a single entry
// point. Calling Run from an executable with a name matching "generate" or
// "detect" will result in the matching DetectFunc or GenerateFunc being called.
func RunExtension(detect DetectFunc, generate GenerateFunc, 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 "generate":
Generate(generate, options...)
default:
config.exitHandler.Error(fmt.Errorf("failed to run buildpack: unknown lifecycle phase %q", phase))
}
}