Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions pkg/shp/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var hiddenKubeFlags = []string{
"user",
}

// Params is a place for Shipwright CLI to store its runtime parameters including configured dynamic
// Params is a place for Shipwright CLI to store its runtime parameters, including configured dynamic
// client and global flags.
type Params struct {
clientset kubernetes.Interface // kubernetes api-client, global instance
Expand All @@ -54,6 +54,9 @@ type Params struct {
failPollTimeout *time.Duration
}

// Options accepts optional functions to override certain parameters
type Options func(params *Params)

// AddFlags accepts flags and adds program global flags to it
func (p *Params) AddFlags(flags *pflag.FlagSet) {
p.configFlags.AddFlags(flags)
Expand Down Expand Up @@ -193,12 +196,39 @@ func (p *Params) NewFollower(
return p.follower, nil
}

// WithClientset updates the shp CLI to use the provided Kubernetes and Build clientsets
func WithClientset(kubeClientset kubernetes.Interface, buildClientset buildclientset.Interface) Options {
return func(p *Params) {
p.clientset = kubeClientset
p.buildClientset = buildClientset
}
}

// WithConfigFlags updates the shp CLI to use the provided configuration flags
func WithConfigFlags(configFlags *genericclioptions.ConfigFlags) Options {
return func(p *Params) {
p.configFlags = configFlags
}
}

// WithNamespace updates the shp CLI to use the provided namespace
func WithNamespace(namespace string) Options {
return func(p *Params) {
p.namespace = namespace
}
}

// NewParams creates a new instance of ShipwrightParams and returns it as
// an interface value
func NewParams() *Params {
func NewParams(options ...Options) *Params {
p := &Params{}
p.configFlags = genericclioptions.NewConfigFlags(true)

// Apply all provided options
for _, option := range options {
option(p)
}

return p
}

Expand Down