Search in sources :

Example 36 with BasicParser

use of org.apache.commons.cli.BasicParser in project atlas by apache.

the class HiveMetaStoreBridge method main.

public static void main(String[] args) {
    int exitCode = EXIT_CODE_FAILED;
    try {
        Options options = new Options();
        options.addOption("d", "database", true, "Database name");
        options.addOption("t", "table", true, "Table name");
        options.addOption("f", "filename", true, "Filename");
        options.addOption("failOnError", false, "failOnError");
        CommandLine cmd = new BasicParser().parse(options, args);
        boolean failOnError = cmd.hasOption("failOnError");
        String databaseToImport = cmd.getOptionValue("d");
        String tableToImport = cmd.getOptionValue("t");
        String fileToImport = cmd.getOptionValue("f");
        Configuration atlasConf = ApplicationProperties.get();
        String[] atlasEndpoint = atlasConf.getStringArray(ATLAS_ENDPOINT);
        if (atlasEndpoint == null || atlasEndpoint.length == 0) {
            atlasEndpoint = new String[] { DEFAULT_ATLAS_URL };
        }
        final AtlasClientV2 atlasClientV2;
        if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
            String[] basicAuthUsernamePassword = AuthenticationUtil.getBasicAuthenticationInput();
            atlasClientV2 = new AtlasClientV2(atlasEndpoint, basicAuthUsernamePassword);
        } else {
            UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
            atlasClientV2 = new AtlasClientV2(ugi, ugi.getShortUserName(), atlasEndpoint);
        }
        HiveMetaStoreBridge hiveMetaStoreBridge = new HiveMetaStoreBridge(atlasConf, new HiveConf(), atlasClientV2);
        if (StringUtils.isNotEmpty(fileToImport)) {
            File f = new File(fileToImport);
            if (f.exists() && f.canRead()) {
                BufferedReader br = new BufferedReader(new FileReader(f));
                String line = null;
                while ((line = br.readLine()) != null) {
                    String[] val = line.split(":");
                    if (ArrayUtils.isNotEmpty(val)) {
                        databaseToImport = val[0];
                        if (val.length > 1) {
                            tableToImport = val[1];
                        } else {
                            tableToImport = "";
                        }
                        hiveMetaStoreBridge.importHiveMetadata(databaseToImport, tableToImport, failOnError);
                    }
                }
                exitCode = EXIT_CODE_SUCCESS;
            } else {
                LOG.error("Failed to read the input file: " + fileToImport);
            }
        } else {
            hiveMetaStoreBridge.importHiveMetadata(databaseToImport, tableToImport, failOnError);
        }
        exitCode = EXIT_CODE_SUCCESS;
    } catch (ParseException e) {
        LOG.error("Failed to parse arguments. Error: ", e.getMessage());
        printUsage();
    } catch (Exception e) {
        LOG.error("Import failed", e);
    }
    System.exit(exitCode);
}
Also used : Options(org.apache.commons.cli.Options) AtlasClientV2(org.apache.atlas.AtlasClientV2) Configuration(org.apache.commons.configuration.Configuration) AtlasServiceException(org.apache.atlas.AtlasServiceException) ParseException(org.apache.commons.cli.ParseException) AtlasHookException(org.apache.atlas.hook.AtlasHookException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) BufferedReader(java.io.BufferedReader) HiveConf(org.apache.hadoop.hive.conf.HiveConf) FileReader(java.io.FileReader) ParseException(org.apache.commons.cli.ParseException) File(java.io.File) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 37 with BasicParser

use of org.apache.commons.cli.BasicParser in project core by jcryptool.

the class CommandEvaluator method evaluate.

public CommandEvaluator.EvaluationResult evaluate(String commandString) throws ParseException {
    if (commandString.contains("\n")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        String[] splitCommandStrings = commandString.split("((\\r\\n)|(\r)|(\n))");
        return evaluateMultiline(splitCommandStrings);
    }
    // $NON-NLS-1$
    int commandEnd = commandString.indexOf(" ");
    commandEnd = commandEnd > 0 ? commandEnd : commandString.length();
    String commandName = commandString.substring(0, commandEnd);
    String cleanCommandLine = commandString.trim();
    // $NON-NLS-1$
    String commandArgs = commandString.substring(commandEnd).trim();
    // $NON-NLS-1$
    StringBuilder result = new StringBuilder();
    Command command = commands.get(commandName);
    if (command != null) {
        CommandLine commandLine = null;
        if (isCallForShortHelp(cleanCommandLine)) {
            result.append(HelpCommand.getShortHelpFor(commandName, command, cleanCommandLine));
        } else if (isCallForDetailedHelp(cleanCommandLine)) {
            result.append(HelpCommand.getDetailedHelpFor(commandName, command, cleanCommandLine));
        } else
            try {
                String[] args = splitArgs(commandArgs);
                BasicParser parser = new BasicParser();
                commandLine = parser.parse(command.createOptions(), args);
                command.execute(commandLine);
                result.append(command.getResult());
            } catch (IllegalCommandException e) {
                result.append(e.getMessage());
            } catch (RuntimeException e) {
                result.append(Messages.CommandEvaluator_1);
                result.append(e.getLocalizedMessage());
            } catch (ParseException e) {
                // TODO only if it is a "help anormality"
                result.append(HelpCommand.getHelpForBadCommandCall(commandName, command, cleanCommandLine, e));
                return new EvaluationResult(result.toString(), ResultType.ERROR_SYNTAX);
            }
    } else {
        result.append(NLS.bind(Messages.CommandEvaluator_0, commandName));
    }
    return new EvaluationResult(result.toString(), ResultType.OK);
}
Also used : BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) Command(org.jcryptool.commands.core.Command) HelpCommand(org.jcryptool.commands.core.HelpCommand) IllegalCommandException(org.jcryptool.commands.core.api.IllegalCommandException) ParseException(org.apache.commons.cli.ParseException)

