|
20 | 20 |
|
21 | 21 | config_test = ARGV.include?('--config-test') |
22 | 22 |
|
23 | | -paths = [ |
24 | | - ENV['OCTOCATALOG_DIFF_CONFIG_FILE'], |
25 | | - File.join(Dir.pwd, '.octocatalog-diff.cfg.rb'), |
26 | | - File.join(ENV['HOME'], '.octocatalog-diff.cfg.rb'), |
27 | | - '/opt/puppetlabs/octocatalog-diff/octocatalog-diff.cfg.rb', |
28 | | - '/usr/local/etc/octocatalog-diff.cfg.rb', |
29 | | - '/etc/octocatalog-diff.cfg.rb' |
30 | | -] |
31 | | - |
32 | | -cfgfile = nil |
33 | | - |
34 | | -paths.each do |path| |
35 | | - next if path.nil? |
36 | | - puts "Looking for config in: #{path}" if config_test |
37 | | - next unless File.file?(path) |
38 | | - begin |
39 | | - cfgfile = path |
40 | | - puts "Loading config: #{path}" if config_test |
41 | | - require path |
42 | | - rescue => exc |
43 | | - STDERR.puts "#{exc.class} error with #{path}: #{exc.message}\n#{exc.backtrace}" |
44 | | - exit 1 |
45 | | - end |
46 | | - break |
47 | | -end |
48 | | - |
49 | | -options = {} |
50 | | - |
51 | | -if cfgfile |
52 | | - begin |
53 | | - options = OctocatalogDiff::Config.config |
54 | | - rescue => exc |
55 | | - STDERR.puts "#{exc.class} error with #{cfgfile}: #{exc.message}\n#{exc.backtrace}" |
56 | | - exit 1 |
57 | | - end |
58 | | - unless options.is_a?(Hash) |
59 | | - STDERR.puts "Configuration must be Hash not #{options.class}!" |
60 | | - exit 1 |
61 | | - end |
62 | | - if config_test |
63 | | - options.each do |key, val| |
64 | | - puts ":#{key} => (#{val.class}) #{val.inspect}" |
65 | | - end |
66 | | - exit 0 |
67 | | - end |
68 | | -elsif config_test |
69 | | - STDERR.puts 'No configuration files found' |
70 | | - exit 1 |
| 23 | +logger = Logger.new(STDERR) |
| 24 | +logger.level = Logger::INFO |
| 25 | +logger.level = Logger::DEBUG if config_test |
| 26 | + |
| 27 | +options = OctocatalogDiff::API::V1.config(logger: logger, test: config_test) |
| 28 | +if config_test |
| 29 | + logger.info 'Exiting now because --config-test was specified' |
| 30 | + exit(0) |
71 | 31 | end |
72 | 32 |
|
73 | 33 | argv = ARGV.dup |
74 | | -exit_code = OctocatalogDiff::CatalogDiff::Cli.cli(argv, Logger.new(STDERR), options) |
| 34 | +exit_code = OctocatalogDiff::Cli.cli(argv, Logger.new(STDERR), options) |
75 | 35 | exit(exit_code) |
0 commit comments