Package org.apache.commons.cli

Examples of org.apache.commons.cli.CommandLine


        .withDescription("access token").create(TOKEN_OPTION));
    options.addOption(OptionBuilder.withArgName("string").hasArg()
        .withDescription("runtag").create(RUNTAG_OPTION));
    options.addOption(new Option(VERBOSE_OPTION, "print out complete document"));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
      cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
      System.err.println("Error parsing command line: " + exp.getMessage());
      System.exit(-1);
    }

    if (!cmdline.hasOption(HOST_OPTION) || !cmdline.hasOption(PORT_OPTION)
        || !cmdline.hasOption(QUERIES_OPTION)) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp(RunQueriesThrift.class.getName(), options);
      System.exit(-1);
    }

    String queryFile = cmdline.getOptionValue(QUERIES_OPTION);
    if (!new File(queryFile).exists()) {
      System.err.println("Error: " + queryFile + " doesn't exist!");
      System.exit(-1);
    }

    String runtag = cmdline.hasOption(RUNTAG_OPTION) ?
        cmdline.getOptionValue(RUNTAG_OPTION) : DEFAULT_RUNTAG;

    TrecTopicSet topicsFile = TrecTopicSet.fromFile(new File(queryFile));

    int numResults = 1000;
    try {
      if (cmdline.hasOption(NUM_RESULTS_OPTION)) {
        numResults = Integer.parseInt(cmdline.getOptionValue(NUM_RESULTS_OPTION));
      }
    } catch (NumberFormatException e) {
      System.err.println("Invalid " + NUM_RESULTS_OPTION + ": " + cmdline.getOptionValue(NUM_RESULTS_OPTION));
      System.exit(-1);
    }

    String group = cmdline.hasOption(GROUP_OPTION) ? cmdline.getOptionValue(GROUP_OPTION) : null;
    String token = cmdline.hasOption(TOKEN_OPTION) ? cmdline.getOptionValue(TOKEN_OPTION) : null;

    boolean verbose = cmdline.hasOption(VERBOSE_OPTION);

    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    TrecSearchThriftClient client = new TrecSearchThriftClient(cmdline.getOptionValue(HOST_OPTION),
        Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)), group, token);

    for (cc.twittertools.search.TrecTopic query : topicsFile) {
      List<TResult> results = client.search(query.getQuery(),
          query.getQueryTweetTime(), numResults);
      int i = 1;
View Full Code Here


        .withDescription("access token").create(TOKEN_OPTION));
    options.addOption(OptionBuilder.withArgName("string").hasArg()
        .withDescription("runtag").create(RUNTAG_OPTION));
    options.addOption(new Option(VERBOSE_OPTION, "print out complete document"));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
      cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
      System.err.println("Error parsing command line: " + exp.getMessage());
      System.exit(-1);
    }

    if (!cmdline.hasOption(HOST_OPTION) || !cmdline.hasOption(PORT_OPTION)
        || !cmdline.hasOption(QUERIES_OPTION)) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp(RunQueriesThrift.class.getName(), options);
      System.exit(-1);
    }

    String queryFile = cmdline.getOptionValue(QUERIES_OPTION);
    if (!new File(queryFile).exists()) {
      System.err.println("Error: " + queryFile + " doesn't exist!");
      System.exit(-1);
    }

    String runtag = cmdline.hasOption(RUNTAG_OPTION) ?
        cmdline.getOptionValue(RUNTAG_OPTION) : DEFAULT_RUNTAG;

    TrecTopicSet topicsFile = TrecTopicSet.fromFile(new File(queryFile));

    int numResults = 1000;
    try {
      if (cmdline.hasOption(NUM_RESULTS_OPTION)) {
        numResults = Integer.parseInt(cmdline.getOptionValue(NUM_RESULTS_OPTION));
      }
    } catch (NumberFormatException e) {
      System.err.println("Invalid " + NUM_RESULTS_OPTION + ": " + cmdline.getOptionValue(NUM_RESULTS_OPTION));
      System.exit(-1);
    }

    String group = cmdline.hasOption(GROUP_OPTION) ? cmdline.getOptionValue(GROUP_OPTION) : null;
    String token = cmdline.hasOption(TOKEN_OPTION) ? cmdline.getOptionValue(TOKEN_OPTION) : null;

    boolean verbose = cmdline.hasOption(VERBOSE_OPTION);

    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    TrecSearchThriftClient client = new TrecSearchThriftClient(cmdline.getOptionValue(HOST_OPTION),
        Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)), group, token);

    for(cc.twittertools.search.TrecTopic query : topicsFile) {
      List<TResult> results = client.search(query.getQuery(),
          query.getQueryTweetTime(), numResults);
View Full Code Here

    public static void main(String[] args) throws Exception {
  Options options = new Options();
  options.addOption(OptionBuilder.withArgName("path").hasArg()
        .withDescription("HTML file from twitter.com").create(HTML_OPTION));
 
  CommandLine cmdline = null;
  CommandLineParser parser = new GnuParser();
  try {
      cmdline = parser.parse(options, args);
  } catch (ParseException exp) {
      System.err.println("Error parsing command line: " + exp.getMessage());
      System.exit(-1);
  }
 
  if (!cmdline.hasOption(HTML_OPTION)) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp(HTMLStatusExtractor.class.getName(), options);
      System.exit(-1);
  }
 
  String html_filename = cmdline.getOptionValue(HTML_OPTION);
  BufferedReader html_file = null;
  StringBuffer buf = new StringBuffer();
  try {
      html_file = new BufferedReader(new InputStreamReader(new FileInputStream(html_filename)));
      String line;
View Full Code Here

    option = new Option("t", "graphite-port",  true, "Graphite server port");
    options.addOption(option);

    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;
    try {
      commandLine = parser.parse(options, args);
    }
    catch(ParseException exception) {
      System.err.println(exception.getMessage());
      System.err.println("Usage: " + PushBot.class + " ARGS");
      System.err.println("  -n,--name                IRC Nick of the Bot");
      System.err.println("  -c,--channels            Comma delimited list of channels to join");
      System.err.println("  -h,--irc-host            IRCD hostname");
      System.err.println("  -p,--irc-port            IRCD port");
      System.err.println("  -a,--irc-passwod         Optional IRCD server password");
      System.err.println("  -g,--graphite-enabled    Enable graphite logging");
      System.err.println("  -r,--graphite-host       Graphite hostname");
      System.err.println("  -t,--graphite-port       Graphite port");
      System.exit(1);
    }

    List<String> channels = new LinkedList<String>();
    for(String channel : commandLine.getOptionValue('c').split("/\\s*,\\s*/")) {
      channels.add(channel);
    }

    // Build PushBot
    PushBot pushBot =
      new PushBot(commandLine.getOptionValue('n'),
          channels,
          commandLine.hasOption('g'),
          commandLine.getOptionValue('r', null),
          Integer.valueOf(commandLine.getOptionValue('t', "2003")));

    // Connect to IRCD
    pushBot.connect(
        commandLine.getOptionValue('h'),
        Integer.valueOf(commandLine.getOptionValue('p')),
        commandLine.getOptionValue('a', null));

    // Launch the web interface
    ConfigServer configServer = new ConfigServer(pushBot);
  }
View Full Code Here

     * @param args              not used
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        Options options = getOptions();
        CommandLine cmd = null;
        CommandLineParser parser = new GnuParser();
        try {
            cmd = parser.parse(options, args);
        } catch (ParseException pe) {
            LOG.error(pe.getMessage());
            printHelp(options);
            System.exit(-1);
        }

        if (cmd.hasOption(HELP_OPTION)) {
            printHelp(options);
            System.exit(0);
        }

        String indexPath = cmd.getOptionValue(INDEX_PATH_OPTION, DEFAULT_INDEX_DIRECTORY);
        String[] gazetteerPaths = cmd.getOptionValues(GAZETTEER_FILES_OPTION);
        if (gazetteerPaths == null || gazetteerPaths.length == 0) {
            gazetteerPaths = DEFAULT_GAZETTEER_FILES;
        }
        boolean replaceIndex = cmd.hasOption(REPLACE_INDEX_OPTION);
        boolean fullAncestry = cmd.hasOption(FULL_ANCESTRY_OPTION);

        File idir = new File(indexPath);
        // if the index directory exists, delete it if we are replacing, otherwise
        // exit gracefully
        if (idir.exists() ) {
            if (replaceIndex) {
                LOG.info("Replacing index: {}", idir.getAbsolutePath());
                FileUtils.deleteDirectory(idir);
            } else {
                LOG.info("{} exists. Remove the directory and try again.", idir.getAbsolutePath());
                System.exit(-1);
            }
        }

        List<File> gazetteerFiles = new ArrayList<File>();
        for (String gp : gazetteerPaths) {
            File gf = new File(gp);
            if (gf.isFile() && gf.canRead()) {
                gazetteerFiles.add(gf);
            } else {
                LOG.info("Unable to read Gazetteer file: {}", gf.getAbsolutePath());
            }
        }
        if (gazetteerFiles.isEmpty()) {
            LOG.error("No Gazetteer files found.");
            System.exit(-1);
        }

        String altNamesPath = cmd.getOptionValue(ALTERNATE_NAMES_OPTION);
        File altNamesFile = altNamesPath != null ? new File(altNamesPath) : null;
        if (altNamesFile != null && !(altNamesFile.isFile() && altNamesFile.canRead())) {
            LOG.error("Unable to read alternate names file: {}", altNamesPath);
            System.exit(-1);
        }
View Full Code Here

    opts.addOption(null, "default-notebook", true, "file name to find default notebook");
    opts.addOption(null, "plugin-option", true, "pass option on to plugin");
    opts.addOption(null, "public-server", false, "allow connections from external computers");
    opts.addOption(null, "no-password", false, "do not require a password from external connections " +
                   "(warning: for advanced users only!)");
    CommandLine line = parser.parse(opts, args);
    if (line.hasOption("help")) {
      new HelpFormatter().printHelp("beaker.command", opts);
      System.exit(0);
    }
    return line;
  }
View Full Code Here

    }
    return result;
  }

  public static void main(String[] args) throws Exception {
    CommandLine options = parseCommandLine(args);

    final Integer portBase = options.hasOption("port-base") ?
      Integer.parseInt(options.getOptionValue("port-base")) : findPortBase(PORT_BASE_START_DEFAULT);
    final Boolean useKerberos = options.hasOption("disable-kerberos") ?
      !parseBoolean(options.getOptionValue("disable-kerberos")) : USE_KERBEROS_DEFAULT;
    final Boolean openBrowser = options.hasOption("open-browser") ?
      parseBoolean(options.getOptionValue("open-browser")) : OPEN_BROWSER_DEFAULT;
    final Boolean useHttps = options.hasOption("use-https") ?
      parseBoolean(options.getOptionValue("use-https")) : USE_HTTPS_DEFAULT;
    final Boolean publicServer = options.hasOption("public-server");

    // create preferences for beaker core from cli options and others
    // to be used by BeakerCoreConfigModule to initialize its config
    BeakerConfigPref beakerCorePref = createBeakerCoreConfigPref(
        useKerberos,
        publicServer,
        false,
        portBase,
        options.getOptionValue("default-notebook"),
        getPluginOptions(options));

    WebAppConfigPref webAppPref = createWebAppConfigPref(
        portBase + BEAKER_SERVER_PORT_OFFSET,
        System.getProperty("user.dir") + "/src/main/web");
View Full Code Here

        options.addOption("f", "theme-folder", true,
                "the folder containing the theme");
        options.addOption("v", "version", true,
                "the Vaadin version to compile for");
        CommandLineParser parser = new PosixParser();
        CommandLine params = parser.parse(options, args);
        if (!params.hasOption("theme") || !params.hasOption("theme-folder")
                || !params.hasOption("version")) {
            // automatically generate the help statement
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(CompileTheme.class.getName(), options);
            return;
        }
        String themeName = params.getOptionValue("theme");
        String themeFolder = params.getOptionValue("theme-folder");
        String version = params.getOptionValue("version");

        // Regular theme
        try {
            processSassTheme(themeFolder, themeName, "styles", version);
            System.out.println("Compiling theme " + themeName
View Full Code Here

    try {
      System.out.println(args[0]);

      CommandLineParser parser = new PosixParser();
      CommandLine line = parser.parse(options, args);

      if (line.hasOption("cassandrahostip")) {
        CountandraUtils.setCassandraHostIp(line
            .getOptionValue("cassandrahostip"));
        if (line.hasOption("consistencylevel")) {
          if (line.hasOption("replicationfactor")) {

            CassandraStorage.setGlobalParams(
                line.getOptionValue("cassandrahostip"),
                line.getOptionValue("consistencylevel"));
            CassandraDB.setGlobalParams(
                line.getOptionValue("cassandrahostip"),
                line.getOptionValue("replicationfactor"));

          } else {

            CassandraStorage.setGlobalParams(
                line.getOptionValue("cassandrahostip"),
                line.getOptionValue("consistencylevel"));
            CassandraDB.setGlobalParams(line
                .getOptionValue("cassandrahostip"));

          }
        }

        else { // no consistency level -- assumed to be ONE
          if (line.hasOption("replicationfactor")) {

            CassandraStorage.setGlobalParams(line
                .getOptionValue("cassandrahostip"));
            CassandraDB.setGlobalParams(
                line.getOptionValue("cassandrahostip"),
                line.getOptionValue("replicationfactor"));

          } else {

            CassandraStorage.setGlobalParams(line
                .getOptionValue("cassandrahostip"));
            CassandraDB.setGlobalParams(line
                .getOptionValue("cassandrahostip"));

          }
        }
      } else {
        CassandraStorage.setGlobalParams(cassandraServerForClient);
        CassandraDB.setGlobalParams(cassandraServerForClient);
      }

      if (line.hasOption("s")) {
        System.out.println("Starting Cassandra");
        // cassandra server
        CassandraUtils.startupCassandraServer();

      }
      if (line.hasOption("i")) {
        System.out.print("Checking if Cassandra is initialized");
        CassandraDB csdb = new CassandraDB();
        while (!csdb.isCassandraUp()) {
          System.out.print(".");
        }
        System.out.println(".");
        System.out.println("Initializing Basic structures");
        CountandraUtils.initBasicDataStructures();
        System.out.println("Initialized Basic structures");

      }

      if (line.hasOption("h")) {

        if (line.hasOption("httpserverport")) {
          httpPort = Integer.parseInt(line
              .getOptionValue("httpserverport"));
        }
        NettyUtils.startupNettyServer(httpPort);
        System.out.println("Started Http Server");
      }


      if (line.hasOption("k")) {

          KafkaUtils.startupKafkaConsumer();
          System.out.println("Started Kafka Consumer");
      }

      // Unit Tests
      if (line.hasOption("t")) {
        try {
          Thread.sleep(30000);
        } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
View Full Code Here

      printUsage();
      return;
    }
   
    CommandLineParser parser = new PosixParser();
    CommandLine cmd;

    try {
      cmd = parser.parse(options, args);
    } catch (ParseException e) {
      System.out.println("Error parsing command-line options: ");
      printUsage();
      return;
    }

    if(cmd.hasOption("h")) { // print help and exit
      printUsage();
      return;
    }

    boolean skipBlocks = cmd.hasOption("skipBlocks");
    boolean printToScreen = cmd.hasOption("printToScreen");
    String inputFile = cmd.getOptionValue("i");
    String processor = cmd.getOptionValue("p", "Ls");
    String outputFile = cmd.getOptionValue("o");
    String delimiter = cmd.getOptionValue("delimiter");
   
    if( !(delimiter == null || processor.equals("Delimited")) ) {
      System.out.println("Can only specify -delimiter with Delimited processor");
      printUsage();
      return;
    }
   
    ImageVisitor v;
    if(processor.equals("Indented")) {
      v = new IndentedImageVisitor(outputFile, printToScreen);
    } else if (processor.equals("XML")) {
      v = new XmlImageVisitor(outputFile, printToScreen);
    } else if (processor.equals("Delimited")) {
      v = delimiter == null
                 new DelimitedImageVisitor(outputFile, printToScreen) :
                 new DelimitedImageVisitor(outputFile, printToScreen, delimiter);
      skipBlocks = false;
    } else if (processor.equals("FileDistribution")) {
      long maxSize = Long.parseLong(cmd.getOptionValue("maxSize", "0"));
      int step = Integer.parseInt(cmd.getOptionValue("step", "0"));
      v = new FileDistributionVisitor(outputFile, maxSize, step);
    } else {
      v = new LsImageVisitor(outputFile, printToScreen);
      skipBlocks = false;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.cli.CommandLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.