Example 38 with BasicParser

use of org.apache.commons.cli.BasicParser in project mm-dev by sbl-sdsc.

the class ArgLigandInteractions method getCommandLine.

private static CommandLine getCommandLine(String[] args) {
    Options options = new Options();
    options.addOption("h", "help", false, "help");
    options.addOption("o", "output-path", true, "path to output file");
    options.addOption("r", "resolution", true, "minimum resolution of structure");
    options.addOption("d", "distance-cutoff", true, "maximum distance for interactions");
    options.addOption("b", "b-factor-cutoff", true, "maximum normalized b-factor");
    options.addOption("min", "min-interactions", true, "minimum number of interactions");
    options.addOption("max", "max-interactions", true, "maximum number of interactions");
    options.addOption("w", "include-waters", false, "include water-water interactions");
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println("ERROR: invalid command line arguments: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ArgLigandInteractions.class.getSimpleName(), options);
        System.exit(-1);
    }
    if (cmd.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ArgLigandInteractions.class.getSimpleName(), options);
        System.exit(1);
    }
    return cmd;
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Example 39 with BasicParser

use of org.apache.commons.cli.BasicParser in project eol-globi-data by jhpoelen.

the class NanoPress method main.

public static void main(final String[] args) throws IOException {
    CommandLineParser parser = new BasicParser();
    Options options = new Options();
    Option inputOpt = new Option("i", "input", true, "location of neo4j db");
    options.addOption(inputOpt);
    inputOpt.setRequired(true);
    Option outputOpt = new Option("o", "output", true, "output location for nanopubs");
    options.addOption(outputOpt);
    outputOpt.setRequired(true);
    Option batchSize = new Option("b", "batchSize", true, "number of interaction to be indexed at once");
    options.addOption(batchSize);
    Option opt = new Option("n", "nanoOnly", false, "output location for nanopubs");
    options.addOption(opt);
    CommandLine cmdLine;
    try {
        cmdLine = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(NanoPress.class.getSimpleName(), options);
        System.exit(1);
        return;
    }
    String inputFilePath = cmdLine.getOptionValue("input");
    String outputFilePath = cmdLine.getOptionValue("output");
    LOG.info("reading from neo4j: [" + inputFilePath + "], writing nanopubs to [" + outputFilePath + "]");
    Map<String, String> config = MapUtil.stringMap("keep_logical_logs", "0M size", // , "cache_type", "none"
    "dump_configuration", "true");
    final GraphDatabaseService graphService = GraphService.getGraphService(inputFilePath, config);
    File pubDir = new File(outputFilePath);
    FileUtils.forceMkdir(pubDir);
    createLinkers(cmdLine, graphService, pubDir).forEach(LinkUtil::doTimedLink);
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) BasicParser(org.apache.commons.cli.BasicParser) Options(org.apache.commons.cli.Options) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) File(java.io.File)

Example 40 with BasicParser

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;
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) BasicParser(org.apache.commons.cli.BasicParser) RepositoryException(javax.jcr.RepositoryException) InvalidItemStateException(javax.jcr.InvalidItemStateException) CommandException(org.apache.jackrabbit.standalone.cli.CommandException) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException) BasicParser(org.apache.commons.cli.BasicParser) Parser(org.apache.commons.cli.Parser)

Aggregations

BasicParser (org.apache.commons.cli.BasicParser)53 CommandLine (org.apache.commons.cli.CommandLine)49 Options (org.apache.commons.cli.Options)38 CommandLineParser (org.apache.commons.cli.CommandLineParser)35 ParseException (org.apache.commons.cli.ParseException)33 HelpFormatter (org.apache.commons.cli.HelpFormatter)25 File (java.io.File)14 IOException (java.io.IOException)14 Option (org.apache.commons.cli.Option)11 ClientConfig (co.cask.cdap.client.config.ClientConfig)2 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 FileReader (java.io.FileReader)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 AtlasClientV2 (org.apache.atlas.AtlasClientV2)2 AtlasHookException (org.apache.atlas.hook.AtlasHookException)2 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)2