Module: Ra10ke::Duplicates

Included in:
RakeTask
Defined in:
lib/ra10ke/duplicates.rb

Defined Under Namespace

Classes: Verification

Instance Method Summary collapse

Instance Method Details

#define_task_duplicates(*_args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ra10ke/duplicates.rb', line 7

def define_task_duplicates(*_args)
  desc 'Check Puppetfile for duplicates'
  task :duplicates do
    duplicates = Ra10ke::Duplicates::Verification.new(get_puppetfile.puppetfile_path).duplicates
    exit_code = 0
    if duplicates.any?
      exit_code = 1
      message = 'Error: Duplicates exist in the Puppetfile'

      duplicates.map do |name, sources|
        puts "#{name}:"
        sources.each do |source|
          puts "- #{source}"
        end

        puts
      end
    else
      message = 'Puppetfile is free of duplicates'
    end

    abort(message) if exit_code.positive?
    puts message
  end
end