Sha256: 05af6adba08f00ce219072f0692e73c551261d2f2fc9552d947a430560c969d9

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'optparse'
require 'English'
require 'open3'

def detect_main
  # check predefined files
  main_file_cands = ['Rakefile.raka', 'rakefile.raka', 'main.raka']
  main_file_cands.each do |cand|
    return cand if File.exist?(cand)
  end

  # if only one .raka file, use it as main
  rakas = Dir.glob('*.raka')
  return rakas[0] if rakas.length == 1
end

entry = detect_main

options = { rake: {}, raka_finished: false }
def set_option(opts, key, value)
  if opts[:raka_finished]
    opts[:rake][key] = value
  else
    opts[key] = value
  end
end
parser = OptionParser.new do |opts|
  opts.banner = 'Usage: raka [options] [raka file] -- [rake options]'

  opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
    set_option(options, :verbose, v)
  end
end

both_args = ARGV.join(' ').split(' -- ')
extra_args = both_args[1]
self_args = both_args[0].split(/\s+/)
parser.parse!(self_args)

env = if options[:verbose]
        'LOG_LEVEL=0 '
      else
        ''
      end
targets = self_args.join(' ')
cmd = "#{env}rake -f #{entry}  #{extra_args} #{targets}"
puts cmd
output, err, code = Open3.capture3(cmd)
if code == 0
  # TOOD: if empty, print all exist
  puts output unless output.empty?
else
  puts 'Error: rake returns the following information:'
end
puts err

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
raka-0.3.2 bin/raka
raka-0.3.1 bin/raka