Package org.apache.commons.cli

Examples of org.apache.commons.cli.CommandLine


    msg("cmd=" + cmd);
    return cmd;
  }

  void parseArgv(){
    CommandLine cmdLine = null;
    try{
      cmdLine = parser.parse(allOptions, argv_);
    }catch(Exception oe){
      LOG.error(oe.getMessage());
      exitUsage(argv_.length > 0 && "-info".equals(argv_[0]));
    }
   
    if (cmdLine != null){
      verbose_ =  cmdLine.hasOption("verbose");
      detailedUsage_ = cmdLine.hasOption("info");
      debug_ = cmdLine.hasOption("debug")? debug_ + 1 : debug_;
     
      String[] values = cmdLine.getOptionValues("input");
      if (values != null && values.length > 0) {
        for (String input : values) {
          inputSpecs_.add(input);
        }
      }
      output_ = (String) cmdLine.getOptionValue("output");
     
      mapCmd_ = (String)cmdLine.getOptionValue("mapper");
      comCmd_ = (String)cmdLine.getOptionValue("combiner");
      redCmd_ = (String)cmdLine.getOptionValue("reducer");
     
      values = cmdLine.getOptionValues("file");
      if (values != null && values.length > 0) {
        StringBuilder unpackRegex = new StringBuilder(
          config_.getPattern(JobContext.JAR_UNPACK_PATTERN,
                             JobConf.UNPACK_JAR_PATTERN_DEFAULT).pattern());
        for (String file : values) {
          packageFiles_.add(file);
          String fname = new File(file).getName();
          unpackRegex.append("|(?:").append(Pattern.quote(fname)).append(")");
        }
        config_.setPattern(JobContext.JAR_UNPACK_PATTERN,
                           Pattern.compile(unpackRegex.toString()));
        validate(packageFiles_);
      }

        
      String fsName = (String)cmdLine.getOptionValue("dfs");
      if (null != fsName){
        LOG.warn("-dfs option is deprecated, please use -fs instead.");
        config_.set("fs.default.name", fsName);
      }
     
      additionalConfSpec_ = (String)cmdLine.getOptionValue("additionalconfspec");
      inputFormatSpec_ = (String)cmdLine.getOptionValue("inputformat");
      outputFormatSpec_ = (String)cmdLine.getOptionValue("outputformat");
      numReduceTasksSpec_ = (String)cmdLine.getOptionValue("numReduceTasks");
      partitionerSpec_ = (String)cmdLine.getOptionValue("partitioner");
      inReaderSpec_ = (String)cmdLine.getOptionValue("inputreader");
      mapDebugSpec_ = (String)cmdLine.getOptionValue("mapdebug");   
      reduceDebugSpec_ = (String)cmdLine.getOptionValue("reducedebug");
      ioSpec_ = (String)cmdLine.getOptionValue("io");
     
      String[] car = cmdLine.getOptionValues("cacheArchive");
      if (null != car && car.length > 0){
        LOG.warn("-cacheArchive option is deprecated, please use -archives instead.");
        for(String s : car){
          cacheArchives = (cacheArchives == null)?s :cacheArchives + "," + s; 
        }
      }

      String[] caf = cmdLine.getOptionValues("cacheFile");
      if (null != caf && caf.length > 0){
        LOG.warn("-cacheFile option is deprecated, please use -files instead.");
        for(String s : caf){
          cacheFiles = (cacheFiles == null)?s :cacheFiles + "," + s; 
        }
      }
     
      String[] jobconf = cmdLine.getOptionValues("jobconf");
      if (null != jobconf && jobconf.length > 0){
        LOG.warn("-jobconf option is deprecated, please use -D instead.");
        for(String s : jobconf){
          String []parts = s.split("=", 2);
          config_.set(parts[0], parts[1]);
        }
      }
     
      String[] cmd = cmdLine.getOptionValues("cmdenv");
      if (null != cmd && cmd.length > 0){
        for(String s : cmd) {
          if (addTaskEnvironment_.length() > 0) {
            addTaskEnvironment_ += " ";
          }
View Full Code Here


    options.addOption(OptionBuilder
        .withLongOpt(OPT_NUM_APPENDS).hasArg()
        .withDescription("number of appends per thread")
        .create());
    CommandLineParser parser = new GnuParser();
    CommandLine line;
    try {
      line = parser.parse( options, args );
      if (line.getArgs().length != 0) {
        throw new ParseException("Unexpected options");
      }
    } catch (ParseException pe) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp("TestFileAppend2", options);
      throw pe;
    }
           
    TestFileAppend2 tfa2 = new TestFileAppend2();
    tfa2.numDatanodes = Integer.parseInt(
        line.getOptionValue(OPT_NUM_DNS, "1"));
    tfa2.numThreads = Integer.parseInt(
        line.getOptionValue(OPT_NUM_THREADS, "30"));
    tfa2.numberOfFiles = Integer.parseInt(
        line.getOptionValue(OPT_NUM_FILES, "1"));
    tfa2.numAppendsPerThread = Integer.parseInt(
        line.getOptionValue(OPT_NUM_APPENDS, "1000"));
   
    // Make workload more aggressive
    tfa2.sleepBetweenSizeChecks = 10;
  
    try {
View Full Code Here

   * @return true on successful parse; false to indicate that the
   * program should exit.
   */
  private boolean parseArguments(String[] args) {
    Options options = makeOptions();
    CommandLine cli;
    try {
      CommandLineParser parser = new GnuParser();
      cli = parser.parse(options, args);
    } catch(ParseException e) {
      LOG.warn("options parsing failed:  "+e.getMessage());
      new HelpFormatter().printHelp("...", options);
      return false;
    }

    if (cli.hasOption("help")) {
      new HelpFormatter().printHelp("...", options);
      return false;
    }
    if (cli.getArgs().length > 0) {
      for (String arg : cli.getArgs()) {
        System.err.println("Unrecognized option: " + arg);
        new HelpFormatter().printHelp("...", options);
        return false;
      }
    }

    // MR
    noMR = cli.hasOption("nomr");
    numTaskTrackers = intArgument(cli, "tasktrackers", 1);
    jobTrackerPort = intArgument(cli, "jobtrackerport", 0);
    taskTrackerPort = intArgument(cli, "tasktrackerport", 0);
    fs = cli.getOptionValue("namenode");

    useLoopBackHosts = cli.hasOption("useloopbackhosts");

    // HDFS
    noDFS = cli.hasOption("nodfs");
    numDataNodes = intArgument(cli, "datanodes", 1);
    nameNodePort = intArgument(cli, "nnport", 0);
    dfsOpts = cli.hasOption("format") ?
        StartupOption.FORMAT : StartupOption.REGULAR;

    // Runner
    writeDetails = cli.getOptionValue("writeDetails");
    writeConfig = cli.getOptionValue("writeConfig");

    // General
    conf = new JobConf();
    updateConfiguration(conf, cli.getOptionValues("D"));
   
    return true;
  }
View Full Code Here

  static final public void main(String args[]) {
    String port;
    Server server;
    SocketConnector connector;
    CommandLine cmd = null;
    CommandLineParser parser = new PosixParser();
    Options o = new Options();

    BasicConfigurator.configure();

    o.addOption("p", true, "port");
    try {
      cmd = parser.parse(o, args);
    }
    catch (ParseException exp ) {
      System.err.println( "Parsing failed.  Reason: " + exp.getMessage() );
      System.exit(-1);
    }

    port = cmd.getOptionValue("p");
    if(port == null) port = "8083";
    connector = new SocketConnector();
    connector.setPort(new Integer(port));
    connector.setHost("127.0.0.1");
    server = new Server();
View Full Code Here

        }
    }

    private static boolean start(String[] args) throws Exception {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(OPTIONS, args);
        String output = cmd.getOptionValue(OPT_OUTPUT.getOpt());
        String className = cmd.getOptionValue(OPT_CLASS.getOpt());
        String packageName = cmd.getOptionValue(OPT_PACKAGE.getOpt());
        String hadoopWork = cmd.getOptionValue(OPT_HADOOPWORK.getOpt());
        String compilerWork = cmd.getOptionValue(OPT_COMPILERWORK.getOpt());
        String link = cmd.getOptionValue(OPT_LINK.getOpt());
        String plugin = cmd.getOptionValue(OPT_PLUGIN.getOpt());

        File outputDirectory = new File(output);
        Location hadoopWorkLocation = Location.fromPath(hadoopWork, '/');
        File compilerWorkDirectory = new File(compilerWork);
        List<File> linkingResources = Lists.create();
View Full Code Here

    static Configuration parseConfiguration(String[] args) throws ParseException {
        assert args != null;
        LOG.debug("Analyzing WindGateAbort bootstrap arguments: {}", Arrays.toString(args));

        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(OPTIONS, args);

        String profile = cmd.getOptionValue(OPT_PROFILE.getOpt());
        LOG.debug("WindGate profile: {}", profile);
        String sessionId = cmd.getOptionValue(OPT_SESSION_ID.getOpt());
        LOG.debug("WindGate sessionId: {}", sessionId);
        String plugins = cmd.getOptionValue(OPT_PLUGIN.getOpt());
        LOG.debug("WindGate plugin: {}", plugins);

        LOG.debug("Loading plugins: {}", plugins);
        List<File> pluginFiles = CommandLineUtil.parseFileList(plugins);
        ClassLoader loader = CommandLineUtil.buildPluginLoader(WindGateAbort.class.getClassLoader(), pluginFiles);
View Full Code Here

    static Configuration parseConfiguration(String[] args) throws ParseException {
        assert args != null;
        LOG.debug("Analyzing WindGate bootstrap arguments: {}", Arrays.toString(args));

        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(OPTIONS, args);

        String mode = cmd.getOptionValue(OPT_MODE.getOpt());
        LOG.debug("WindGate mode: {}", mode);
        String profile = cmd.getOptionValue(OPT_PROFILE.getOpt());
        LOG.debug("WindGate profile: {}", profile);
        String script = cmd.getOptionValue(OPT_SCRIPT.getOpt());
        LOG.debug("WindGate script: {}", script);
        String sessionId = cmd.getOptionValue(OPT_SESSION_ID.getOpt());
        LOG.debug("WindGate sessionId: {}", sessionId);
        String plugins = cmd.getOptionValue(OPT_PLUGIN.getOpt());
        LOG.debug("WindGate plugin: {}", plugins);
        String arguments = cmd.getOptionValue(OPT_ARGUMENTS.getOpt());
        LOG.debug("WindGate arguments: {}", arguments);

        LOG.debug("Loading plugins: {}", plugins);
        List<File> pluginFiles = CommandLineUtil.parseFileList(plugins);
        ClassLoader loader = CommandLineUtil.buildPluginLoader(WindGate.class.getClassLoader(), pluginFiles);
View Full Code Here

        }
    }

    private static void start(String[] args) throws Exception {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(OPTIONS, args);
        String sourcePath = cmd.getOptionValue(OPT_SOURCEPATH.getOpt());
        String output = cmd.getOptionValue(OPT_OUTPUT.getOpt());
        String encoding = cmd.getOptionValue(OPT_ENCODING.getOpt(), "UTF-8");
        String[] classes = cmd.getOptionValues(OPT_CLASSES.getOpt());

        List<Class<?>> operatorClasses = Lists.create();
        for (String className : classes) {
            Class<?> oc = Class.forName(className);
            operatorClasses.add(oc);
View Full Code Here

        }
    }

    private static boolean start(String[] args) throws Exception {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(OPTIONS, args);
        String output = cmd.getOptionValue(OPT_OUTPUT.getOpt());
        String scanPath = cmd.getOptionValue(OPT_SCANPATH.getOpt());
        String packageName = cmd.getOptionValue(OPT_PACKAGE.getOpt());
        String hadoopWork = cmd.getOptionValue(OPT_HADOOPWORK.getOpt());
        String compilerWork = cmd.getOptionValue(OPT_COMPILERWORK.getOpt());
        String link = cmd.getOptionValue(OPT_LINK.getOpt());
        String plugin = cmd.getOptionValue(OPT_PLUGIN.getOpt());
        boolean skipError = cmd.hasOption(OPT_SKIPERROR.getOpt());

        File outputDirectory = new File(output);
        Location hadoopWorkLocation = Location.fromPath(hadoopWork, '/');
        File compilerWorkDirectory = new File(compilerWork);
        List<File> linkingResources = Lists.create();
View Full Code Here

    Options options = new Options();
    options.addOption("p", "port", true, "bind port");
    options.addOption("b", "base", true, "base path");
   
    try {
      CommandLine cl = new PosixParser().parse(options, args);
     
      int port = 8080;
      if (cl.hasOption('p')) {
        port = Integer.parseInt(cl.getOptionValue('p'));
      }
      String basePath = "src/main";
      if (cl.hasOption('b')) {
        basePath = cl.getOptionValue('b');
      }
     
      StandaloneServer server = new StandaloneServer(port);
      server.setBasePath(basePath);
      server.start();
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.