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
32 changes: 31 additions & 1 deletion pkg/shp/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 Use explicit clientset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use clearer godoc

Suggested change
// WithClientset Use explicit clientset
// 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 Use explicit config flags
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use clearer godoc

Suggested change
// WithConfigFlags Use explicit config flags
// 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 Use explicit namespace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: clearer godoc

Suggested change
// WithNamespace Use explicit namespace
// 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