Package org.apache.commons.cli

Examples of org.apache.commons.cli.CommandLine


      options.addOption(optTargetFile);
      options.addOption(optLogLevel);
      options.addOption(optChangeUser);
     
      CommandLineParser parser = new GnuParser();
      CommandLine line=null;
      try{
        line = parser.parse(options, args);
      } catch(Exception e){
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("cronconverter", options, true);
        System.exit(0);
      }
     
      sourceFile = getWholeArgument(line.getOptionValues("crontab"));
      if (sourceFile.equalsIgnoreCase("/etc/crontab")) sysTab = true;
      targetFile = getWholeArgument(line.getOptionValues("target"));
     
      String ll = line.getOptionValue("v", ""+SOSStandardLogger.INFO);
      logLevel = Integer.parseInt(ll);
      if (line.hasOption(optSysTab.getOpt())){
        sysTab =(line.getOptionValue(optSysTab.getOpt()).trim().equals("1"));
      }   
      useOldRunTime = line.hasOption("oldRunTime");
      changeUser = "";
      if (line.hasOption("changeuser")){
        changeUser = getWholeArgument(line.getOptionValues("changeuser"));
      }     
           
      jobTimeout = line.getOptionValue("timeout");
      if (logLevel==0) logLevel=SOSLogger.INFO;
      sosLogger = new SOSStandardLogger(logLevel);     
           
      target = new File(targetFile);
      source = new File(sourceFile);
View Full Code Here


    options.addOption("p", "port", true, "Port to bind to [default: 8080]");
    options.addOption("ro", "readonly", false, "Respond only to GET HTTP " +
      "method requests [default: false]");
    options.addOption(null, "infoport", true, "Port for web UI");

    CommandLine commandLine = null;
    try {
      commandLine = new PosixParser().parse(options, args);
    } catch (ParseException e) {
      LOG.error("Could not parse: ", e);
      printUsageAndExit(options, -1);
    }

    // check for user-defined port setting, if so override the conf
    if (commandLine != null && commandLine.hasOption("port")) {
      String val = commandLine.getOptionValue("port");
      servlet.getConfiguration()
          .setInt("hbase.rest.port", Integer.valueOf(val));
      LOG.debug("port set to " + val);
    }

    // check if server should only process GET requests, if so override the conf
    if (commandLine != null && commandLine.hasOption("readonly")) {
      servlet.getConfiguration().setBoolean("hbase.rest.readonly", true);
      LOG.debug("readonly set to true");
    }

    // check for user-defined info server port setting, if so override the conf
    if (commandLine != null && commandLine.hasOption("infoport")) {
      String val = commandLine.getOptionValue("infoport");
      servlet.getConfiguration()
          .setInt("hbase.rest.info.port", Integer.valueOf(val));
      LOG.debug("Web UI port set to " + val);
    }

    @SuppressWarnings("unchecked")
    List<String> remainingArgs = commandLine != null ?
        commandLine.getArgList() : new ArrayList<String>();
    if (remainingArgs.size() != 1) {
      printUsageAndExit(options, 1);
    }

    String command = remainingArgs.get(0);
