quran-json/bin/quran-json

35 lines
765 B
Ruby
Executable file

#!/usr/bin/env ruby
##
# Utils
def spawn(libexec_dir, exec, *args)
Process.spawn File.join(libexec_dir, exec), *args
end
def wait(pid)
Process.wait(pid)
rescue Interrupt
retry
end
##
# main
def main(argv)
root_dir = File.realpath(File.join(__dir__, ".."))
lib_dir = File.join(root_dir, "lib", "quran-json")
libexec_dir = File.join(root_dir, "libexec", "quran-json")
require File.join(lib_dir, "pull")
case argv[0]
when "pull"
options = Pull.cli(argv[1..])
if %w[en pt fa].include?(options.locale)
wait spawn(libexec_dir, "quran.com", *argv[1..])
elsif %w[ar].include?(options.locale)
wait spawn(libexec_dir, "searchtruth.com", *argv[1..])
end
else
warn "Usage: quran-json pull [OPTIONS]"
end
end
main(ARGV)