Skip to content

Commit

Permalink
define newConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jackspirou committed Nov 30, 2024
1 parent 2b47daa commit 4ae5123
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
22 changes: 14 additions & 8 deletions pkg/shcv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ type config struct {
Verbose bool
}

// newConfig creates a new config with the default options.
func newConfig(opts []Option) *config {
c := defaultConfig()
c.apply(opts)
return c
}

// defaultConfig returns the default configuration options for Chart processing.
// This includes standard file locations and common default values.
func defaultConfig() *config {
Expand All @@ -21,6 +28,13 @@ func defaultConfig() *config {
}
}

// apply applies the given options to the config.
func (c *config) apply(opts []Option) {
for _, option := range opts {
option(c)
}
}

// Option is a functional option for configuring the Chart processing.
type Option func(*config)

Expand All @@ -44,11 +58,3 @@ func WithVerbose(verbose bool) Option {
c.Verbose = verbose
}
}

// applyOptions applies the given options to the config.
func applyOptions(c *config, opts []Option) *config {
for _, option := range opts {
option(c)
}
return c
}
5 changes: 2 additions & 3 deletions pkg/shcv/shcv.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ func NewChart(dir string, opts ...Option) (*Chart, error) {
return nil, fmt.Errorf("invalid chart directory: %w", err)
}

// Create a new config, apply options, and update values files
config := defaultConfig()
config = applyOptions(config, opts)
// Create a new config with the given options
config := newConfig(opts)

// create a new chart and return it
chart := &Chart{
Expand Down

0 comments on commit 4ae5123

Please sign in to comment.