use of org.apache.commons.cli.ParseException in project Krill by KorAP.
the class Indexer method main.
/**
* Main method.
*
* @param argv
* Argument list,
* expecting the properties file
* and a list of directories
* @throws IOException
*/
public static void main(String[] argv) throws IOException {
Options options = new Options();
options.addOption(Option.builder("c").longOpt("config").desc("configuration file (defaults to " + KrillProperties.defaultPropertiesLocation + ").").hasArg().argName("properties file").required().build());
options.addOption(Option.builder("i").longOpt("inputDir").desc("input directories separated by semicolons. The input files " + "have to be in <filename>.json.gz format. ").hasArgs().argName("input directories").required().valueSeparator(new Character(';')).build());
options.addOption(Option.builder("o").longOpt("outputDir").desc("index output directory (defaults to " + "krill.indexDir in the configuration.").hasArg().argName("output directory").build());
CommandLineParser parser = new DefaultParser();
String propFile = null;
String[] inputDirectories = null;
try {
CommandLine cmd = parser.parse(options, argv);
log.info("Configuration file: " + cmd.getOptionValue("c"));
propFile = cmd.getOptionValue("c");
log.info("Input directories: " + StringUtils.join(cmd.getOptionValues("i"), ";"));
inputDirectories = cmd.getOptionValues("i");
if (cmd.hasOption("o")) {
log.info("Output directory: " + cmd.getOptionValue("o"));
path = cmd.getOptionValue("o");
}
} catch (MissingOptionException e) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("Krill indexer\n java -jar -c <properties file> -i <input directories> " + "[-o <output directory>]", options);
return;
} catch (ParseException e) {
log.error("Unexpected error: " + e);
e.printStackTrace();
}
// Load properties
Properties prop = KrillProperties.loadProperties(propFile);
// Get indexer object
Indexer indexer = new Indexer(prop);
// Iterate over list of directories
for (String arg : inputDirectories) {
log.info("Indexing files in " + arg);
File f = new File(arg);
if (f.isDirectory())
indexer.parse(f);
}
indexer.closeIndex();
// Final commit
log.info("Finished indexing.");
// Finish indexing
String message = "Indexed " + indexer.count + " file";
if (indexer.count > 1) {
message += "s";
}
System.out.print(message + ".");
}
use of org.apache.commons.cli.ParseException in project openmeetings by apache.
the class Admin method process.
// package private wrapper for testing
void process(String... args) throws Exception {
CommandLineParser parser = new DefaultParser();
try {
cmdl = parser.parse(opts, args);
} catch (ParseException e) {
log(e.getMessage());
usage();
throw new ExitException();
}
verbose = cmdl.hasOption('v');
Command cmd = Command.usage;
if (cmdl.hasOption('i')) {
cmd = Command.install;
} else if (cmdl.hasOption('b')) {
cmd = Command.backup;
} else if (cmdl.hasOption('r')) {
cmd = Command.restore;
} else if (cmdl.hasOption('f')) {
cmd = Command.files;
} else if (cmdl.hasOption('l')) {
cmd = Command.ldap;
}
String file = cmdl.getOptionValue("file", "");
switch(cmd) {
case install:
step = "Install";
processInstall(file);
break;
case backup:
step = "Backup";
processBackup(file);
break;
case restore:
step = "Restore";
processRestore(checkRestoreFile(file));
break;
case files:
step = "Files";
processFiles();
break;
case ldap:
step = "LDAP import";
processLdap();
break;
case usage:
default:
usage();
break;
}
}
use of org.apache.commons.cli.ParseException in project ff4j by ff4j.
the class FF4jCliProcessor method processCommandUpdateProperty.
private void processCommandUpdateProperty(String commandLine) {
try {
CommandLine cmd = CMD_PARSER.parse(propertyOptions(), commandLine.split(" "));
if (cmd.getArgList().size() != 1 || !cmd.hasOption("p") || !cmd.hasOption("v")) {
logError("Invalid command, expecting update -p <property> -v <value>");
} else {
String property = cmd.getOptionValue('p');
String value = cmd.getOptionValue('v');
if (!currentFF4J.getPropertiesStore().existProperty(property)) {
logWarn("Property " + property + " does not exist, nothing to update");
} else {
currentFF4J.getPropertiesStore().updateProperty(property, value);
logInfo("Property " + property + " has been updated with " + value);
}
}
} catch (ParseException e) {
error(e, "parsing error during update property command");
} catch (Exception e) {
error(e, "Cannot update property");
}
}
use of org.apache.commons.cli.ParseException in project ff4j by ff4j.
the class FF4jCliProcessor method processCommandAddGroup.
private void processCommandAddGroup(String commandLine) {
try {
CommandLine cmd = CMD_PARSER.parse(addGroupOptions(), commandLine.split(" "));
if (cmd.getArgList().size() != 1 || !cmd.hasOption("f") || !cmd.hasOption("g")) {
logError("Invalid command, expecting addToGroup[removeFromGroup] -f <featureName> -g <grouName>");
} else {
String feature = cmd.getOptionValue('f');
String group = cmd.getOptionValue('g');
if (!currentFF4J.getFeatureStore().exist(feature)) {
logWarn("Feature does not exist, nothing updated");
} else {
if (cmd.getArgList().get(0).equals("addToGroup")) {
currentFF4J.getFeatureStore().addToGroup(feature, group);
logInfo(FEATURE + feature + " has been added to group " + group);
} else if (cmd.getArgList().get(0).equals("removeFromGroup")) {
String currentGroup = currentFF4J.getFeatureStore().read(feature).getGroup();
if (group.equals(currentGroup)) {
currentFF4J.getFeatureStore().removeFromGroup(feature, group);
logInfo(FEATURE + feature + " has been removed from group: " + group);
} else if (currentGroup == null || currentGroup.isEmpty()) {
logWarn("The groupName is invalid expected:" + currentGroup + " but was [" + group + "]");
} else {
logWarn("Cannot remove group: there are no group on this feature");
}
}
}
}
} catch (ParseException e) {
error(e, "Error during addToGroup/removeFromGroup command");
}
}
use of org.apache.commons.cli.ParseException in project java-jotasync by trixon.
the class Main method main.
/**
* @param args the command line arguments
* @throws java.rmi.RemoteException
*/
public static void main(String[] args) throws RemoteException {
SystemHelper.enableRmiServer();
Options options = initOptions();
CommandLineParser parser = new DefaultParser();
try {
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption(Main.OPT_HELP)) {
displayHelp(options);
} else if (cmd.hasOption(OPT_VERSION)) {
displayVersion();
} else {
Client client = new Client(cmd);
}
} catch (ParseException ex) {
Xlog.timedErr(ex.getMessage());
System.out.println(sBundle.getString("parse_help_client"));
}
}
Aggregations