class Contraption::Options

Attributes

values[R]

Public Class Methods

new(args) click to toggle source
# File lib/contraption/options.rb, line 15
def initialize args
  @values = {
             source:               DEFAULT_SOURCE,
             destination:          DEFAULT_DESTINATION,
             s3_access_key_id:     nil,
             s3_secret_access_key: nil,
             s3_target_bucket:     nil
  }
  @values.merge!(YAML.load_file(DEFAULT_CONFIG_FILE)) if DEFAULT_CONFIG_FILE.file?
  @values.each_pair {|k, v| @values[k] = Location.new(v) if %i[source destination].include? k}
  parse(args)
end

Private Instance Methods

method_missing(m, *a, &b) click to toggle source
Calls superclass method
# File lib/contraption/options.rb, line 29
def method_missing m, *a, &b
  values.fetch(m) { super }
end
parse(args) click to toggle source
# File lib/contraption/options.rb, line 33
def parse args
  OptionParser.new do |opts|
    opts.banner = "Usage: contraption [ options ]"
    opts.on("-d", "--destination path", "Path to destination") do |path|
      @values[:destination] = Location.new path
    end
    opts.on("-h", "--help") do
      puts opts
      exit
    end
    opts.on("-s", "--source path", "Path to source") do |path|
      @values[:source] = Location.new path
    end
    opts.on("--generate-config-file", "Create YAML file containing configuration options") do
      DEFAULT_CONFIG_FILE.open('w+') {|f| f.write(@values.to_yaml) }
      exit
    end
    begin
      opts.parse!(args)
    rescue OptionParser::ParseError => e
      STDERR.puts e.message, "\n", opts
      exit(1)
    end
  end
end