|
8 | 8 | has_weight 181 |
9 | 9 |
|
10 | 10 | def parse(parser, options) |
11 | | - parser.on('--hiera-path PATH', 'Path to hiera data directory, relative to top directory of repository') do |path_in| |
12 | | - if options.key?(:hiera_path_strip) && options[:hiera_path_strip] != :none |
13 | | - raise ArgumentError, '--hiera-path and --hiera-path-strip are mutually exclusive' |
| 11 | + OctocatalogDiff::Cli::Options.option_globally_or_per_branch( |
| 12 | + parser: parser, |
| 13 | + options: options, |
| 14 | + cli_name: 'hiera-path', |
| 15 | + option_name: 'hiera_path', |
| 16 | + desc: 'Path to hiera data directory, relative to top directory of repository', |
| 17 | + validator: lambda do |path| |
| 18 | + if path.start_with?('/') |
| 19 | + raise ArgumentError, '--hiera-path PATH must be a relative path not an absolute path' |
| 20 | + end |
| 21 | + end, |
| 22 | + translator: lambda do |path| |
| 23 | + result = path.sub(%r{/+$}, '') |
| 24 | + raise ArgumentError, '--hiera-path must not be empty' if result.empty? |
| 25 | + result |
| 26 | + end, |
| 27 | + post_process: lambda do |opts| |
| 28 | + if opts.key?(:to_hiera_path_strip) && opts[:to_hiera_path_strip] != :none |
| 29 | + raise ArgumentError, '--hiera-path and --hiera-path-strip are mutually exclusive' |
| 30 | + end |
| 31 | + if opts.key?(:from_hiera_path_strip) && opts[:from_hiera_path_strip] != :none |
| 32 | + raise ArgumentError, '--hiera-path and --hiera-path-strip are mutually exclusive' |
| 33 | + end |
| 34 | + if opts[:to_hiera_path] == :none || opts[:from_hiera_path] == :none |
| 35 | + raise ArgumentError, '--hiera-path and --no-hiera-path are mutually exclusive' |
| 36 | + end |
14 | 37 | end |
15 | | - |
16 | | - if options[:hiera_path] == :none |
17 | | - raise ArgumentError, '--hiera-path and --no-hiera-path are mutually exclusive' |
18 | | - end |
19 | | - |
20 | | - options[:hiera_path] = path_in |
21 | | - |
22 | | - if options[:hiera_path].start_with?('/') |
23 | | - raise ArgumentError, '--hiera-path PATH must be a relative path not an absolute path' |
24 | | - end |
25 | | - |
26 | | - options[:hiera_path].sub!(%r{/+$}, '') |
27 | | - raise ArgumentError, '--hiera-path must not be empty' if options[:hiera_path].empty? |
28 | | - end |
| 38 | + ) |
29 | 39 |
|
30 | 40 | parser.on('--no-hiera-path', 'Do not use any default hiera path settings') do |
31 | | - if options[:hiera_path].is_a?(String) |
| 41 | + if options[:to_hiera_path].is_a?(String) || options[:from_hiera_path].is_a?(String) |
32 | 42 | raise ArgumentError, '--hiera-path and --no-hiera-path are mutually exclusive' |
33 | 43 | end |
34 | 44 |
|
35 | | - options[:hiera_path] = :none |
| 45 | + options[:from_hiera_path] = :none |
| 46 | + options[:to_hiera_path] = :none |
36 | 47 | end |
37 | 48 | end |
38 | 49 | end |
0 commit comments