github.com/nak3/source-to-image@v1.1.10-0.20180319140719-2ed55639898d/pkg/build/strategies/sti/usage.go (about) 1 package sti 2 3 import ( 4 "github.com/openshift/source-to-image/pkg/api" 5 "github.com/openshift/source-to-image/pkg/build" 6 "github.com/openshift/source-to-image/pkg/docker" 7 "github.com/openshift/source-to-image/pkg/util/fs" 8 ) 9 10 // UsageHandler handles a config to display usage 11 type usageHandler interface { 12 build.ScriptsHandler 13 build.Preparer 14 SetScripts([]string, []string) 15 } 16 17 // Usage display usage information about a particular build image 18 type Usage struct { 19 handler usageHandler 20 garbage build.Cleaner 21 config *api.Config 22 } 23 24 // NewUsage creates a new instance of the default Usage implementation 25 func NewUsage(client docker.Client, config *api.Config) (*Usage, error) { 26 b, err := New(client, config, fs.NewFileSystem(), build.Overrides{}) 27 if err != nil { 28 return nil, err 29 } 30 usage := Usage{ 31 handler: b, 32 config: config, 33 garbage: b.garbage, 34 } 35 return &usage, nil 36 } 37 38 // Show starts the builder container and invokes the usage script on it 39 // to print usage information for the script. 40 func (u *Usage) Show() error { 41 b := u.handler 42 defer u.garbage.Cleanup(u.config) 43 44 b.SetScripts([]string{api.Usage}, []string{}) 45 46 if err := b.Prepare(u.config); err != nil { 47 return err 48 } 49 50 return b.Execute(api.Usage, "", u.config) 51 }