Method: UCD::Interface::CommandLine#run

Defined in:
lib/ucd/interface/command_line.rb

#runObject

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ucd/interface/command_line.rb', line 38

def run
  @option_parser.parse!
  self.paths = ARGV
  @formatter.type = @type

  raise Error, "Output path must be a directory if multiple input files are given" if @output_path && @output_path.file? && @paths.length > 1

  @paths.each do |input_path|
    raise FileError, "File does not exist: #{input_path}" unless input_path.exist?

    data     = input_path.read
    document = Parser.parse(data)
    result   = @formatter.format(document)

    if @output_path
      output_path = @output_path
      output_path = output_path.join(input_path.basename(".*").to_s + ".#{@formatter.type}") if output_path.directory?

      output_path.open("w+") { |file| file.write(result) }
    else
      puts result
    end

  end
end