Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/herb/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
require "optparse"

class Herb::CLI
include Herb::Colors

attr_accessor :json, :silent, :no_interactive, :no_log_file, :no_timing, :local, :escape, :no_escape, :freeze, :debug

def initialize(args)
Expand All @@ -27,6 +29,8 @@ def call
puts result.value.to_json
else
puts result.value.inspect

print_error_summary(result.errors) if @command == "parse" && result.respond_to?(:errors) && result.errors.any?
end
end

Expand Down Expand Up @@ -223,6 +227,33 @@ def options

private

def print_error_summary(errors)
puts
puts white("#{bold(red("Errors"))} #{dimmed("(#{errors.size} total)")}")
puts

errors.each_with_index do |error, index|
error_type = error.error_name
error_location = format_location_for_copy(error.location)
error_message = error.message

puts white(" #{bold("#{index + 1}.")} #{bold(red(error_type))} #{dimmed("at #{error_location}")}")
puts white(" #{error_message}")
puts unless index == errors.size - 1
end
end

def format_location_for_copy(location)
line = location.start.line
column = location.start.column

if @file
"#{@file}:#{line}:#{column}"
else
"#{line}:#{column}"
end
end

def compile_template
require_relative "engine"

Expand Down
Loading