/
usage.go
49 lines (41 loc) · 1.06 KB
/
usage.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
package sti
import (
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/build"
)
// UsageHandler handles a config to display usage
type usageHandler interface {
build.ScriptsHandler
build.Preparer
SetScripts([]string, []string)
}
// Usage display usage information about a particular build image
type Usage struct {
handler usageHandler
garbage build.Cleaner
config *api.Config
}
// NewUsage creates a new instance of the default Usage implementation
func NewUsage(config *api.Config) (*Usage, error) {
b, err := New(config, build.Overrides{})
if err != nil {
return nil, err
}
usage := Usage{
handler: b,
config: config,
garbage: b.garbage,
}
return &usage, nil
}
// Show starts the builder container and invokes the usage script on it
// to print usage information for the script.
func (u *Usage) Show() error {
b := u.handler
defer u.garbage.Cleanup(u.config)
b.SetScripts([]string{api.Usage}, []string{})
if err := b.Prepare(u.config); err != nil {
return err
}
return b.Execute(api.Usage, "", u.config)
}