#!/usr/bin/env ruby

if File.file?(asciidoctor_bespoke = (File.expand_path '../../lib/asciidoctor-bespoke.rb', __FILE__))
  require asciidoctor_bespoke
else
  require 'asciidoctor-bespoke'
end
require 'asciidoctor/cli'

options = Asciidoctor::Cli::Options.new backend: 'bespoke'

# FIXME This is a really bizarre API. Please make me simpler.
if Integer === (result = options.parse! ARGV)
  exit result
else
  invoker = Asciidoctor::Cli::Invoker.new options
  GC.start
  invoker.invoke!
  exit invoker.code
end
