Class: PROIEL::Commands::Validate

Inherits:
PROIEL::Command show all
Defined in:
lib/proiel/cli/commands/validate.rb

Class Method Summary collapse

Methods inherited from PROIEL::Command

inherited, subclasses

Class Method Details

.init_with_program(prog) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/proiel/cli/commands/validate.rb', line 5

def init_with_program(prog)
  prog.command(:validate) do |c|
    c.syntax 'validate'
    c.description 'Validate input data'
    c.action { |args, options| process(args, options) }
  end
end

.process(args, options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/proiel/cli/commands/validate.rb', line 13

def process(args, options)
  exit_code = 0

  if args.empty?
    STDERR.puts 'Missing filename(s). Use --help for more information.'
    exit 1
  end

  @schemas = {}

  args.each do |filename|
    v = PROIEL::PROIELXML::Validator.new(filename)

    if v.valid?
      puts "#{filename} is valid".green
    else
      puts "#{filename} is invalid".red

      v.errors.each do |error|
        puts "* #{error}"
      end

      exit_code = 1
    end
  end

  exit exit_code
end