Skip to content

Commit

Permalink
Add ability to define excluded parameters
Browse files Browse the repository at this point in the history
Excluded parameters can be defined for a given Puppet class that is
included such that the parameter is never presented to the user
as a command line option. These excluded parameters still appear
in the answers file and can be set through hiera.
  • Loading branch information
ehelms committed Aug 13, 2021
1 parent f0de2e7 commit 0216c9f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/kafo/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,21 @@ def modules
@data.map do |name, values|
if (class_config = app[:classes][name.to_sym])
can_disable = class_config[:can_disable] || false
excluded_params = class_config[:exclude] || []
else
can_disable = true
excluded_params = []
end

enabled = !!values || values.is_a?(Hash)

puppet_mod = PuppetModule.new(name, configuration: self, enabled: enabled, can_disable: can_disable)
puppet_mod = PuppetModule.new(
name,
configuration: self,
enabled: enabled,
can_disable: can_disable,
excluded_params: excluded_params
)
puppet_mod.parse
end.sort
end
Expand Down
1 change: 1 addition & 0 deletions lib/kafo/kafo_configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ def set_options
end

params.sort.each do |param|
next if param.module.excluded_param?(dashize(param.name))
doc = param.doc.nil? ? 'UNDOCUMENTED' : param.doc.join("\n")
app_option parametrize(param), '', doc + " (current: #{param.value_to_s})",
:multivalued => param.multivalued?
Expand Down
7 changes: 6 additions & 1 deletion lib/kafo/puppet_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.find_parser
end
end

def initialize(identifier, parser: nil, configuration: KafoConfigure.config, enabled: nil, can_disable: true)
def initialize(identifier, parser: nil, configuration: KafoConfigure.config, enabled: nil, can_disable: true, excluded_params: [])
@identifier = identifier
@configuration = configuration
@name = get_name
Expand All @@ -49,6 +49,7 @@ def initialize(identifier, parser: nil, configuration: KafoConfigure.config, ena
@raw_data = nil
@enabled = enabled
@can_disable = can_disable
@excluded_params = excluded_params
end

def enabled?
Expand Down Expand Up @@ -103,6 +104,10 @@ def params_hash
Hash[params.map { |param| [param.name, param.value] }]
end

def excluded_param?(param)
@excluded_params.include?(param)
end

def <=>(other)
@configuration.app[:low_priority_modules].each do |module_name|
return 1 if self.name.include?(module_name) && !other.name.include?(module_name)
Expand Down
12 changes: 12 additions & 0 deletions test/acceptance/kafo_configure_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,18 @@ module Kafo
_(code).must_equal 0, err
_(out).must_include "--enable-testing"
end

it 'allows declaring parameters that should be excluded as command line options' do
config = YAML.load_file(KAFO_CONFIG)
config[:classes] = {:testing => {:exclude => ['version']}}
File.open(KAFO_CONFIG, 'w') do |file|
file.write(config.to_yaml)
end

code, out, err = run_command '../bin/kafo-configure --full-help'
_(code).must_equal 0, err
_(out).wont_include "--testing-version"
end
end
end
end

0 comments on commit 0216c9f

Please sign in to comment.