Class: SyntaxTree::CLI::Write

Inherits:
Action
  • Object
show all
Defined in:
lib/syntax_tree/cli.rb

Overview

An action of the CLI that formats the input source and writes the formatted output back to the file.

Instance Method Summary collapse

Methods inherited from Action

#failure, #success

Instance Method Details

#run(filepath, source) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/syntax_tree/cli.rb', line 118

def run(filepath, source)
  print filepath
  start = Time.now

  formatted = SyntaxTree.format(source)
  File.write(filepath, formatted)

  color = source == formatted ? Color.gray(filepath) : filepath
  delta = ((Time.now - start) * 1000).round

  puts "\r#{color} #{delta}ms"
rescue StandardError
  puts "\r#{filepath}"
  raise
end