Dynamically map locale to libexec script
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".
This commit is contained in:
parent
50229ec4ca
commit
313420b653
2 changed files with 8 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
require "json"
|
||||||
|
|
||||||
##
|
##
|
||||||
# Utils
|
# Utils
|
||||||
|
@ -18,15 +19,18 @@ def main(argv)
|
||||||
root_dir = File.realpath(File.join(__dir__, ".."))
|
root_dir = File.realpath(File.join(__dir__, ".."))
|
||||||
lib_dir = File.join(root_dir, "lib", "quran-json")
|
lib_dir = File.join(root_dir, "lib", "quran-json")
|
||||||
libexec_dir = File.join(root_dir, "libexec", "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")
|
require File.join(lib_dir, "pull")
|
||||||
|
|
||||||
case argv[0]
|
case argv[0]
|
||||||
when "pull"
|
when "pull"
|
||||||
options = Pull.cli(argv[1..])
|
options = Pull.cli(argv[1..])
|
||||||
if %w[en pt fa nl fr].include?(options.locale)
|
sources.each do |locale, source|
|
||||||
wait spawn(libexec_dir, "quran.com", *argv[1..])
|
case options.locale
|
||||||
elsif %w[ar].include?(options.locale)
|
when locale
|
||||||
wait spawn(libexec_dir, "searchtruth.com", *argv[1..])
|
wait spawn(libexec_dir, source["http"]["hostname"], *argv[1..])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
warn "Usage: quran-json pull [OPTIONS]"
|
warn "Usage: quran-json pull [OPTIONS]"
|
||||||
|
|
Loading…
Reference in a new issue