Add Pull.cli_options
I came across the pattern in this diff while browsing the [rake](https://github.com/ruby/rake/) source code, and I thought it was worth repeating in quran-json.
This commit is contained in:
parent
4ba407021e
commit
3f1ed58432
2 changed files with 30 additions and 14 deletions
|
@ -45,7 +45,8 @@ the content of The Quran in multiple languages.
|
|||
Usage: quran-json pull [OPTIONS]
|
||||
-l, --locale LOCALE ar, en, pt, fa, nl, fr, or it (default: en)
|
||||
-r, --replace Replace existing JSON files (default: no)
|
||||
-u, --update Only update the surah metadata (implies -r, default: no)
|
||||
-u, --update Replace surah metadata with an updated copy (implies -r, default: no)
|
||||
|
||||
|
||||
<p align="left">
|
||||
<strong>Thanks</strong>
|
||||
|
@ -53,12 +54,12 @@ the content of The Quran in multiple languages.
|
|||
|
||||
First and foremost, Alhamdulillah.
|
||||
|
||||
Thanks to the following websites for making the content available to download:
|
||||
Thanks to the following websites for providing the downloadable content:
|
||||
|
||||
* https://searchtruth.com for the original Arabic, and the Italian translation.
|
||||
* https://quran.com for the English, Farsi, Portuguese, Dutch, and French translations.
|
||||
|
||||
And thanks to the translators of the content:
|
||||
And sincere thanks to the translators of the content:
|
||||
|
||||
* _Dr. Mustafa Khattab_ for the English translation.
|
||||
* _Hussein Taji Kal Dari_ for the Farsi translation.
|
||||
|
@ -72,4 +73,4 @@ And thanks to the translators of the content:
|
|||
|
||||
The "source code" is released under the [GPL](./LICENSE) license.
|
||||
<br>
|
||||
The content is copyrighted to the translators (named above).
|
||||
The content is copyrighted to the translators (listed above).
|
||||
|
|
|
@ -15,20 +15,35 @@ class Quran::JSON::Pull
|
|||
|
||||
def self.cli(argv)
|
||||
op = nil
|
||||
options = Ryo({locale: "en", replace: false, update: false})
|
||||
OptionParser.new(nil, 26, " " * 2) do |o|
|
||||
o.banner = "Usage: quran-json pull [OPTIONS]"
|
||||
result = Ryo({locale: "en", replace: false, update: false})
|
||||
OptionParser.new(nil, 22, " " * 2) do |o|
|
||||
op = o
|
||||
o.on("-l", "--locale LOCALE", "ar, en, pt, fa, nl, fr, or it (default: en)")
|
||||
o.on("-r", "--replace", "Replace existing JSON files (default: no)")
|
||||
o.on("-u", "--update", "Only update the surah metadata (implies -r, default: no)")
|
||||
end.parse(argv, into: options)
|
||||
options
|
||||
op.banner = "Usage: quran-json pull [OPTIONS]"
|
||||
cli_options.each { op.on(*_1) }
|
||||
end.parse(argv, into: result)
|
||||
result
|
||||
rescue
|
||||
puts op.help
|
||||
exit
|
||||
end
|
||||
|
||||
def self.cli_options
|
||||
[
|
||||
[
|
||||
"-l", "--locale LOCALE",
|
||||
"ar, en, pt, fa, nl, fr, or it (default: en)"
|
||||
],
|
||||
[
|
||||
"-r", "--replace",
|
||||
"Replace existing JSON files (default: no)"
|
||||
],
|
||||
[
|
||||
"-u", "--update",
|
||||
"Replace surah metadata with an updated copy (implies -r, default: no)"
|
||||
]
|
||||
]
|
||||
end
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
@source = sources[options.locale]
|
||||
|
|
Loading…
Reference in a new issue