Skip to content

Commit 9386c4c

Browse files
Merge pull request #367 from sayan-biswas/override-parameters
Add overridable parameter
2 parents 392e668 + 3da4f12 commit 9386c4c

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

pkg/shp/params/params.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var hiddenKubeFlags = []string{
3939
"user",
4040
}
4141

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

57+
// Options accepts optional functions to override certain parameters
58+
type Options func(params *Params)
59+
5760
// AddFlags accepts flags and adds program global flags to it
5861
func (p *Params) AddFlags(flags *pflag.FlagSet) {
5962
p.configFlags.AddFlags(flags)
@@ -193,12 +196,39 @@ func (p *Params) NewFollower(
193196
return p.follower, nil
194197
}
195198

199+
// WithClientset updates the shp CLI to use the provided Kubernetes and Build clientsets
200+
func WithClientset(kubeClientset kubernetes.Interface, buildClientset buildclientset.Interface) Options {
201+
return func(p *Params) {
202+
p.clientset = kubeClientset
203+
p.buildClientset = buildClientset
204+
}
205+
}
206+
207+
// WithConfigFlags updates the shp CLI to use the provided configuration flags
208+
func WithConfigFlags(configFlags *genericclioptions.ConfigFlags) Options {
209+
return func(p *Params) {
210+
p.configFlags = configFlags
211+
}
212+
}
213+
214+
// WithNamespace updates the shp CLI to use the provided namespace
215+
func WithNamespace(namespace string) Options {
216+
return func(p *Params) {
217+
p.namespace = namespace
218+
}
219+
}
220+
196221
// NewParams creates a new instance of ShipwrightParams and returns it as
197222
// an interface value
198-
func NewParams() *Params {
223+
func NewParams(options ...Options) *Params {
199224
p := &Params{}
200225
p.configFlags = genericclioptions.NewConfigFlags(true)
201226

227+
// Apply all provided options
228+
for _, option := range options {
229+
option(p)
230+
}
231+
202232
return p
203233
}
204234

0 commit comments

Comments
 (0)