View Full Code Here

        ImplType.THREAD_POOL.simpleClassName());

    options.addOptionGroup(ImplType.createOptionGroup());

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

    // This is so complicated to please both bin/hbase and bin/hbase-daemon.
    // hbase-daemon provides "start" and "stop" arguments
    // hbase should print the help if no argument is provided
    List<String> commandLine = Arrays.asList(args);
    boolean stop = commandLine.contains("stop");
    boolean start = commandLine.contains("start");
    boolean invalidStartStop = (start && stop) || (!start && !stop);
    if (cmd.hasOption("help") || invalidStartStop) {
      if (invalidStartStop) {
        LOG.error("Exactly one of 'start' and 'stop' has to be specified");
      }
      printUsageAndExit(options, 1);
    }

    // Get port to bind to
    try {
      int listenPort = Integer.parseInt(cmd.getOptionValue(PORT_OPTION,
          String.valueOf(DEFAULT_LISTEN_PORT)));
      conf.setInt(ThriftServerRunner.PORT_CONF_KEY, listenPort);
    } catch (NumberFormatException e) {
      LOG.error("Could not parse the value provided for the port option", e);
      printUsageAndExit(options, -1);
    }

    // check for user-defined info server port setting, if so override the conf
    try {
      if (cmd.hasOption("infoport")) {
        String val = cmd.getOptionValue("infoport");
        conf.setInt("hbase.thrift.info.port", Integer.valueOf(val));
        LOG.debug("Web UI port set to " + val);
      }
    } catch (NumberFormatException e) {
      LOG.error("Could not parse the value provided for the infoport option", e);
      printUsageAndExit(options, -1);
    }

    // Make optional changes to the configuration based on command-line options
    optionToConf(cmd, MIN_WORKERS_OPTION,
        conf, TBoundedThreadPoolServer.MIN_WORKER_THREADS_CONF_KEY);
    optionToConf(cmd, MAX_WORKERS_OPTION,
        conf, TBoundedThreadPoolServer.MAX_WORKER_THREADS_CONF_KEY);
    optionToConf(cmd, MAX_QUEUE_SIZE_OPTION,
        conf, TBoundedThreadPoolServer.MAX_QUEUED_REQUESTS_CONF_KEY);
    optionToConf(cmd, KEEP_ALIVE_SEC_OPTION,
        conf, TBoundedThreadPoolServer.THREAD_KEEP_ALIVE_TIME_SEC_CONF_KEY);

    // Set general thrift server options
    conf.setBoolean(
        ThriftServerRunner.COMPACT_CONF_KEY, cmd.hasOption(COMPACT_OPTION));
    conf.setBoolean(
        ThriftServerRunner.FRAMED_CONF_KEY, cmd.hasOption(FRAMED_OPTION));
    if (cmd.hasOption(BIND_OPTION)) {
      conf.set(
          ThriftServerRunner.BIND_CONF_KEY, cmd.getOptionValue(BIND_OPTION));
    }

    ImplType.setServerImpl(cmd, conf);
  }
View Full Code Here

    options.addOption(opt);
    opt = new Option("t", true, "capacity of the channel");
    opt.setRequired(true);
    options.addOption(opt);
    CommandLineParser parser = new GnuParser();
    CommandLine cli = parser.parse(options, args);
    File checkpointDir = new File(cli.getOptionValue("c"));
    String[] logDirs = cli.getOptionValue("l").split(",");
    List<File> logFiles = Lists.newArrayList();
    for (String logDir : logDirs) {
      File[] files = new File(logDir).listFiles();
      logFiles.addAll(Arrays.asList(files));
    }
    int capacity = Integer.parseInt(cli.getOptionValue("t"));
    File checkpointFile = new File(checkpointDir, "checkpoint");
    if(checkpointFile.exists()) {
      LOG.error("Cannot execute fast replay",
          new IllegalStateException("Checkpoint exists" + checkpointFile));
    } else {
View Full Code Here

        .addOption("R", "headerFile", true, ("file containing headers as " +
            "key/value pairs on each new line"))
        .addOption("h", "help", false, "display help text");

    CommandLineParser parser = new GnuParser();
    CommandLine commandLine = parser.parse(options, args);

    if (commandLine.hasOption('h')) {
      new HelpFormatter().printHelp("flume-ng avro-client", "", options,
          "The --dirname option assumes that a spooling directory exists " +
          "where immutable log files are dropped.", true);

      return false;
    }

    if (commandLine.hasOption("filename") && commandLine.hasOption("dirname")) {
      throw new ParseException(
          "--filename and --dirname options cannot be used simultaneously");
    }

    if (!commandLine.hasOption("port")) {
      throw new ParseException(
          "You must specify a port to connect to with --port");
    }

    port = Integer.parseInt(commandLine.getOptionValue("port"));

    if (!commandLine.hasOption("host")) {
      throw new ParseException(
          "You must specify a hostname to connect to with --host");
    }

    hostname = commandLine.getOptionValue("host");
    fileName = commandLine.getOptionValue("filename");
    dirName = commandLine.getOptionValue("dirname");

    if (commandLine.hasOption("headerFile")){
      parseHeaders(commandLine);
    }

    return true;
  }
