Sha256: bdbef37c7ade946c3a05d8b700b57af1422f312533545329debdeb2ee0f1ddc8
Contents?: true
Size: 1.89 KB
Versions: 2
Compression:
Stored size: 1.89 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 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] <output> -- [rake options]' opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v| set_option(options, :verbose, v) end opts.on('-f', '--file FILE', String, 'Run even when up to date') do |s| set_option(options, :file, s) end opts.on('-j', '--jobs JOBS', Integer, 'Run in parallel') do |n| set_option(options, :jobs, n) end end if ARGV.empty? puts parser.help exit(1) end both_args = ARGV.join(' ').split(' -- ') self_args = both_args[0].split(/\s+/) parser.parse!(self_args) extra_args = (both_args[1] || ' ').lstrip entry = options[:file] || detect_main env = if options[:verbose] 'LOG_LEVEL=0 ' else '' end targets = self_args.join(' ') cmd = '' opt_str = "-f #{entry}" opt_str += " -m -j #{options[:jobs]}" if options.key?(:jobs) cmd += "#{env}rake #{opt_str} #{extra_args} #{targets}" puts cmd output = [] ro, out = IO.pipe re, err = IO.pipe pid = fork do status = system(cmd, out: out, err: err) puts 'Error: rake returns the following information:' unless status exit($CHILD_STATUS.exitstatus) end out.close err.close ro.each_line do |l| puts l output << l.chomp end re.each_line { |l| puts l; } Process.wait(pid) puts 'All targets are up to date' if output.empty? && $CHILD_STATUS.exitstatus == 0
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
raka-0.3.6 | bin/raka |
raka-0.3.4 | bin/raka |