Skip to content

Commit

Permalink
Improve diver_down_web
Browse files Browse the repository at this point in the history
  • Loading branch information
alpaca-tc committed Apr 10, 2024
1 parent c427b14 commit 7f55851
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions exe/diver_down_web
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,48 @@ require 'rack/contrib'
require 'webrick'
require 'diver_down'
require 'diver_down-web'
require 'optparse'

definition_dir = ENV.fetch('DIVER_DOWN_DIR')
module_store = DiverDown::Web::ModuleStore.new(ENV.fetch('DIVER_DOWN_MODULE_STORE'))
options = {}
option_parser = OptionParser.new do |opts|
opts.banner = <<~BANNER
Usage: diver_down_web [options]
Example:
diver_down_web --definition-dir /path/to/definitions --module-store /path/to/module_store.yml
Options:
BANNER

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

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

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

unless options[:module_store]
puts 'Missing --module-store'
puts
puts option_parser.help
exit 1
end

app = Rack::JSONBodyParser.new(
DiverDown::Web.new(definition_dir:, module_store:)
DiverDown::Web.new(
definition_dir: options.fetch(:definition_dir),
module_store: DiverDown::Web::ModuleStore.new(options[:module_store])
)
)

begin
Expand Down

0 comments on commit 7f55851

Please sign in to comment.