Created
October 21, 2015 18:12
-
-
Save asterite/0c9834e35920e5dcd3a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "compiler/crystal/**" | |
# This is OK | |
filename = ARGV[0]? | |
abort "missing filename" unless filename | |
if filename == "--all" | |
files = Dir["./**/*.cr"] | |
count = 0 | |
files.each do |file| | |
print "#{file}... " | |
time = Time.now | |
source = File.read(file) | |
begin | |
result = Crystal::Formatter.format(source) | |
File.write(file, result) | |
rescue ex | |
percent = (count * 100.0 / files.size).round(2) | |
puts "BAD (progress: #{percent}%)" | |
ex.inspect_with_backtrace STDERR | |
exit 1 | |
else | |
time = Time.now - time | |
puts "OK (#{time.total_milliseconds.round(2)}ms)" | |
count += 1 | |
end | |
end | |
else | |
source = File.read(filename) | |
begin | |
result = Crystal::Formatter.format(source) | |
puts result | |
puts | |
puts "~~~" | |
puts | |
print " assert_format " | |
print source.inspect.chomp | |
print ", " | |
p result.chomp | |
rescue ex | |
ex.inspect_with_backtrace STDERR | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment