summaryrefslogtreecommitdiff
path: root/lib/options.rb
blob: ee302956c2dde9835a94f9e33800c4ff444f42ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'optparse'

module RCM
  # Command line options
  module Options
    @@options = { debug: false }

    if (after_double_dash = ARGV.slice_before('--').to_a.last&.drop(1))
      OptionParser.new do |opts|
        opts.banner = 'Usage: rake [task] -- [options]'
        opts.on('-v', '--[no-]debug', 'debug output') { |v| @@options[:debug] = v }
      end.parse!(after_double_dash)
    end

    def option(key)
      raise "No such option: #{key}" unless @@options.key?(key)

      @@options[key]
    end
  end
end