File tree Expand file tree Collapse file tree
lib/octocatalog-diff/catalog-diff/cli/options
spec/octocatalog-diff/tests/catalog-diff/cli/options Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 22# @param parser [OptionParser object] The OptionParser argument
33# @param options [Hash] Options hash being constructed; this is modified in this method.
44OctocatalogDiff ::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 |
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments