quran-go

Read Qur'an right in the terminal.
git clone http://git.hanabi.in/repos/quran-go.git
Log | Files | Refs | README | LICENSE

commit 2213e51cb00ec1084be494ec8a93680f7f5ab4fa
parent 46a2e79afeee3e89c9348f732e6caa33f0e985cf
Author: Agastya Chandrakant <me@hanabi.in>
Date:   Tue, 26 Apr 2022 23:13:39 +0530

Do not accept 2:14-14 as a valid input, it is incorrect semantics.  - is
used only when speaking of multiple verses.  2:14 is correct, so is
2:14-15.  But not 2:14-14.

Diffstat:
MPLAN | 4++++
Mmain.go | 18++++++++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/PLAN b/PLAN @@ -5,3 +5,7 @@ Available commands: + quran 2:10 + quran 2:10-11 + quran 2:10-11 -lang=ur + +Convention: + +In the source code (even in the comments), "verse" is used in place of "aayat" since the JSON response of quran.com API says verse. So staying consistent with it. diff --git a/main.go b/main.go @@ -23,8 +23,13 @@ func main() { if err := checkVerseRange(chap, ver1, ver2); err != nil { printerr(err) } else { - // @CONTINUE - // @TODO -- identify if one ayaat, multiple aayat or the whole chapter needs to be printed. + if ver1 == 0 { + // Print whole chapter. + } else if ver1 < ver2 { + // Print the range of verses. + } else if ver1 == ver2 { + // Print just one verse. + } } } } @@ -136,7 +141,7 @@ type ChaptersList struct { } func getInput() (input, lang string) { - flag.StringVar(&lang, "lang", "en", "Aayat language.") + flag.StringVar(&lang, "lang", "en", "Verse language.") flag.Parse() input = flag.Arg(0) return input, lang @@ -160,6 +165,11 @@ func parseInput(input string) (err error, chapter t_chap, verse1, verse2 t_verse } chapter = t_chap(ch) + if res[0][3] == res[0][5] && len(res[0][3]) > 0 { + err = fmt.Errorf("Verse 2 should not be same as Verse 1.\n") + return + } + if res[0][3] == "" { res[0][3] = "0" } @@ -182,7 +192,7 @@ func parseInput(input string) (err error, chapter t_chap, verse1, verse2 t_verse } if verse2 < verse1 { - err = fmt.Errorf("Verse 2 cannot be smaller than Verse 1.") + err = fmt.Errorf("Verse 2 must be bigger than Verse 1.\n") } return