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 Attribute Summary
Attributes inherited from Action
Instance Method Summary collapse
Methods inherited from Action
#failure, #initialize, #success
Constructor Details
This class inherits a constructor from SyntaxTree::CLI::Action
Instance Method Details
#run(item) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/syntax_tree/cli.rb', line 218 def run(item) filepath = item.filepath start = Time.now source = item.source formatted = item.handler.format(source, .print_width) File.write(filepath, formatted) if item.writable? color = source == formatted ? Color.gray(filepath) : filepath delta = ((Time.now - start) * 1000).round puts "#{color} #{delta}ms" rescue StandardError puts filepath raise end |