class Rufo::Command

def format_file(filename)

def format_file(filename)
  code = File.read(filename)
  begin
    result = format(code, File.dirname(filename))
  rescue Rufo::SyntaxError
    # We ignore syntax errors as these might be template files
    # with .rb extension
    STDERR.puts "Error: #{filename} has syntax errors"
    return true
  end
  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 => 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