use of org.apache.commons.cli.BasicParser in project jackrabbit by apache.
the class JcrClient method run.
/**
* Run client
* @param args
* the arguments
*/
private void run(String[] args) {
try {
// parse arguments
Parser parser = new BasicParser();
org.apache.commons.cli.CommandLine cl = parser.parse(options, args);
// Set locale
this.setLocale(cl);
// Welcome message
System.out.println(bundle.getString("word.welcome"));
// check interactive mode
if (cl.hasOption("source")) {
this.runNonInteractive(cl);
} else {
this.runInteractive();
}
} catch (Exception e) {
HelpFormatter hf = new HelpFormatter();
hf.printHelp("jcrclient", options);
e.printStackTrace();
return;
}
}
use of org.apache.commons.cli.BasicParser in project cdap by caskdata.
the class CLIMain method main.
public static void main(String[] args) {
// disable logback logging
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.OFF);
final PrintStream output = System.out;
Options options = getOptions();
CLIMainArgs cliMainArgs = CLIMainArgs.parse(args, options);
CommandLineParser parser = new BasicParser();
try {
CommandLine command = parser.parse(options, cliMainArgs.getOptionTokens());
if (command.hasOption(HELP_OPTION.getOpt())) {
usage();
System.exit(0);
}
LaunchOptions launchOptions = LaunchOptions.builder().setUri(command.getOptionValue(URI_OPTION.getOpt(), getDefaultURI().toString())).setDebug(command.hasOption(DEBUG_OPTION.getOpt())).setVerifySSL(parseBooleanOption(command, VERIFY_SSL_OPTION, DEFAULT_VERIFY_SSL)).setAutoconnect(parseBooleanOption(command, AUTOCONNECT_OPTION, DEFAULT_AUTOCONNECT)).build();
String scriptFile = command.getOptionValue(SCRIPT_OPTION.getOpt(), "");
boolean hasScriptFile = command.hasOption(SCRIPT_OPTION.getOpt());
String[] commandArgs = cliMainArgs.getCommandTokens();
try {
ClientConfig clientConfig = ClientConfig.builder().setConnectionConfig(null).setDefaultReadTimeout(parseIntegerOption(command, TIMEOUT_OPTION, 60) * 1000).build();
final CLIConfig cliConfig = new CLIConfig(clientConfig, output, new AltStyleTableRenderer());
CLIMain cliMain = new CLIMain(launchOptions, cliConfig);
CLI cli = cliMain.getCLI();
if (!cliMain.tryAutoconnect(command)) {
System.exit(0);
}
CLIConnectionConfig connectionConfig = new CLIConnectionConfig(cliConfig.getClientConfig().getConnectionConfig(), cliConfig.getCurrentNamespace(), null);
cliMain.updateCLIPrompt(connectionConfig);
if (hasScriptFile) {
File script = cliMain.getFilePathResolver().resolvePathToFile(scriptFile);
if (!script.exists()) {
output.println("ERROR: Script file '" + script.getAbsolutePath() + "' does not exist");
System.exit(1);
}
List<String> scriptLines = Files.readLines(script, Charsets.UTF_8);
for (String scriptLine : scriptLines) {
output.print(cliMain.getPrompt(connectionConfig));
output.println(scriptLine);
cli.execute(scriptLine, output);
output.println();
}
} else if (commandArgs.length == 0) {
cli.startInteractiveMode(output);
} else {
cli.execute(Joiner.on(" ").join(commandArgs), output);
}
} catch (DisconnectedException e) {
output.printf("Couldn't reach the CDAP instance at '%s'.", e.getConnectionConfig().getURI().toString());
} catch (Exception e) {
e.printStackTrace(output);
}
} catch (ParseException e) {
output.println(e.getMessage());
usage();
}
}
use of org.apache.commons.cli.BasicParser in project cdap by caskdata.
the class CoprocessorBuildTool method main.
public static void main(final String[] args) throws ParseException {
Options options = new Options().addOption(new Option("h", "help", false, "Print this usage message.")).addOption(new Option("f", "force", false, "Overwrites any coprocessors that already exist."));
CommandLineParser parser = new BasicParser();
CommandLine commandLine = parser.parse(options, args);
String[] commandArgs = commandLine.getArgs();
// if help is an option, or if there isn't a single 'ensure' command, print usage and exit.
if (commandLine.hasOption("h") || commandArgs.length != 1 || !"check".equalsIgnoreCase(commandArgs[0])) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp(CoprocessorBuildTool.class.getName() + " check", "Checks that HBase coprocessors required by CDAP are loaded onto HDFS. " + "If not, the coprocessors are built and placed on HDFS.", options, "");
System.exit(0);
}
boolean overwrite = commandLine.hasOption("f");
CConfiguration cConf = CConfiguration.create();
Configuration hConf = HBaseConfiguration.create();
Injector injector = Guice.createInjector(new ConfigModule(cConf, hConf), // for LocationFactory
new PrivateModule() {
@Override
protected void configure() {
bind(FileContext.class).toProvider(FileContextProvider.class).in(Scopes.SINGLETON);
expose(LocationFactory.class);
}
@Provides
@Singleton
private LocationFactory providesLocationFactory(Configuration hConf, CConfiguration cConf, FileContext fc) {
final String namespace = cConf.get(Constants.CFG_HDFS_NAMESPACE);
if (UserGroupInformation.isSecurityEnabled()) {
return new FileContextLocationFactory(hConf, namespace);
}
return new InsecureFileContextLocationFactory(hConf, namespace, fc);
}
});
try {
SecurityUtil.loginForMasterService(cConf);
} catch (Exception e) {
LOG.error("Failed to login as CDAP user", e);
System.exit(1);
}
LocationFactory locationFactory = injector.getInstance(LocationFactory.class);
HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
CoprocessorManager coprocessorManager = new CoprocessorManager(cConf, locationFactory, tableUtil);
try {
Location location = coprocessorManager.ensureCoprocessorExists(overwrite);
LOG.info("coprocessor exists at {}.", location);
} catch (IOException e) {
LOG.error("Unable to build and upload coprocessor jars.", e);
System.exit(1);
}
}
Aggregations