Sha256: f8d5bdc9efcf7e1e8ca20e8ec97a3fa201f7ff9d930a364d933e6738b6731074

Contents?: true

Size: 929 Bytes

Versions: 2

Compression:

Stored size: 929 Bytes

Contents

require 'thor'

module KaiserRuby
  class CLI < Thor
    desc "transpile FILE", "transpile a .rock FILE and output the result"
    option 'show-source'.to_sym, type: :boolean, desc: "prints out the source file along with the transpiled output"
    option :save, desc: "saves the transpiled output in SAVE"
    def transpile(filename)
      file = File.read filename
      output = KaiserRuby.transpile(file)

      if options['show-source'.to_sym]
        puts file
        puts "-" * 40
      end

      if options[:save]
        out = File.new(options[:save], 'w')
        out.write output
        out.close
        puts "Saved output in `#{options[:save]}`"
      else
        puts output
      end
      puts
    end

    desc "execute FILE", "transpiles and runs a .rock FILE"
    def execute(filename)
      file = File.read filename
      output = KaiserRuby.transpile(file)

      eval output
      puts
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kaiser-ruby-0.2.1 lib/kaiser_ruby/cli.rb
kaiser-ruby-0.2.0 lib/kaiser_ruby/cli.rb