Class: Micron::App::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/micron/app/options.rb

Constant Summary collapse

DEFAULTS =
{
  :coverage => true
}

Class Method Summary collapse

Class Method Details

.parse(options = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/micron/app/options.rb', line 12

def self.parse(options=nil)

  # always try to use default options first
  if options then
    options = DEFAULTS.merge(options)
  else
    options = DEFAULTS.dup
  end

  # then rc file
  rc = File.join(Dir.pwd, ".micronrc")
  if File.exists? rc then
    parse_opts(options, File.read(rc).split(" "))
  end

  # then anything on command line
  parse_opts(options, ARGV)

  return options
end

.parse_opts(options, argv) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/micron/app/options.rb', line 33

def self.parse_opts(options, argv)
  parser = OptionParser.new do |opts|
    opts.banner = "usage: #{$0} [options]"

    opts.on("--nocov", "Disable coverage reporting") {
      options[:coverage] = false
    }

    opts.on("--proc", "Use the process runner") {
      options[:proc] = true
    }

    opts.on("--fork", "Use the forking runner") {
      options[:fork] = true
    }

    opts.on("--runclass", "Run class in child process") {
      options[:runclass] = true
    }

    opts.on("--runmethod", "Run method in child process") {
      options[:runmethod] = true
    }
  end

  begin
    parser.parse!(argv)

  rescue Exception => ex
    exit if ex.kind_of? SystemExit
    STDERR.puts "error: #{ex}"
    STDERR.puts
    STDERR.puts parser
    exit 1
  end

  return options
end