Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.exist.client.CommandlineOptions Maven / Gradle / Ivy
/*
* eXist-db Open Source Native XML Database
* Copyright (C) 2001 The eXist-db Authors
*
* [email protected]
* http://www.exist-db.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.exist.client;
import java.io.File;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.*;
import org.exist.xmldb.XmldbURI;
import org.exist.xquery.util.URIUtils;
import se.softhouse.jargo.*;
import static org.exist.util.ArgumentUtil.*;
import static se.softhouse.jargo.Arguments.*;
/**
* Command Line Options for the {@link InteractiveClient}
*
* @author Adam Retter
* @author wessels
*/
public class CommandlineOptions {
/* general arguments */
private static final Argument> helpArg = helpArgument("-h", "--help");
private static final Argument quietArg = optionArgument("-q", "--quiet")
.description("be quiet. Just print errors.")
.defaultValue(false)
.build();
private static final Argument verboseArg = optionArgument("-v", "--verbose")
.description("be verbose. Display progress information on put.")
.defaultValue(false)
.build();
private static final Argument outputFileArg = fileArgument("-O", "--output")
.description("write output of command into given file (use with -x, -g).")
.build();
private static final Argument> optionArg = stringArgument("-o", "--option")
.description("specify extra options: property=value. For available properties see client.properties.")
.asKeyValuesWithKeyParser(StringParsers.stringParser())
.build();
/* database connection arguments */
private static final Argument userArg = stringArgument("-u", "--user")
.description("set username.")
.defaultValue(null)
.build();
private static final Argument passwordArg = stringArgument("-P", "--password")
.description("specify password.")
.build();
private static final Argument useSslArg = optionArgument("-S", "--use-ssl")
.description("Use SSL by default for remote connections")
.defaultValue(false)
.build();
private static final Argument embeddedArg = optionArgument("-l", "--local")
.description("launch a local database instance. Otherwise client will connect to URI specified in client.properties.")
.defaultValue(false)
.build();
private static final Argument embeddedConfigArg = fileArgument("-C", "--config")
.description("specify alternate configuration file. Implies -l.")
.build();
private static final Argument noEmbeddedModeArg = optionArgument("-N", "--no-embedded-mode")
.description("do not make embedded mode available")
.defaultValue(false)
.build();
/* gui arguments */
private static final Argument noGuiArg = optionArgument("-s", "--no-gui")
.description("don't start client with GUI. Just use the shell.")
.defaultValue(false)
.build();
private static final Argument guiQueryDialogArg = optionArgument("-Q", "--query")
.description("directly open the query gui")
.defaultValue(false)
.build();
/* mk/rm/set collection arguments */
private static final Argument mkColArg = stringArgument("-m", "--mkcol")
.description("create a collection (and any missing parent collection). Implies -c.")
.build();
private static final Argument rmColArg = stringArgument("-R", "--rmcol")
.description("remove entire collection")
.build();
private static final Argument setColArg = stringArgument("-c", "--collection")
.description("set target collection.")
.build();
/* put/get/rm document arguments */
private static final Argument> parseDocsArg = fileArgument("-p", "--parse")
.description("store files or directories given as extra args on command line.")
.variableArity()
.build();
private static final Argument getDocArg = stringArgument("-g", "--get")
.description("retrieve a document.")
.build();
private static final Argument rmDocArg = stringArgument("-r", "--remove")
.description("remove a document.")
.build();
/* query arguments */
public static final String XPATH_STDIN = "< xpathArg = stringArgument("-x", "--xpath")
.description("execute XPath query given as argument. Without argument reads query from stdin.")
.build();
private static final Argument> loadQueriesArg = fileArgument("-F", "--file")
.description("load queries from file and execute in random order.")
.variableArity()
.build();
private static final Argument howManyResultsArg = integerArgument("-n", "--howmany")
.description("max. number of query results to be displayed.")
.build();
private static final Argument traceQueriesArg = fileArgument("-T", "--trace")
.description("log queries to the file specified by the argument (for debugging).")
.build();
/* xupdate arguments */
private static final Argument setDocArg = stringArgument("-f", "--resource")
.description("specify a resource contained in the current collection. Use in conjunction with --xupdate to specify the resource to update.")
.build();
private static final Argument xupdateArg = fileArgument("-X", "--xupdate")
.description("process XUpdate commands. Commands are read from the file specified in the argument.")
.build();
/* reindex arguments */
private static final Argument reindexArg = optionArgument("-i", "--reindex")
.description("reindex the collection specified in the collection argument --collection")
.defaultValue(false)
.build();
private static final Argument reindexRecurseDirsArg = optionArgument("-d", "--recurse-dirs")
.description("recurse into subdirectories during index?")
.defaultValue(false)
.build();
private static Optional optUri(final ParsedArguments parsedArguments, final Argument argument) throws URISyntaxException {
final Optional uriStr = getOpt(parsedArguments, argument);
if (uriStr.isPresent()) {
return Optional.of(URIUtils.encodeXmldbUriFor(uriStr.get()));
} else {
return Optional.empty();
}
}
public static CommandlineOptions parse(final String[] args) throws ArgumentException, URISyntaxException {
final ParsedArguments arguments = CommandLineParser
.withArguments(userArg, passwordArg, useSslArg, embeddedArg, embeddedConfigArg, noEmbeddedModeArg)
.andArguments(noGuiArg, guiQueryDialogArg)
.andArguments(mkColArg, rmColArg, setColArg)
.andArguments(parseDocsArg, getDocArg, rmDocArg)
.andArguments(xpathArg, loadQueriesArg, howManyResultsArg, traceQueriesArg)
.andArguments(setDocArg, xupdateArg)
.andArguments(reindexArg, reindexRecurseDirsArg)
.andArguments(helpArg, quietArg, verboseArg, outputFileArg, optionArg)
.parse(args);
final boolean quiet = getBool(arguments, quietArg);
final boolean verbose = getBool(arguments, verboseArg);
final Optional outputFile = getPathOpt(arguments, outputFileArg);
final Map options = arguments.get(optionArg);
final Optional username = getOpt(arguments, userArg);
final Optional password = getOpt(arguments, passwordArg);
final boolean useSSL = getBool(arguments, useSslArg);
final boolean embedded = getBool(arguments, embeddedArg);
final Optional embeddedConfig = getPathOpt(arguments, embeddedConfigArg);
final boolean noEmbeddedMode = getBool(arguments, noEmbeddedModeArg);
final boolean startGUI = !getBool(arguments, noGuiArg);
final boolean openQueryGUI = getBool(arguments, guiQueryDialogArg);
final Optional mkCol = optUri(arguments, mkColArg);
final Optional rmCol = optUri(arguments, rmColArg);
final Optional setCol = optUri(arguments, setColArg);
final List parseDocs = getPathsOpt(arguments, parseDocsArg);
final Optional getDoc = optUri(arguments, getDocArg);
final Optional rmDoc = getOpt(arguments, rmDocArg);
final Optional maybeXpath = getOpt(arguments, xpathArg);
final Optional xpath;
if(maybeXpath.isPresent()) {
if(maybeXpath.get().isEmpty()) {
xpath = Optional.of(XPATH_STDIN);
} else {
xpath = maybeXpath;
}
} else {
xpath = Optional.empty();
}
final List queryFiles = getPathsOpt(arguments, loadQueriesArg);
final Optional howManyResults = getOpt(arguments, howManyResultsArg);
final Optional traceQueriesFile = getPathOpt(arguments, traceQueriesArg);
final Optional setDoc = getOpt(arguments, setDocArg);
final Optional xupdateFile = getPathOpt(arguments, xupdateArg);
final boolean reindex = getBool(arguments, reindexArg);
final boolean reindexRecurse = getBool(arguments, reindexRecurseDirsArg);
return new CommandlineOptions(
quiet,
verbose,
outputFile,
options,
username,
password,
useSSL,
embedded,
embeddedConfig,
noEmbeddedMode,
startGUI,
openQueryGUI,
mkCol,
rmCol,
setCol,
parseDocs,
getDoc,
rmDoc,
xpath,
queryFiles,
howManyResults,
traceQueriesFile,
setDoc,
xupdateFile,
reindex,
reindexRecurse
);
}
public CommandlineOptions(boolean quiet, boolean verbose, Optional outputFile, Map options, Optional username, Optional password, boolean useSSL, boolean embedded, Optional embeddedConfig, boolean noEmbeddedMode, boolean startGUI, boolean openQueryGUI, Optional mkCol, Optional rmCol, Optional setCol, List parseDocs, Optional getDoc, Optional rmDoc, Optional xpath, List queryFiles, Optional howManyResults, Optional traceQueriesFile, Optional setDoc, Optional xupdateFile, boolean reindex, boolean reindexRecurse) {
this.quiet = quiet;
this.verbose = verbose;
this.outputFile = outputFile;
this.options = options;
this.username = username;
this.password = password;
this.useSSL = useSSL;
this.embedded = embedded;
this.embeddedConfig = embeddedConfig;
this.noEmbeddedMode = noEmbeddedMode;
this.startGUI = startGUI;
this.openQueryGUI = openQueryGUI;
this.mkCol = mkCol;
this.rmCol = rmCol;
this.setCol = setCol;
this.parseDocs = parseDocs;
this.getDoc = getDoc;
this.rmDoc = rmDoc;
this.xpath = xpath;
this.queryFiles = queryFiles;
this.howManyResults = howManyResults;
this.traceQueriesFile = traceQueriesFile;
this.setDoc = setDoc;
this.xupdateFile = xupdateFile;
this.reindex = reindex;
this.reindexRecurse = reindexRecurse;
}
final boolean quiet;
final boolean verbose;
final Optional outputFile;
final Map options;
final Optional username;
final Optional password;
final boolean useSSL;
final boolean embedded;
final Optional embeddedConfig;
final boolean noEmbeddedMode;
final boolean startGUI;
final boolean openQueryGUI;
final Optional mkCol;
final Optional rmCol;
final Optional setCol;
final List parseDocs;
final Optional getDoc;
final Optional rmDoc;
final Optional xpath;
final List queryFiles;
final Optional howManyResults;
final Optional traceQueriesFile;
final Optional setDoc;
final Optional xupdateFile;
final boolean reindex;
final boolean reindexRecurse;
}