0x1eef
313420b653
When given a locale, the "bin/quran-json" script will automatically map it to the appropriate libexec script based on the contents of "share/quran-json/data/sources.json".
39 lines
880 B
Ruby
Executable file
39 lines
880 B
Ruby
Executable file
#!/usr/bin/env ruby
|
|
require "json"
|
|
|
|
##
|
|
# 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")
|
|
share_dir = File.join(root_dir, "share", "quran-json", "data")
|
|
sources = JSON.parse(File.binread(File.join(share_dir, "sources.json")))
|
|
require File.join(lib_dir, "pull")
|
|
|
|
case argv[0]
|
|
when "pull"
|
|
options = Pull.cli(argv[1..])
|
|
sources.each do |locale, source|
|
|
case options.locale
|
|
when locale
|
|
wait spawn(libexec_dir, source["http"]["hostname"], *argv[1..])
|
|
end
|
|
end
|
|
else
|
|
warn "Usage: quran-json pull [OPTIONS]"
|
|
end
|
|
end
|
|
main(ARGV)
|