Skip to content

Commit 7fb451c

Browse files
committed
Make hiera config specifiable per branch
1 parent 07f4c24 commit 7fb451c

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

lib/octocatalog-diff/cli.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,14 @@ def self.cli(argv = ARGV, logger = Logger.new(STDERR), opts = {})
7070
# Note: do NOT use 'options[k] ||= v' here because if the value of options[k] is boolean(false)
7171
# it will then be overridden. Whereas the intent is to define values only for those keys that don't exist.
7272
opts.each { |k, v| options[k] = v unless options.key?(k) }
73-
veto_options = %w(enc header hiera_config include_tags)
73+
veto_options = %w(enc header include_tags)
7474
veto_options.each { |x| options.delete(x.to_sym) if options["no_#{x}".to_sym] }
75+
if options[:no_hiera_config]
76+
vetoes = %w[hiera_config to_hiera_config from_hiera_config]
77+
vetoes.each do |key|
78+
options.delete(key.to_sym)
79+
end
80+
end
7581
options[:ignore].concat opts.fetch(:additional_ignores, [])
7682

7783
# Incorporate default options where needed.

lib/octocatalog-diff/cli/options/hiera_config.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77
has_weight 180
88

99
def parse(parser, options)
10-
parser.on('--hiera-config PATH', 'Relative path to hiera YAML file') do |path_in|
11-
raise ArgumentError, '--no-hiera-config incompatible with --hiera-config' if options[:no_hiera_config]
12-
options[:hiera_config] = path_in
13-
end
10+
OctocatalogDiff::Cli::Options.option_globally_or_per_branch(
11+
parser: parser,
12+
options: options,
13+
cli_name: 'hiera-config',
14+
option_name: 'hiera_config',
15+
desc: 'Full or relative path to global Hiera configuration file',
16+
post_process: lambda do |opts|
17+
raise ArgumentError, '--no-hiera-config incompatible with --hiera-config' if opts[:no_hiera_config]
18+
end
19+
)
1420

1521
parser.on('--no-hiera-config', 'Disable hiera config file installation') do
16-
raise ArgumentError, '--no-hiera-config incompatible with --hiera-config' if options[:hiera_config]
22+
if options[:to_hiera_config] || options[:from_hiera_config]
23+
raise ArgumentError, '--no-hiera-config incompatible with --hiera-config'
24+
end
1725
options[:no_hiera_config] = true
1826
end
1927
end

spec/octocatalog-diff/tests/cli/options/hiera_config_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
describe '#opt_hiera_config' do
77
it 'should handle --hiera-config' do
88
result = run_optparse(['--hiera-config', 'adflkadfs'])
9-
expect(result[:hiera_config]).to eq('adflkadfs')
9+
expect(result[:to_hiera_config]).to eq('adflkadfs')
10+
expect(result[:from_hiera_config]).to eq('adflkadfs')
1011
expect(result.key?(:no_hiera_config)).to eq(false)
1112
end
1213

14+
it 'should handle separate to and from hiera config arguments' do
15+
end
16+
1317
it 'should handle --no-hiera-config' do
1418
result = run_optparse(['--no-hiera-config'])
1519
expect(result.key?(:hiera_config)).to eq(false)

spec/octocatalog-diff/tests/cli_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@
1818
end
1919

2020
describe '#cli' do
21+
context 'with --no-hiera-config' do
22+
it 'should not pass a hiera config file' do
23+
opts = { hiera_config: 'abcdefg', to_hiera_config: 'xyz123', from_hiera_config: 'qwerty' }
24+
argv = ['--no-hiera-config', '--catalog-only']
25+
answer = {
26+
ignore: [{ type: 'Class' }],
27+
no_hiera_config: true,
28+
catalog_only: true,
29+
from_env: 'origin/master',
30+
to_env: '.',
31+
colors: true,
32+
debug: false,
33+
quiet: false,
34+
format: :color_text,
35+
display_source_file_line: false,
36+
compare_file_text: true,
37+
display_datatype_changes: true,
38+
parallel: true,
39+
suppress_absent_file_details: true,
40+
hiera_path: 'hieradata'
41+
}
42+
logger, _logger_str = OctocatalogDiff::Spec.setup_logger
43+
expect(described_class).to receive(:catalog_only).with(logger, answer)
44+
OctocatalogDiff::Cli.cli(argv, logger, opts)
45+
end
46+
end
47+
2148
context 'Additional ARGV' do
2249
let(:default_argv) do
2350
[

0 commit comments

Comments
 (0)