Skip to content

Commit

Permalink
[ADD] CLI, -O: set option (name=value)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianGruen committed Sep 17, 2024
1 parent 7995203 commit f48a371
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 52 deletions.
10 changes: 7 additions & 3 deletions basex-core/src/main/java/org/basex/BaseX.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public BaseX(final String... args) throws IOException {
out = new PrintOutput(new IOFile(value));
session().setOutputStream(out);
break;
case 'O':
String[] kv = value.split("=", 2);
execute(new Set(kv[0], kv.length > 1 ? kv[1] : ""), false);
break;
case 'q':
console = false;
execute(new XQuery(value), verbose);
Expand All @@ -118,7 +122,7 @@ public BaseX(final String... args) throws IOException {
break;
case 's':
if(sopts == null) sopts = new SerializerOptions();
final String[] kv = value.split("=", 2);
kv = value.split("=", 2);
sopts.assign(kv[0], kv.length > 1 ? kv[1] : "");
execute(new Set(MainOptions.SERIALIZER, sopts), false);
break;
Expand Down Expand Up @@ -215,8 +219,8 @@ protected final void parseArgs() throws IOException {
if(c == 'd') {
// activate debug mode
Prop.debug = true;
} else if(c == 'b' || c == 'c' || c == 'C' || c == 'i' || c == 'I' || c == 'o' ||
c == 'q' || c == 'Q' || c == 'r' || c == 's' || c == 't' && local()) {
} else if(c == 't' && local() || c == 'b' || c == 'c' || c == 'C' || c == 'i' || c == 'I' ||
c == 'o' || c == 'O' || c == 'q' || c == 'Q' || c == 'r' || c == 's') {
// options followed by a string
v = arg.string();
} else if(c == 'D' && local() || c == 'u' && local() || c == 'R' ||
Expand Down
100 changes: 51 additions & 49 deletions basex-core/src/main/java/org/basex/core/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,63 +86,65 @@ public interface Text {
String S_STANDALONE = "Standalone";
/** Start information. */
String S_LOCALINFO =
" [-bcCdiIoqQrRstuvVwWxz] [input]" + NL +
" [input] XQuery or command file, or query string" + NL +
" -b<args> Bind external query variables" + NL +
" -c<input> Execute commands from file or string" + NL +
" -C<file> Execute command script file" + NL +
" -d Toggle debugging output" + NL +
" -i<input> Bind file or database to context" + NL +
" -I<input> Bind input string to context" + NL +
" -o<path> Write output to local file" + NL +
" -q<expr> Execute XQuery expression" + NL +
" -Q<file> Execute XQuery file" + NL +
" -r<num> Run query multiple times" + NL +
" -R Toggle query execution" + NL +
" -s<args> Set serialization parameters" + NL +
" -t[path] Run tests in file or directory" + NL +
" -u Toggle updates in original files" + NL +
" -v Toggle output of progress info" + NL +
" -V Toggle detailed query output" + NL +
" -w Toggle whitespace stripping" + NL +
" -W Enable indentation with whitespace" + NL +
" -x Toggle output of query plan" + NL +
" -z Toggle output of query result";
" [options...] [input]" + NL +
" [input] XQuery or command file, or query string" + NL +
" -b<var> Bind query variable (name=value)" + NL +
" -c<input> Execute commands from file or string" + NL +
" -C<file> Execute command script file" + NL +
" -d Toggle debugging output" + NL +
" -i<input> Bind file or database to context" + NL +
" -I<input> Bind input string to context" + NL +
" -o<path> Write output to local file" + NL +
" -O<option> Set option (name=value)" + NL +
" -q<expr> Execute XQuery expression" + NL +
" -Q<file> Execute XQuery file" + NL +
" -r<num> Run query multiple times" + NL +
" -R Toggle query execution" + NL +
" -s<param> Set serialization parameter (name=value)" + NL +
" -t[path] Run tests in file or directory" + NL +
" -u Toggle updates in original files" + NL +
" -v Toggle output of progress info" + NL +
" -V Toggle detailed query output" + NL +
" -w Toggle whitespace stripping" + NL +
" -W Enable indentation with whitespace" + NL +
" -x Toggle output of query plan" + NL +
" -z Toggle output of query result";

/** Client mode. */
String S_CLIENT = "Client";
/** Client start information. */
String S_CLIENTINFO =
" [-bcCdiInopPqQrRsUvVwWxz] [input]" + NL +
" [input] XQuery or command file, or query string" + NL +
" -b<args> Bind external query variables" + NL +
" -c<input> Execute commands from file or string" + NL +
" -C<file> Execute command script file" + NL +
" -d Toggle debugging output" + NL +
" -i<input> Bind file or database to context" + NL +
" -I<input> Bind input string to context" + NL +
" -n<name> Set server (host) name" + NL +
" -o<path> Write output to local file" + NL +
" -p<port> Set server port" + NL +
" -P<pass> Specify user password" + NL +
" -q<expr> Execute XQuery expression" + NL +
" -Q<file> Execute XQuery file" + NL +
" -r<num> Run query multiple times" + NL +
" -R Toggle query execution" + NL +
" -s<args> Set serialization parameters" + NL +
" -U<name> Specify username" + NL +
" -v Toggle output of progress info" + NL +
" -V Toggle detailed query output" + NL +
" -w Toggle whitespace stripping" + NL +
" -W Enable indentation with whitespace" + NL +
" -x Toggle output of query plan" + NL +
" -z Toggle output of query result";
" [options...] [input]" + NL +
" [input] XQuery or command file, or query string" + NL +
" -b<var> Bind query variable (name=value)" + NL +
" -c<input> Execute commands from file or string" + NL +
" -C<file> Execute command script file" + NL +
" -d Toggle debugging output" + NL +
" -i<input> Bind file or database to context" + NL +
" -I<input> Bind input string to context" + NL +
" -n<name> Set server (host) name" + NL +
" -o<path> Write output to local file" + NL +
" -O<option> Set option (name=value)" + NL +
" -p<port> Set server port" + NL +
" -P<pass> Specify user password" + NL +
" -q<expr> Execute XQuery expression" + NL +
" -Q<file> Execute XQuery file" + NL +
" -r<num> Run query multiple times" + NL +
" -R Toggle query execution" + NL +
" -s<param> Set serialization parameter (name=value)" + NL +
" -U<name> Specify username" + NL +
" -v Toggle output of progress info" + NL +
" -V Toggle detailed query output" + NL +
" -w Toggle whitespace stripping" + NL +
" -W Enable indentation with whitespace" + NL +
" -x Toggle output of query plan" + NL +
" -z Toggle output of query result";

/** Server mode. */
String S_SERVER = "Server";
/** Server start information. */
String S_SERVERINFO =
" [-cCdnpSz] [stop]" + NL +
" [options...] [stop]" + NL +
" stop Stop running server" + NL +
" -c<input> Execute commands from file or string" + NL +
" -C<file> Execute command script file" + NL +
Expand All @@ -156,15 +158,15 @@ public interface Text {
String S_GUI = "GUI";
/** GUI start information. */
String S_GUIINFO =
" [-d] [files]" + NL +
" [options...] [files...]" + NL +
" [files] Open specified files" + NL +
" -d Enable debugging";

/** HTTP server mode. */
String S_HTTP_SERVER = "HTTP Server";
/** HTTP information. */
String S_HTTPINFO =
" [-cCdghlnpsSUz] [stop]" + NL +
" [options...] [stop]" + NL +
" stop Stop running server" + NL +
" -c<input> Execute commands from file or string" + NL +
" -C<file> Execute command script file" + NL +
Expand Down
17 changes: 17 additions & 0 deletions basex-core/src/test/java/org/basex/BaseXTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ public abstract class BaseXTest extends SandboxTest {
equals("<a/>", "-w", "-i" + INPUT, "-q.");
}

/**
* Test options flag.
* @throws IOException I/O exception
*/
@Test public void options() throws IOException {
equals("", "-Oserialize=false", "-q1");
equals("", "-Oserialize=no", "-q1");
equals("", "-Oserialize=0", "-q1");

equals("1", "-Oserialize=true", "-q1");
equals("1", "-Oserialize=yes", "-q1");
equals("1", "-Oserialize=1", "-q1");

equals("", "-Oserialize=", "-q1");
equals("1", "-Oserialize=", "-Oserialize=", "-q1");
}

/**
* Turn off serialization.
* @throws IOException I/O exception
Expand Down

0 comments on commit f48a371

Please sign in to comment.