From 43bde3c5d4ade0bb4a5b6aba23c1830d17005659 Mon Sep 17 00:00:00 2001 From: Sayan Biswas Date: Wed, 21 Jan 2026 13:22:13 +0530 Subject: [PATCH] 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 --- pkg/shp/params/params.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/pkg/shp/params/params.go b/pkg/shp/params/params.go index 14346c788..022ed4e96 100644 --- a/pkg/shp/params/params.go +++ b/pkg/shp/params/params.go @@ -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) @@ -193,12 +196,39 @@ func (p *Params) NewFollower( return p.follower, nil } +// WithClientset Use explicit clientset +func WithClientset(kubeClientset kubernetes.Interface, buildClientset buildclientset.Interface) Options { + return func(p *Params) { + p.clientset = kubeClientset + p.buildClientset = buildClientset + } +} + +// WithConfigFlags Use explicit config flags +func WithConfigFlags(configFlags *genericclioptions.ConfigFlags) Options { + return func(p *Params) { + p.configFlags = configFlags + } +} + +// WithNamespace Use explicit 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 }