Skip to content

Commit 4fd3106

Browse files
committed
Add overridable parameter
# Changes: - Add options to NewParams method to allow overriding certain parameters. This can benefit other projects to import this CLI as library. Signed-off-by: Sayan Biswas <sayan-biswas@live.com>
1 parent 59a465f commit 4fd3106

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

pkg/shp/params/params.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ type Params struct {
5454
failPollTimeout *time.Duration
5555
}
5656

57+
type Options func(params *Params)
58+
5759
// AddFlags accepts flags and adds program global flags to it
5860
func (p *Params) AddFlags(flags *pflag.FlagSet) {
5961
p.configFlags.AddFlags(flags)
@@ -193,12 +195,39 @@ func (p *Params) NewFollower(
193195
return p.follower, nil
194196
}
195197

198+
// WithClientset Use explicit clientset
199+
func WithClientset(kubeClientset kubernetes.Interface, buildClientset buildclientset.Interface) Options {
200+
return func(p *Params) {
201+
p.clientset = kubeClientset
202+
p.buildClientset = buildClientset
203+
}
204+
}
205+
206+
// WithConfigFlags Use explicit config flags
207+
func WithConfigFlags(configFlags *genericclioptions.ConfigFlags) Options {
208+
return func(p *Params) {
209+
p.configFlags = configFlags
210+
}
211+
}
212+
213+
// WithNamespace Use explicit namespace
214+
func WithNamespace(namespace string) Options {
215+
return func(p *Params) {
216+
p.namespace = namespace
217+
}
218+
}
219+
196220
// NewParams creates a new instance of ShipwrightParams and returns it as
197221
// an interface value
198-
func NewParams() *Params {
222+
func NewParams(options ...Options) *Params {
199223
p := &Params{}
200224
p.configFlags = genericclioptions.NewConfigFlags(true)
201225

226+
// Apply all provided options
227+
for _, option := range options {
228+
option(p)
229+
}
230+
202231
return p
203232
}
204233

0 commit comments

Comments
 (0)