Module: MRubyTools::CLI

Defined in:
lib/mruby_tools.rb

Class Method Summary collapse

Class Method Details

.args(argv = ARGV) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/mruby_tools.rb', line 108

def self.args(argv = ARGV)
  rb_files = []
  out_file = nil
  c_file = nil
  mruby_dir = nil
  verbose = false
  help = false

  while !argv.empty?
    arg = argv.shift
    if arg == '-o'
      out_file = argv.shift
      raise "no out_file provided with -o" unless out_file
      raise "#{out_file} is misnamed" if File.extname(out_file) == '.rb'
    elsif arg == '-c'
      c_file = File.open(argv.shift || 'generated.c', "w")
    elsif arg == '-v'
      verbose = true
    elsif arg == '-h'
      help = true
    elsif arg == '-m'
      mruby_dir = argv.shift
      raise "no mruby_dir provided with -m" unless mruby_dir
    else
      rb_files << arg
    end
  end

  c_file ||= Tempfile.new(['mrbt-', '.c'])

  { verbose: verbose,
    help: help,
    c_file: c_file,
    out_file: out_file || 'outfile',
    rb_files: rb_files,
    mruby_dir: mruby_dir }
end

.usage(msg = nil) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/mruby_tools.rb', line 96

def self.usage(msg = nil)
  puts "  USAGE: mrbt file1.rb file2.rb ...\nOPTIONS: -o outfile     (provide a name for the standalone executable)\n     -c generated.c (leave the specified C file on the filesystem)\n     -m mruby_dir   (provide the dir for mruby src)\n     -v             (verbose)\n"
  warn "  ERROR: #{msg}" if msg
  exit(msg ? 1 : 0)
end