Class: SyntaxTree::CLI::Write
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
Instance Method Details
#run(handler, filepath, source) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/syntax_tree/cli.rb', line 139 def run(handler, filepath, source) print filepath start = Time.now formatted = handler.format(source) File.write(filepath, formatted) if filepath != :stdin 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 |