module Rufo::Command
def self.format_file(filename, want_check)
def self.format_file(filename, want_check) code = File.read(filename) result = format(code, File.dirname(filename)) if code != result if want_check STDERR.puts "Error: formatting #{filename} produced changes" else File.write(filename, result) puts "Format: #{filename}" end return true end false rescue Rufo::SyntaxError STDERR.puts "Error: the given text in #{filename} is not a valid ruby program (it has syntax errors)" exit 1 rescue Rufo::Bug => ex STDERR.puts "You've found a bug!" STDERR.puts "It happened while trying to format the file #{filename}" STDERR.puts "Please report it to https://github.com/asterite/rufo/issues with code that triggers it" STDERR.puts raise ex end