Sha256: 42b83f1debb62d740dbb43d7b29b173670175d86993e1de866b91b65ecd3ac1b

Contents?: true

Size: 697 Bytes

Versions: 1

Compression:

Stored size: 697 Bytes

Contents

require "thor"

module Prettyrb
  class CLI < Thor
    desc "format [FILE]", "Ruby file to prettify"
    def format(file)
      content = File.read(file)
      formatted_content = Prettyrb::Formatter.new(content).format

      puts formatted_content
    end

    desc "write [FILES]", "Write prettified Ruby files"
    def write(*files)
      files.each do |file|
        content = File.read(file)
        begin
          formatted_content = Prettyrb::Formatter.new(content).format
        rescue Exception => e
          puts "Failed to write #{file}"
          throw e
        end

        File.open(file, 'w') do |f|
          f.write(formatted_content)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prettyrb-0.5.0 lib/prettyrb/cli.rb