aboutsummaryrefslogtreecommitdiff
path: root/bible.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2020-11-06 15:28:10 -0500
committerYour Name <you@example.com>2020-11-06 15:28:10 -0500
commit44f16b6cd5b9cd9641c0c5df1c671c9e610ad7ac (patch)
tree47e540ac3e98d8f68a0e0ab36f1c1bc03beb2d35 /bible.cc
parent7fc8ebf27892eb02488fd2e75ca35ae48f596782 (diff)
downloadlibbible-44f16b6cd5b9cd9641c0c5df1c671c9e610ad7ac.tar.gz
libbible-44f16b6cd5b9cd9641c0c5df1c671c9e610ad7ac.tar.bz2
libbible-44f16b6cd5b9cd9641c0c5df1c671c9e610ad7ac.zip
Added mod installation to cli interface
Diffstat (limited to 'bible.cc')
-rw-r--r--bible.cc62
1 files changed, 61 insertions, 1 deletions
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 <book> 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=<lang> list bible versions available for download and install. Default lists for all languages.\n");
+ printf(" --install-network <mod> install module from the network where <mod> is LANG:NAME as provided by --list-installable\n");
+ printf(" --install-zip <path> install module from a zip file\n");
+ printf(" --remove-mod <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<string, vector<string>> 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;