use of org.apache.commons.cli2.CommandLine in project jackrabbit-filevault by apache.
the class AbstractApplication method run.
protected void run(String[] args) {
// setup and start
init();
Parser parser = new Parser();
parser.setGroup(getApplicationCLGroup());
parser.setHelpOption(optHelp);
try {
CommandLine cl = parser.parse(args);
String logLevel = getEnv().getProperty(KEY_LOGLEVEL);
if (cl.hasOption(optLogLevel)) {
logLevel = (String) cl.getValue(optLogLevel);
}
if (logLevel != null) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
// overwrite level of configuration file
ch.qos.logback.classic.Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(Level.toLevel(logLevel));
}
prepare(cl);
execute(cl);
} catch (OptionException e) {
log.error("{}. Type --help for more information.", e.getMessage());
} catch (ExecutionException e) {
log.error("Error while starting: {}", e.getMessage());
} finally {
close();
}
}
use of org.apache.commons.cli2.CommandLine in project jackrabbit-filevault by apache.
the class ExecutionContext method execute.
public boolean execute(String[] args) {
Parser parser = new Parser();
parser.setHelpFormatter(getCmdHelpFormatter(null));
parser.setGroup(getCommandsGroup());
CommandLine cl = parser.parseAndHelp(args);
return cl != null && execute(cl);
}
use of org.apache.commons.cli2.CommandLine in project Practical-Machine-Learning by PacktPublishing.
the class InputDriver method main.
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
ArgumentBuilder abuilder = new ArgumentBuilder();
GroupBuilder gbuilder = new GroupBuilder();
Option inputOpt = DefaultOptionCreator.inputOption().withRequired(false).create();
Option outputOpt = DefaultOptionCreator.outputOption().withRequired(false).create();
Option vectorOpt = obuilder.withLongName("vector").withRequired(false).withArgument(abuilder.withName("v").withMinimum(1).withMaximum(1).create()).withDescription("The vector implementation to use.").withShortName("v").create();
Option helpOpt = DefaultOptionCreator.helpOption();
Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt).withOption(vectorOpt).withOption(helpOpt).create();
try {
Parser parser = new Parser();
parser.setGroup(group);
CommandLine cmdLine = parser.parse(args);
if (cmdLine.hasOption(helpOpt)) {
CommandLineUtil.printHelp(group);
return;
}
Path input = new Path(cmdLine.getValue(inputOpt, "testdata").toString());
Path output = new Path(cmdLine.getValue(outputOpt, "output").toString());
String vectorClassName = cmdLine.getValue(vectorOpt, "org.apache.mahout.math.RandomAccessSparseVector").toString();
// runJob(input, output, vectorClassName);
} catch (OptionException e) {
InputDriver.log.error("Exception parsing command line: ", e);
CommandLineUtil.printHelp(group);
}
}
use of org.apache.commons.cli2.CommandLine in project jackrabbit-filevault by apache.
the class Test method main.
public static void main(String[] args) throws Exception {
final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
final ArgumentBuilder abuilder = new ArgumentBuilder();
final CommandBuilder cbuilder = new CommandBuilder();
final GroupBuilder gbuilder = new GroupBuilder();
Option recursive = obuilder.withShortName("r").withLongName("recursive").withDescription("do recursively").create();
Command update = cbuilder.withName("update").withName("up").withDescription("update the work directory").create();
Option projecthelp = obuilder.withShortName("projecthelp").withShortName("p").withDescription("print project help information").create();
Option version = obuilder.withShortName("v").withDescription("print the version information and exit").create();
Group options = gbuilder.withName("Global options:").withOption(projecthelp).withOption(version).withMinimum(0).create();
Option command = abuilder.withName("command").withMinimum(1).withMaximum(1).create();
Option targets = abuilder.withName("arg").create();
CliCommand exit = new org.apache.jackrabbit.vault.util.console.commands.CmdExit();
CliCommand help = new org.apache.jackrabbit.vault.util.console.commands.CmdHelp();
CliCommand setenv = new org.apache.jackrabbit.vault.util.console.commands.CmdSet();
Group commands = gbuilder.withName("Commands:").withOption(help.getCommand()).withOption(exit.getCommand()).withOption(setenv.getCommand()).withOption(update).withMinimum(0).withMaximum(1).create();
Group main = gbuilder.withName("").withOption(options).withOption(commands).withMinimum(0).create();
HelpFormatter hf = new HelpFormatter();
StringBuffer sep = new StringBuffer(hf.getPageWidth());
while (sep.length() < hf.getPageWidth()) {
sep.append("-");
}
hf.setHeader("File Vault version 1.0");
hf.setDivider(sep.toString());
hf.setShellCommand("vlt [options] <command> [arg1 [arg2 [arg3] ..]]");
hf.setGroup(main);
// hf.setHeader("bla bla version vla");
// displayHelp();
hf.getFullUsageSettings().removeAll(DisplaySetting.ALL);
// hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
// hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_CHILDREN);
// hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_OPTIONAL);
hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
hf.getDisplaySettings().add(DisplaySetting.DISPLAY_OPTIONAL);
// hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
// hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
// hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_GROUP_NAME);
// hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
// hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
// hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
// hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
// hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
Parser parser = new Parser();
parser.setHelpFormatter(hf);
parser.setGroup(main);
System.out.println(main);
CommandLine cl = parser.parseAndHelp(args);
if (cl != null) {
if (exit.execute(null, cl)) {
System.out.println("exit executed");
} else if (help.execute(null, cl)) {
System.out.println("help executed.");
} else {
hf.print();
}
}
}
use of org.apache.commons.cli2.CommandLine in project jackrabbit-filevault by apache.
the class CmdSync method doExecute.
protected void doExecute(VaultFsApp app, CommandLine cl) throws Exception {
Sync.Command cmd = (Sync.Command) cl.getValue(argCommand);
if (cmd == null) {
cmd = Sync.Command.INIT;
}
String root = (String) cl.getValue(optUri);
RepositoryAddress addr = root == null ? null : new RepositoryAddress(root);
String localPath = (String) cl.getValue(argLocalPath);
File localFile = app.getPlatformFile(localPath == null ? "." : localPath, false).getCanonicalFile();
VltContext vCtx = app.createVaultContext(localFile);
vCtx.setVerbose(cl.hasOption(OPT_VERBOSE));
vCtx.setQuiet(cl.hasOption(OPT_QUIET));
Sync sc = new Sync(cmd, addr, localFile);
sc.setForce(cl.hasOption(optForce));
vCtx.execute(sc);
}
Aggregations