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