Method: Raygun::Runner.parse

Defined in:
lib/raygun/raygun.rb

.parse(_args) ⇒ Object

rubocop:disable Metrics/MethodLength



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/raygun/raygun.rb', line 252

def parse(_args)
  raygun = nil

  options = OpenStruct.new
  options.target_dir     = nil
  options.prototype_repo = CARBONFIVE_REPO

  parser = OptionParser.new do |opts|
    opts.banner = "Usage: raygun [options] NEW_APP_DIRECTORY"

    opts.on("-h", "--help", "Show raygun usage") do
      usage_and_exit(opts)
    end
    opts.on(
      "-p",
      "--prototype [github_repo]",
      "Prototype github repo (e.g. carbonfive/raygun-rails)."
    ) do |prototype|
      options.prototype_repo = prototype
    end

    opts.on("-v", "--version", "Print the version number") do
      puts Raygun::VERSION
      exit 1
    end
  end

  begin
    parser.parse!
    options.target_dir = ARGV.first

    raise OptionParser::InvalidOption if options.target_dir.nil?

    raygun = Raygun::Runner.new(options.target_dir, options.prototype_repo)
  rescue OptionParser::InvalidOption
    usage_and_exit(parser)
  end

  raygun
end