From 313420b6538910547e8df147798a6b77c5a6e05c Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sat, 11 Feb 2023 23:32:03 -0300 Subject: [PATCH] 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". --- bin/quran-json | 12 ++++++++---- .../{searchtruth.com => www.searchtruth.com} | 0 2 files changed, 8 insertions(+), 4 deletions(-) rename libexec/quran-json/{searchtruth.com => www.searchtruth.com} (100%) diff --git a/bin/quran-json b/bin/quran-json index f82ef6c..99fe899 100755 --- a/bin/quran-json +++ b/bin/quran-json @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +require "json" ## # Utils @@ -18,15 +19,18 @@ 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..]) - if %w[en pt fa nl fr].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..]) + 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]" diff --git a/libexec/quran-json/searchtruth.com b/libexec/quran-json/www.searchtruth.com similarity index 100% rename from libexec/quran-json/searchtruth.com rename to libexec/quran-json/www.searchtruth.com