use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.
the class OConsoleApplication method help.
@ConsoleCommand(splitInWords = false, description = "Receives help on available commands or a specific one. Use 'help -online <cmd>' to fetch online documentation")
public void help(@ConsoleParameter(name = "command", description = "Command to receive help") String iCommand) {
if (iCommand == null || iCommand.trim().isEmpty()) {
// GENERIC HELP
message("\nAVAILABLE COMMANDS:\n");
for (Method m : getConsoleMethods().keySet()) {
ConsoleCommand annotation = m.getAnnotation(ConsoleCommand.class);
if (annotation == null)
continue;
message("* %-85s%s\n", getCorrectMethodName(m), annotation.description());
}
message("* %-85s%s\n", getClearName("exit"), "Close the console");
return;
}
final String[] commandWords = OStringParser.getWords(iCommand, wordSeparator);
boolean onlineMode = commandWords.length > 1 && commandWords[0].equalsIgnoreCase("-online");
if (onlineMode)
iCommand = iCommand.substring("-online".length() + 1);
final Method m = getMethod(iCommand);
if (m != null) {
final ConsoleCommand ann = m.getAnnotation(ConsoleCommand.class);
message("\nCOMMAND: " + iCommand + "\n\n");
if (ann != null) {
// FETCH ONLINE CONTENT
if (onlineMode && !ann.onlineHelp().isEmpty()) {
// try {
final String text = getOnlineHelp(ONLINE_HELP_URL + ann.onlineHelp() + ONLINE_HELP_EXT);
if (text != null && !text.isEmpty()) {
message(text);
// ONLINE FETCHING SUCCEED: RETURN
return;
}
// } catch (Exception e) {
// }
error("!CANNOT FETCH ONLINE DOCUMENTATION, CHECK IF COMPUTER IS CONNECTED TO THE INTERNET.");
return;
}
message(ann.description() + "." + "\r\n\r\nSYNTAX: ");
// IN ANY CASE DISPLAY INFORMATION BY READING ANNOTATIONS
message(formatCommandSpecs(iCommand, m));
} else
message("No description available");
}
}
use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.
the class OGremlinConsole method exportDatabase.
@Override
@ConsoleCommand(description = "Export a database", splitInWords = false, onlineHelp = "Console-Command-Export")
public void exportDatabase(@ConsoleParameter(name = "options", description = "Export options") String iText) throws IOException {
checkForDatabase();
final List<String> items = OStringSerializerHelper.smartSplit(iText, ' ');
final String fileName = items.size() <= 1 || items.get(1).charAt(0) == '-' ? null : items.get(1);
if (fileName != null && (fileName.endsWith(".graphml") || fileName.endsWith(".xml"))) {
message("\nExporting database in GRAPHML format to " + iText + "...");
try {
final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(currentDatabase);
g.setUseLog(false);
g.setWarnOnForceClosingTx(false);
// CREATE THE EXPORT FILE IF NOT EXIST YET
final File f = new File(fileName);
if (f.getParentFile() != null) {
f.getParentFile().mkdirs();
}
f.createNewFile();
new GraphMLWriter(g).outputGraph(fileName);
} catch (ODatabaseImportException e) {
printError(e);
}
} else
// BASE EXPORT
super.exportDatabase(iText);
}
use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method configGet.
@ConsoleCommand(description = "Return the value of a configuration value")
public void configGet(@ConsoleParameter(name = "config-name", description = "Name of the configuration") final String iConfigName) throws IOException {
final OGlobalConfiguration config = OGlobalConfiguration.findByKey(iConfigName);
if (config == null)
throw new IllegalArgumentException("Configuration variable '" + iConfigName + "' wasn't found");
final String value;
if (serverAdmin != null) {
value = serverAdmin.getGlobalConfiguration(config);
message("\nRemote configuration: ");
} else {
value = config.getValueAsString();
message("\nLocal configuration: ");
}
out.println(iConfigName + " = " + value);
}
use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method importDatabase.
@ConsoleCommand(description = "Import a database into the current one", splitInWords = false, onlineHelp = "Console-Command-Import")
public void importDatabase(@ConsoleParameter(name = "options", description = "Import options") final String text) throws IOException {
checkForDatabase();
message("\nImporting database " + text + "...");
final List<String> items = OStringSerializerHelper.smartSplit(text, ' ');
final String fileName = items.size() <= 0 || (items.get(1)).charAt(0) == '-' ? null : items.get(1);
final String options = fileName != null ? text.substring((items.get(0)).length() + (items.get(1)).length() + 1).trim() : text;
try {
if (currentDatabase.getStorage().isRemote()) {
ODatabaseImportRemote databaseImport = new ODatabaseImportRemote(currentDatabase, fileName, this);
databaseImport.setOptions(options);
databaseImport.importDatabase();
databaseImport.close();
} else {
ODatabaseImport databaseImport = new ODatabaseImport(currentDatabase, fileName, this);
databaseImport.setOptions(options);
databaseImport.importDatabase();
databaseImport.close();
}
} catch (ODatabaseImportException e) {
printError(e);
}
}
use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method repairDatabase.
@ConsoleCommand(description = "Repair database structure")
public void repairDatabase(@ConsoleParameter(name = "options", description = "Options: -v", optional = true) final String iOptions) throws IOException {
checkForDatabase();
message("\nRepairing database...");
boolean verbose = iOptions != null && iOptions.contains("-v");
new ODatabaseRepair().setDatabase(currentDatabase).setOutputListener(new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
message(iText);
}
}).setVerbose(verbose).run();
}
Aggregations