Skip to content

Commit

Permalink
Add parameter support for the help command
Browse files Browse the repository at this point in the history
  • Loading branch information
kovzol committed Feb 13, 2024
1 parent 111a704 commit 19cd6c3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ The available commands are:
* `sql` *switch*: Set some outputs to be shown also as an SQL query if *switch* is `on`.
* `colors` *switch*: Show some outputs colored if *switch* is `on`.
* `tokens` *Bible* *book* *verse*: Search for the given *verse* in the given *book* in the given *Bible* (see command `lookup`), but the output is shown in a tokenized form. Tokenization is done via Strong's numbers.
* `help`: Show some hints on usage.
* `help` *command*: Show some hints on usage of *command*, or get general help if no parameter is given.
* `quit`: Exit program.

There may be other commands available that are not documented yet.
Expand Down
57 changes: 52 additions & 5 deletions cli.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define BIBREF_VERSION "2023Dec21"
#define BIBREF_VERSION "2024Feb13"

#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -90,14 +90,15 @@ string errorTokensParameters = tokensCmd + " requires 3 or 4 parameters.";
string errorSearchParameters = searchCmd + " requires at least one parameter.";
string errorMisc = "Sorry, there were some problems with the command you entered.";

vector<string> vocabulary {addbooksCmd, compareCmd + "12", jaccardCmd + "12",
vector<string> commands {addbooksCmd, compareCmd + "12", jaccardCmd + "12",
textCmd + "1", textCmd + "2", lookupCmd + "1", lookupCmd + "2", quitCmd,
helpCmd, findCmd + "1", findCmd + "2", lengthCmd + "1", lengthCmd + "2",
minuniqueCmd + "1", latintextCmd + "1", latintextCmd + "2",
extendCmd, getrefsCmd, lookupCmd, maxresultsCmd, sqlCmd, psalminfoCmd,
rawCmd, rawCmd + "1", rawCmd + "2",
printCmd + "1", printCmd + "2", colorsCmd, tokensCmd, searchCmd
};
vector<string> vocabulary = commands;

void add_vocabulary_item(string item) {
replace(item.begin(), item.end(), ' ', '_');
Expand Down Expand Up @@ -193,7 +194,53 @@ void processQuitCmd() {
exit(0);
}

void processHelpCmd() {
void processHelpCmd(string input) {
int commandLength = helpCmd.length();
if (input.length() != commandLength) {
string rest = input.substr(input.find(" ") + 1);
if ((boost::ends_with(rest, "1") || boost::ends_with(rest, "2")) && !boost::ends_with(rest, "12"))
rest = rest.substr(0, rest.length()-1) + "N";
vector<string> helpStr = {"* `addbooks`: Load the books of LXX, SBLGNT and StatResGNT (if any of these are available). Most commands require that these books are already loaded. After using this command for the first time (it takes a couple of seconds), a folder named `bibref-addbooks-cache` will be created in the current working directory to speed up the next startup of this command.",
"* `textN` *text*: Define a Greek *text* and put its Latin transcription in clipboard N.",
"* `latintextN` *text*: Put the Latin transcription *text* in clipboard N.",
"* `findN` *Bible*: Search for the text of clipboard N in the given *Bible*.",
"* `lengthN`: Compute the length of the text in clipboard N.",
"* `printN`: Show the Greek text in clipboard N (without punctuation and spaces).",
"* `lookup` *Bible* *book* *verse*: Search for the given *verse* in the given *book* in the given *Bible*. Here *Bible* can be any translation that is already [installed as a module](https://www.crosswire.org/sword/modules/ModDisp.jsp?modType=Bibles) on the computer.",
"* `lookupN` *Bible* *book* *passage*: Search for the given *passage* in the given *book* in the given *Bible* and put its Latin transcription in clipboard N.",
"* `search` *Bible* *token1* *token2* ... *tokenN* *maxlength*: Search for the given set of tokens on a maximal length of *maxlength* in the given *Bible*.",
"* `raw` *Bible* *book* *start* *length*: Show the raw Latin transcription of a passage in the given *book* in the given *Bible*, beginning with the *start* position on *length* characters.",
"* `rawN` *Bible* *book* *start* *length*: Put a passage in the given *book* in the given *Bible*, beginning with the *start* position on *length* characters, in clipboard N.",
"* `minunique1` *Bible*: Search for minimal unique passages in clipboard 1 in the given *Bible*.",
"* `extend` *Bible1* *Bible2* *book2* *passage2*: Extend the given passage in *Bible2* according to the longest possible citation from *Bible1*, based on the text of *book2* in *passage2*. In most cases `LXX` is used for *Bible1* and `SBLGNT` for *Bible2*.",
"* `psalminfo` *Bible* *number*: Show the number of verses in Psalm *number* in the given *Bible*.",
"* `getrefs` *Bible2* *Bible1* *book1* *passage1*: Search for references in *Bible2* on the passage in *Bible1* in book *book1* in *passage1*. Usually `SBLGNT` stands for *Bible2* and `LXX` for *Bible1*. If *book1* is `Psalms`, the passage can also be its number only.",
"* `maxresults` *number*: Set the maximal amount of results to be shown to *number*.",
"* `compare12`: Compare the two clipboards with a 2-long substring-fingerprint (2-shingles) check, best match is reached at 1/(length1+length2).",
"* `jaccard12`: Compare the two clipboards the same way how `compare12` does but use the \"Jaccard similarity for bags\" algorithm, best match is reached at 0.",
"* `sql` *switch*: Set some outputs to be shown also as an SQL query if *switch* is `on`.",
"* `colors` *switch*: Show some outputs colored if *switch* is `on`.",
"* `tokens` *Bible* *book* *verse*: Search for the given *verse* in the given *book* in the given *Bible* (see command `lookup`), but the output is shown in a tokenized form. Tokenization is done via Strong's numbers.",
"* `help` *command*: Show some hints on usage of *command*, or get general help if no parameter is given.",
"* `quit`: Exit program."};
bool found = false;
for (int i = 0; i < helpStr.size(); i++) {
string helpText = helpStr[i];
if (helpText.length() >= 4 + commandLength && helpText.substr(3, rest.length()) == rest) {
info(helpText.substr(2)); // remove trailing "* "
found = true;
}
}
if (!found) {
error("Command `" + rest + "` is not supported.");
string commands_flattened = commands[0];
for (int i = 1; i < commands.size(); i++) {
commands_flattened += ", " + commands[i];
}
error("Available commands are: " + commands_flattened + ".");
}
return;
}
#ifdef __EMSCRIPTEN__
showAvailableBibles();
#endif
Expand Down Expand Up @@ -761,11 +808,11 @@ string cli_process(char *buf) {
processAddbooksCmd();
else if (input.compare(quitCmd) == 0)
processQuitCmd();
else if (input.compare(helpCmd) == 0)
processHelpCmd();
// Commands with some parameters...
// TODO: This list is not ordered, it should be listed alphabetically,
// or even better, an array could be defined to combine strings and functions.
else if (boost::starts_with(input, helpCmd))
processHelpCmd(input);
else if (boost::starts_with(input, textCmd))
processTextCmd(input);
else if (boost::starts_with(input, searchCmd))
Expand Down
2 changes: 1 addition & 1 deletion snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bibref
base: core20
version: '2023Dec21'
version: '2024Feb13'
summary: A tool that helps discovering internal references in the Bible
icon: logo-Psalm40-192.png
description: |
Expand Down

0 comments on commit 19cd6c3

Please sign in to comment.