Skip to content

Commit 4e28776

Browse files
author
Kevin Paulisse
committed
Add --hiera_path command line argument
1 parent b932640 commit 4e28776

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Specify the path to the Hiera data directory (relative to the top level Puppet checkout). For Puppet Enterprise and the
2+
# Puppet control repo template, the value of this should be 'hieradata', which is the default.
3+
# @param parser [OptionParser object] The OptionParser argument
4+
# @param options [Hash] Options hash being constructed; this is modified in this method.
5+
OctocatalogDiff::CatalogDiff::Cli::Options::Option.newoption(:hiera_path) do
6+
has_weight 181
7+
8+
def parse(parser, options)
9+
parser.on('--hiera-path PATH', 'Path to hiera data directory, relative to top directory of repository') do |path_in|
10+
options[:hiera_path] = path_in
11+
12+
if options[:hiera_path].start_with?('/')
13+
raise ArgumentError, '--hiera-path PATH must be a relative path not an absolute path'
14+
end
15+
16+
options[:hiera_path].sub!(%r{/+$}, '')
17+
raise ArgumentError, '--hiera-path must not be empty' if options[:hiera_path].empty?
18+
end
19+
end
20+
end

lib/octocatalog-diff/catalog-diff/cli/options/hiera_path_strip.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# @param parser [OptionParser object] The OptionParser argument
33
# @param options [Hash] Options hash being constructed; this is modified in this method.
44
OctocatalogDiff::CatalogDiff::Cli::Options::Option.newoption(:hiera_path_strip) do
5-
has_weight 181
5+
has_weight 182
66

77
def parse(parser, options)
88
parser.on('--hiera-path-strip PATH', 'Path prefix to strip when munging hiera.yaml') do |path_in|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require_relative '../options_helper'
2+
3+
describe OctocatalogDiff::CatalogDiff::Cli::Options do
4+
describe '#opt_hiera_path' do
5+
it 'should set options[:hiera_path] when relative path is specified' do
6+
result = run_optparse(['--hiera-path', 'foo/bar/baz'])
7+
expect(result.fetch(:hiera_path, 'key-not-defined')).to eq('foo/bar/baz')
8+
end
9+
10+
it 'should error if an absolute path is specified' do
11+
expect { run_optparse(['--hiera-path', '/foo/bar/baz']) }.to raise_error(ArgumentError, /must be a relative path/)
12+
end
13+
14+
it 'should strip trailing slashes' do
15+
result = run_optparse(['--hiera-path', 'foo/bar/baz///'])
16+
expect(result.fetch(:hiera_path, 'key-not-defined')).to eq('foo/bar/baz')
17+
end
18+
19+
it 'should error if empty' do
20+
expect { run_optparse(['--hiera-path', '']) }.to raise_error(ArgumentError, /must not be empty/)
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)