From 44f16b6cd5b9cd9641c0c5df1c671c9e610ad7ac Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 6 Nov 2020 15:28:10 -0500 Subject: Added mod installation to cli interface --- bible.cc | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'bible.cc') diff --git a/bible.cc b/bible.cc index 2846c5f..b0e3ed3 100644 --- a/bible.cc +++ b/bible.cc @@ -16,6 +16,10 @@ void usage() { printf(" --list-books list books available in the current module\n"); printf(" --list-chapters list chapters available in book in the current module\n"); printf(" -o, --omit-verse-numbers when printing verse text, skip printing verse and chapter numbers\n"); + printf(" --list-installable= list bible versions available for download and install. Default lists for all languages.\n"); + printf(" --install-network install module from the network where is LANG:NAME as provided by --list-installable\n"); + printf(" --install-zip install module from a zip file\n"); + printf(" --remove-mod delete a mod from the system\n"); printf("\n\nExamples:\n bible Gal 5:22-23\n"); printf(" bible John 3:16\n bible Romans 12\n bible Matt 5:3-7:27\n"); printf(" bible Genesis 1-3\n"); @@ -61,6 +65,42 @@ void listChapters(string modname, string book) { } } +void listInstallable(string language) { + map> installable = libbible::downloadModsAvailable(); + for(auto pair : installable) { + if(!language.empty() && language != pair.first) { + continue; + } + printf("For language %s:\n", pair.first.c_str()); + for(string name : pair.second) { + printf(" %s\n", name.c_str()); + } + } +} + +void installNetwork(string mod) { + //Split on : + if(mod.find(':') == string::npos) { + printf("Unable to process module \"%s\": Must contain colon separated language:name\n", mod.c_str()); + return; + } + string lang = mod.substr(0, mod.find(':')); + string name = mod.substr(mod.find(':')+1); + if(libbible::installModFromInternet(lang, name)) { + printf("Module installed.\n"); + } else { + printf("Error installing module!\n"); + } +} + +void installZip(string path) { + libbible::installModFromZip(path); +} + +void removeMod(string mod) { + libbible::uninstallMod(mod); +} + int main(int argc, char* argv[]) { static struct option long_options[] = { {"help", no_argument, 0, 'h'}, @@ -69,7 +109,11 @@ int main(int argc, char* argv[]) { {"set-default-module", required_argument, 0, 0}, {"list-books", no_argument, 0, 0}, {"list-chapters", required_argument, 0, 0}, - {"omit-verse-numbers", no_argument, 0, 'o'} + {"omit-verse-numbers", no_argument, 0, 'o'}, + {"list-installable", optional_argument, 0, 0}, + {"install-network", required_argument, 0, 0}, + {"install-zip", required_argument, 0, 0}, + {"remove-mod", required_argument, 0, 0} }; int opt, option_index; string modname; @@ -99,6 +143,18 @@ int main(int argc, char* argv[]) { doListBooks = true; } else if(option == "list-chapters") { listChaptersBook = string(optarg); + } else if(option == "list-installable") { + if(optarg == nullptr) { + listInstallable(string()); + } else { + listInstallable(string(optarg)); + } + } else if(option == "install-network") { + installNetwork(string(optarg)); + } else if(option == "install-zip") { + installZip(string(optarg)); + } else if(option == "remove-mod") { + removeMod(string(optarg)); } break; default: @@ -120,6 +176,10 @@ int main(int argc, char* argv[]) { reference += argv[optind++]; reference += " "; } + if(reference.empty()) { + // That's all. + return 0; + } auto text = libbible::getText(libbible::passage{.modName = modname, .reference = reference}); int chapter = 0; -- cgit v1.2.3