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(item) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/syntax_tree/cli.rb', line 176 def run(item) filepath = item.filepath start = Time.now source = item.source formatted = item.handler.format(source) File.write(filepath, formatted) if filepath != :stdin color = source == formatted ? Color.gray(filepath) : filepath delta = ((Time.now - start) * 1000).round puts "#{color} #{delta}ms" rescue StandardError puts filepath raise end |