View Full Code Here

        return new GnuParser().parse(options, args);
    }

    public static void main(String[] args) throws Exception {
        CommandLine cmd = parseArgs(args);
        String projectVersion = BuildProperties.get().getProperty("project.version");
        String appPath = "webapp/target/falcon-webapp-" + projectVersion;
        int appPort = 15000;

        if (cmd.hasOption(APP_PATH)) {
            appPath = cmd.getOptionValue(APP_PATH);
        }

        if (cmd.hasOption(APP_PORT)) {
            appPort = Integer.valueOf(cmd.getOptionValue(APP_PORT));
        }

        boolean startActiveMq = Boolean.valueOf(System.getProperty("falcon.embeddedmq", "true"));
        if (startActiveMq) {
            String dataDir = System.getProperty("falcon.embeddedmq.data", "target/");
View Full Code Here

      Options options = getOptions();
      try {
       
        CommandLineParser parser = new GnuParser();

        CommandLine line = parser.parse( options, args );
        File dir = new File(line.getOptionValue("dir", "."));
        Collection files = ListFile.list(dir);
        System.out.println("listing files in "+dir);
        for (Iterator it = files.iterator(); it.hasNext(); ) {
          System.out.println("\t"+it.next()+"\n");
        }
View Full Code Here

    }

    private MavenExecutionRequest populateRequest( CliRequest cliRequest )
    {
        MavenExecutionRequest request = cliRequest.request;
        CommandLine commandLine = cliRequest.commandLine;
        String workingDirectory = cliRequest.workingDirectory;
        boolean debug = cliRequest.debug;
        boolean quiet = cliRequest.quiet;
        boolean showErrors = cliRequest.showErrors;

        String[] deprecatedOptions = { "up", "npu", "cpu", "npr" };
        for ( String deprecatedOption : deprecatedOptions )
        {
            if ( commandLine.hasOption( deprecatedOption ) )
            {
                cliRequest.stdout.println( "[WARNING] Command line option -" + deprecatedOption
                    + " is deprecated and will be removed in future Maven versions." );
            }
        }

        // ----------------------------------------------------------------------
        // Now that we have everything that we need we will fire up plexus and
        // bring the maven component to life for use.
        // ----------------------------------------------------------------------

        if ( commandLine.hasOption( CLIManager.BATCH_MODE ) )
        {
            request.setInteractiveMode( false );
        }

        boolean noSnapshotUpdates = false;
        if ( commandLine.hasOption( CLIManager.SUPRESS_SNAPSHOT_UPDATES ) )
        {
            noSnapshotUpdates = true;
        }

        // ----------------------------------------------------------------------
        //
        // ----------------------------------------------------------------------

        @SuppressWarnings("unchecked")
        List<String> goals = commandLine.getArgList();

        boolean recursive = true;

        // this is the default behavior.
        String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;

        if ( commandLine.hasOption( CLIManager.NON_RECURSIVE ) )
        {
            recursive = false;
        }

        if ( commandLine.hasOption( CLIManager.FAIL_FAST ) )
        {
            reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
        }
        else if ( commandLine.hasOption( CLIManager.FAIL_AT_END ) )
        {
            reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END;
        }
        else if ( commandLine.hasOption( CLIManager.FAIL_NEVER ) )
        {
            reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER;
        }

        if ( commandLine.hasOption( CLIManager.OFFLINE ) )
        {
            request.setOffline( true );
        }

        boolean updateSnapshots = false;

        if ( commandLine.hasOption( CLIManager.UPDATE_SNAPSHOTS ) )
        {
            updateSnapshots = true;
        }

        String globalChecksumPolicy = null;

        if ( commandLine.hasOption( CLIManager.CHECKSUM_FAILURE_POLICY ) )
        {
            globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL;
        }
        else if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) )
        {
            globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN;
        }

        File baseDirectory = new File( workingDirectory, "" ).getAbsoluteFile();

        // ----------------------------------------------------------------------
        // Profile Activation
        // ----------------------------------------------------------------------

        List<String> activeProfiles = new ArrayList<String>();

        List<String> inactiveProfiles = new ArrayList<String>();

        if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) )
        {
            String[] profileOptionValues = commandLine.getOptionValues( CLIManager.ACTIVATE_PROFILES );
            if ( profileOptionValues != null )
            {
                for ( int i = 0; i < profileOptionValues.length; ++i )
                {
                    StringTokenizer profileTokens = new StringTokenizer( profileOptionValues[i], "," );

                    while ( profileTokens.hasMoreTokens() )
                    {
                        String profileAction = profileTokens.nextToken().trim();

                        if ( profileAction.startsWith( "-" ) || profileAction.startsWith( "!" ) )
                        {
                            inactiveProfiles.add( profileAction.substring( 1 ) );
                        }
                        else if ( profileAction.startsWith( "+" ) )
                        {
                            activeProfiles.add( profileAction.substring( 1 ) );
                        }
                        else
                        {
                            activeProfiles.add( profileAction );
                        }
                    }
                }
            }
        }

        ArtifactTransferListener transferListener;

        if ( quiet )
        {
            transferListener = new QuietMavenTransferListener( cliRequest.stdout );
        }
        else if ( request.isInteractiveMode() )
        {
            transferListener = new ConsoleMavenTransferListener( cliRequest.stdout );
        }
        else
        {
            transferListener = new BatchModeMavenTransferListener( cliRequest.stdout );
        }

        transferListener.setShowChecksumEvents( false );

        String alternatePomFile = null;
        if ( commandLine.hasOption( CLIManager.ALTERNATE_POM_FILE ) )
        {
            alternatePomFile = commandLine.getOptionValue( CLIManager.ALTERNATE_POM_FILE );
        }

        int loggingLevel;

        if ( debug )
        {
            loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_DEBUG;
        }
        else if ( quiet )
        {
            // TODO: we need to do some more work here. Some plugins use sys out or log errors at info level.
            // Ideally, we could use Warn across the board
            loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_ERROR;
            // TODO:Additionally, we can't change the mojo level because the component key includes the version and
            // it isn't known ahead of time. This seems worth changing.
        }
        else
        {
            loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_INFO;
        }

        File userToolchainsFile;
        if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_TOOLCHAINS ) )
        {
            userToolchainsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_TOOLCHAINS ) );
            userToolchainsFile = resolveFile( userToolchainsFile, workingDirectory );
        }
        else
        {
            userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE;
        }

        request.setBaseDirectory( baseDirectory ).setGoals( goals )
            .setSystemProperties( cliRequest.systemProperties )
            .setUserProperties( cliRequest.userProperties )
            .setReactorFailureBehavior( reactorFailureBehaviour ) // default: fail fast
            .setRecursive( recursive ) // default: true
            .setShowErrors( showErrors ) // default: false
            .addActiveProfiles( activeProfiles ) // optional
            .addInactiveProfiles( inactiveProfiles ) // optional
            .setLoggingLevel( loggingLevel ) // default: info
            .setTransferListener( transferListener ) // default: batch mode which goes along with interactive
            .setUpdateSnapshots( updateSnapshots ) // default: false
            .setNoSnapshotUpdates( noSnapshotUpdates ) // default: false
            .setGlobalChecksumPolicy( globalChecksumPolicy ) // default: warn
            .setUserToolchainsFile( userToolchainsFile );

        if ( alternatePomFile != null )
        {
            File pom = resolveFile( new File( alternatePomFile ), workingDirectory );

            request.setPom( pom );
        }
        else
        {
            File pom = modelProcessor.locatePom( baseDirectory );

            if ( pom.isFile() )
            {
                request.setPom( pom );
            }
        }

        if ( ( request.getPom() != null ) && ( request.getPom().getParentFile() != null ) )
        {
            request.setBaseDirectory( request.getPom().getParentFile() );
        }

        if ( commandLine.hasOption( CLIManager.RESUME_FROM ) )
        {
            request.setResumeFrom( commandLine.getOptionValue( CLIManager.RESUME_FROM ) );
        }

        if ( commandLine.hasOption( CLIManager.PROJECT_LIST ) )
        {
            String projectList = commandLine.getOptionValue( CLIManager.PROJECT_LIST );
            String[] projects = StringUtils.split( projectList, "," );
            request.setSelectedProjects( Arrays.asList( projects ) );
        }

        if ( commandLine.hasOption( CLIManager.ALSO_MAKE )
                        && !commandLine.hasOption( CLIManager.ALSO_MAKE_DEPENDENTS ) )
        {
            request.setMakeBehavior( MavenExecutionRequest.REACTOR_MAKE_UPSTREAM );
        }
        else if ( !commandLine.hasOption( CLIManager.ALSO_MAKE )
                        && commandLine.hasOption( CLIManager.ALSO_MAKE_DEPENDENTS ) )
        {
            request.setMakeBehavior( MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM );
        }
        else if ( commandLine.hasOption( CLIManager.ALSO_MAKE )
                        && commandLine.hasOption( CLIManager.ALSO_MAKE_DEPENDENTS ) )
        {
            request.setMakeBehavior( MavenExecutionRequest.REACTOR_MAKE_BOTH );
        }

        String localRepoProperty = request.getUserProperties().getProperty( MavenCli.LOCAL_REPO_PROPERTY );

        if ( localRepoProperty == null )
        {
            localRepoProperty = request.getSystemProperties().getProperty( MavenCli.LOCAL_REPO_PROPERTY );
        }

        if ( localRepoProperty != null )
        {
            request.setLocalRepositoryPath( localRepoProperty );
        }

        final String threadConfiguration = commandLine.hasOption( CLIManager.THREADS )
            ? commandLine.getOptionValue( CLIManager.THREADS )
            : request.getSystemProperties().getProperty(
                MavenCli.THREADS_DEPRECATED ); // TODO: Remove this setting. Note that the int-tests use it

        if ( threadConfiguration != null )
        {
View Full Code Here

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("HFile ", options, true);
        System.exit(-1);
      }
      CommandLineParser parser = new PosixParser();
      CommandLine cmd = parser.parse(options, args);
      boolean verbose = cmd.hasOption("v");
      boolean printKeyValue = cmd.hasOption("p");
      boolean printMeta = cmd.hasOption("m");
      boolean checkRow = cmd.hasOption("k");
      boolean checkFamily = cmd.hasOption("a");
      // get configuration, file system and get list of files
      HBaseConfiguration conf = new HBaseConfiguration();
      conf.set("fs.default.name",
        conf.get(org.apache.hadoop.hbase.HConstants.HBASE_DIR));
      FileSystem fs = FileSystem.get(conf);
      ArrayList<Path> files = new ArrayList<Path>();
      if (cmd.hasOption("f")) {
        files.add(new Path(cmd.getOptionValue("f")));
      }
      if (cmd.hasOption("r")) {
        String regionName = cmd.getOptionValue("r");
        byte[] rn = Bytes.toBytes(regionName);
        byte[][] hri = HRegionInfo.parseRegionName(rn);
        Path rootDir = FSUtils.getRootDir(conf);
        Path tableDir = new Path(rootDir, Bytes.toString(hri[0]));
        int enc = HRegionInfo.encodeRegionName(rn);
View Full Code Here

  protected static String[] processLocalArgs(String[] cliArgs) throws IOException, ParseException
  {
    CommandLineParser cliParser = new GnuParser();
    Options cliOptions = constructCommandLineOptions();

    CommandLine cmd = cliParser.parse(cliOptions, cliArgs, true);
    // Options here has to be up front
    if (cmd.hasOption(RELAY_HOST_OPT_NAME))
    {
      _relayHost = cmd.getOptionValue(RELAY_HOST_OPT_NAME);
      LOG.info("Relay Host = " + _relayHost);
    }
    if (cmd.hasOption(RELAY_PORT_OPT_NAME))
    {
      _relayPort = cmd.getOptionValue(RELAY_PORT_OPT_NAME);
      LOG.info("Relay Port = " + _relayPort);
    }
    if (cmd.hasOption(EVENT_DUMP_FILE_OPT_NAME))
    {
      _eventDumpFile = cmd.getOptionValue(EVENT_DUMP_FILE_OPT_NAME);
      LOG.info("Saving event dump to file: " + _eventDumpFile);
    }
    if (cmd.hasOption(VALUE_DUMP_FILE_OPT_NAME))
    {
      _valueDumpFile = cmd.getOptionValue(VALUE_DUMP_FILE_OPT_NAME);
      LOG.info("Saving event value dump to file: " + _valueDumpFile);
    }
    if (cmd.hasOption(HTTP_PORT_OPT_NAME))
    {
      _httpPort = cmd.getOptionValue(HTTP_PORT_OPT_NAME);
      LOG.info("Consumer http port =  " + _httpPort);
    }
    if (cmd.hasOption(JMX_SERVICE_PORT_OPT_NAME))
    {
      _jmxServicePort = cmd.getOptionValue(JMX_SERVICE_PORT_OPT_NAME);
      LOG.info("Consumer JMX Service port =  " + _jmxServicePort);
    }
    if (cmd.hasOption(CHECKPOINT_DIR))
    {
      _checkpointFileRootDir = cmd.getOptionValue(CHECKPOINT_DIR);
      LOG.info("Checkpoint dir =  " + _checkpointFileRootDir);
    }
    if (cmd.hasOption(BOOTSTRAP_HOST_OPT_NAME))
    {
      _bootstrapHost = cmd.getOptionValue(BOOTSTRAP_HOST_OPT_NAME);
      LOG.info("Bootstrap Server = " + _bootstrapHost);
    }
    if (cmd.hasOption(BOOTSTRAP_PORT_OPT_NAME))
    {
      _bootstrapPort = cmd.getOptionValue(BOOTSTRAP_PORT_OPT_NAME);
      LOG.info("Bootstrap Server Port = " + _bootstrapPort);
    }
    if (cmd.hasOption(EVENT_PATTERN_OPT_NAME))
    {
      _eventPattern = cmd.getOptionValue(EVENT_PATTERN_OPT_NAME);
      LOG.info("Event pattern = " + _eventPattern);
    }
    if (_bootstrapHost != null || _bootstrapPort != null)
    {
      _enableBootStrap = true;
    }

    if ( cmd.hasOption(FILTER_CONF_FILE_OPT_NAME))
    {
      _filterConfFile = cmd.getOptionValue(FILTER_CONF_FILE_OPT_NAME);
      LOG.info("Server Side Filtering Config File =" + _filterConfFile);
    }

    if (cmd.hasOption(SOURCES_OPT_NAME))
    {
      _sources = cmd.getOptionValue(SOURCES_OPT_NAME).split(",");
      LOG.info("Sources to be subscribed are =" + Arrays.toString(_sources));
    }
   
    // return what left over args
    return cmd.getArgs();
  }
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.