Sha256: 7df75b8e090e18a2bec5396d5b04af8013b5e9cc96f0ee2dbe0c529370215aa1

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'rack/contrib'
require 'diver_down'
require 'diver_down-web'
require 'optparse'
require 'tempfile'

options = {}
option_parser = OptionParser.new do |opts|
  opts.banner = <<~BANNER
    Usage: diver_down_web [options]

    Example:
      diver_down_web --definition-dir /path/to/definitions --metadata /path/to/metadata.yml

    Options:
  BANNER

  opts.on('--definition-dir PATH', 'Path to the definition directory') do |path|
    options[:definition_dir] = path
  end

  opts.on('--metadata PATH', 'Path to the metadata.yml') do |path|
    options[:metadata] = path
  end
end
option_parser.parse!(ARGV)

unless options[:definition_dir]
  puts 'Missing --definition-dir'
  puts
  puts option_parser.help
  exit 1
end

app = Rack::JSONBodyParser.new(
  DiverDown::Web.new(
    definition_dir: options.fetch(:definition_dir),
    metadata: DiverDown::Web::Metadata.new(options[:metadata] || Tempfile.new(['metadata', '.yaml']).path)
  )
)

begin
  # Rack 2.0
  require 'rack'
  require 'rack/server'
  Rack::Server.new(app:).start
rescue LoadError
  # Rack 3.0
  require 'rackup'
  Rackup::Server.new(app:).start
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
diver_down-0.0.1.alpha17 exe/diver_down_web