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