Package org.apache.commons.cli

Examples of org.apache.commons.cli.CommandLine


            options.addOption("z", true, "zk-server")
                    .addOption("c", true, "cluster-name ")
                    .addOption("p", true, "partition")
                    .addOption("l", false, "legacy")
                    .addOption("h", false, "help");
            CommandLine cmdLineArgs = cmdLineParser.parse(options, args, false);

            if (cmdLineArgs.hasOption('h'))
            {
                usage();
                System.exit(0);
            }

            if (!cmdLineArgs.hasOption('c'))
            {
                usage();
                System.exit(1);
            }
            String clusterName = cmdLineArgs.getOptionValue('c');
            String zkServer = cmdLineArgs.getOptionValue('z');
            boolean isLegacyChkptLocation = cmdLineArgs.hasOption('l');
            if (zkServer == null || zkServer.isEmpty())
            {
                zkServer = "localhost:2181";
            }

            String partitionStr = cmdLineArgs.getOptionValue('p');
            String partition = partitionStr;
            if ((partition != null) && partition.equals("all"))
            {
                partition = "";
            }

            String[] fns = cmdLineArgs.getArgs();
            if (fns.length < 1)
            {
                usage();
                System.exit(1);
            }
View Full Code Here


      options.addOption("n",true,"Zookeeper namespace  [/DatabusClient")
      .addOption("g",true,"Groupname [default-group-name] ")
      .addOption("d",true,"Shared directory name [shareddata] ")
      .addOption("s",true,"Zookeeper server list [localhost:2181] ")
      .addOption("h",false,"help");
      CommandLine cmdLineArgs  = cmdLineParser.parse(options, args,false);
     
      if (cmdLineArgs.hasOption('h')) {
        usage();
        System.exit(0);
      }
     
      String namespace = cmdLineArgs.getOptionValue('n');
      if (namespace==null || namespace.isEmpty())
      {
        namespace = "/DatabusClient";
      }
      String groupname = cmdLineArgs.getOptionValue('g');
      if (groupname==null || groupname.isEmpty())
      {
        groupname = "default-group-name";
      }
      String sharedDir = cmdLineArgs.getOptionValue('d');
      if (sharedDir==null || sharedDir.isEmpty())
      {
        sharedDir = "shareddata";
      }
      String serverList = cmdLineArgs.getOptionValue('s');
      if (serverList==null || serverList.isEmpty())
      {
        serverList  = "localhost:2181";
      }
      String[] fns =  cmdLineArgs.getArgs();
      if (fns.length < 1)
      {
        usage();
        System.exit(1);
      }
View Full Code Here

    options.addOption("l", "data log path", true, "File path where the logs will be written.");
    options.addOption("p", "original data path", true, "Path where zip files will be stored.");
    options.addOption("b", "original tsv path", true, "Path where tsv files will be stored.");
    options.addOption("r", "raw data path", true, "Path where the uncompressed files will be stored.");
    options.addOption("a", "sdmx ttl file", true, "Path where the sdmx ttl is located.");
    CommandLine commandLine = parser.parse( options, args );
   
    if( commandLine.hasOption('h') ) {
        usage();
        return;
     }

    if(commandLine.hasOption('a'))
      sdmxTTLFile = commandLine.getOptionValue('a');
   
    if(commandLine.hasOption('i'))
      inputFilePath = commandLine.getOptionValue('i');
   
    if(commandLine.hasOption('o'))
      outputFilePath = commandLine.getOptionValue('o');
   
    if(commandLine.hasOption('f'))
      logFilePath = commandLine.getOptionValue('f');
   
    if(commandLine.hasOption('z'))
      tempZipPath = commandLine.getOptionValue('z');
   
    if(commandLine.hasOption('t'))
      tempDataPath = commandLine.getOptionValue('t');
   
    if(commandLine.hasOption('s'))
      dataPath = commandLine.getOptionValue('s');
   
    if(commandLine.hasOption('d'))
      dsdPath = commandLine.getOptionValue('d');
   
    if(commandLine.hasOption('l'))
      dataLogPath = commandLine.getOptionValue('l');
   
    if(commandLine.hasOption('p'))
      originalDataPath = commandLine.getOptionValue('p');
   
    if(commandLine.hasOption('r'))
      rawDataPath = commandLine.getOptionValue('r');
   
    if(commandLine.hasOption('b'))
      originalTSVPath = commandLine.getOptionValue('b');
   
    if(commandLine.hasOption('v'))
      tempTsvPath = commandLine.getOptionValue('v');
   
    if(tempTsvPath.equals("") || originalTSVPath.equals("") || inputFilePath.equals("") || outputFilePath.equals("") || logFilePath.equals("") || tempZipPath.equals("") || tempDataPath.equals("") || dsdPath.equals("") || dataPath.equals("") || dataLogPath.equals("") || originalDataPath.equals("") || rawDataPath.equals("") || sdmxTTLFile.equals(""))
    {
      usage();
      return;
View Full Code Here

    options.addOption(sourceNameOption);
    options.addOption(dbOption);
    options.addOption(cmdLinePropsOption);
    options.addOption(log4jPropsOption);

    CommandLine cmd = null;
    try
    {
      cmd = cliParser.parse(options, args);
    }
    catch (ParseException pe)
    {
      LOG.error("Bootstrap Physical Config: failed to parse command-line options.", pe);
      throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
    }

    if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR))
    {
      String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
      PropertyConfigurator.configure(log4jPropFile);
      LOG.info("Using custom logging settings from file " + log4jPropFile);
    }
    else
    {
      PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
      ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);

      Logger.getRootLogger().removeAllAppenders();
      Logger.getRootLogger().addAppender(defaultAppender);

      LOG.info("Using default logging settings");
    }

    if (cmd.hasOption(HELP_OPT_CHAR))
    {
      printCliHelp(options);
      System.exit(0);
    }

    if ( !cmd.hasOption(SOURCE_ID_OPT_CHAR))
      throw new RuntimeException("Source ID is not provided");

    if ( !cmd.hasOption(SOURCE_NAME_OPT_CHAR))
      throw new RuntimeException("Source Name is not provided");

    if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR) )
      throw new RuntimeException("Bootstrap config is not provided");

    String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
    LOG.info("Loading bootstrap DB config from properties file " + propFile);

    _sBootstrapConfigProps = new Properties();
    FileInputStream f = new FileInputStream(propFile);
    try
    {
      _sBootstrapConfigProps.load(f);
    } finally {
      f.close();
    }
    if (cmd.hasOption(CMD_LINE_PROPS_OPT_CHAR))
    {
      String cmdLinePropString = cmd.getOptionValue(CMD_LINE_PROPS_OPT_CHAR);
      updatePropsFromCmdLine(_sBootstrapConfigProps, cmdLinePropString);
    }

    int srcId = Integer.parseInt(cmd.getOptionValue(SOURCE_ID_OPT_CHAR));
    String srcName = cmd.getOptionValue(SOURCE_NAME_OPT_CHAR);

    BootstrapConfig config = new BootstrapConfig();

    ConfigLoader<BootstrapReadOnlyConfig> configLoader =
        new ConfigLoader<BootstrapReadOnlyConfig>("bootstrap.", config);
View Full Code Here

    options.addOption("i", "file path", true, "File path of the SDMX xml file.");
    options.addOption("t", "tsv file path", true, "File path of the SDMX tsv file.");
    options.addOption("o", "output file path", true, "Output directory path to generate DataCube representation of observations");
    options.addOption("l", "log file path", true, "File path where the logs will be written.");
   
    CommandLine commandLine = parser.parse( options, args );
   
    if( commandLine.hasOption('h') ) {
        usage();
        return;
     }
   
    if(commandLine.hasOption('f'))
      fileName = commandLine.getOptionValue('f');
   
    if(commandLine.hasOption('i'))
      sdmxFilePath = commandLine.getOptionValue('i');
   
    if(commandLine.hasOption('t'))
      tsvFilePath = commandLine.getOptionValue('t');
   
    if(commandLine.hasOption('o'))
      outputFilePath = commandLine.getOptionValue('o');
   
    if(commandLine.hasOption('l'))
      logFilePath = commandLine.getOptionValue('l');
   
   
    if(tsvFilePath.equals("") || fileName.equals("") || sdmxFilePath.equals("") || outputFilePath.equals("") || logFilePath.equals(""))
    {
      usage();
View Full Code Here

    @Override
    public void processCommandLineArgs(String[] cliArgs) throws IOException, DatabusException
    {
      super.processCommandLineArgs(cliArgs);
      CommandLine cmdLine = getCmdLine();

      if (! cmdLine.hasOption(ACTION_OPTION_CHAR))
      {
        throw new DatabusException("action expected; see --help for usage");
      }
      String actionString = cmdLine.getOptionValue(ACTION_OPTION_CHAR).toUpperCase();

      try
      {
        _action = Action.valueOf(actionString);
      }
      catch (IllegalArgumentException e)
      {
        throw new DatabusException("invalid action: " + actionString);
      }

      if (_action.equals(Action.CREATE_LOG_TABLE) || _action.equals(Action.CREATE_TAB_TABLE))
      {
        if (! cmdLine.hasOption(SRCID_OPTION_CHAR))
        {
          throw new DatabusException("srcid expected; see --help for usage");
        }
        String srcidString = cmdLine.getOptionValue(SRCID_OPTION_CHAR);

        try
        {
          _srcId = Integer.parseInt(srcidString);
        }
View Full Code Here

      options.addOption(dbOption);
      options.addOption(cmdLinePropsOption1);
    options.addOption(log4jPropsOption);
    options.addOption(sourcesOption);

      CommandLine cmd = null;
      try
      {
        cmd = cliParser.parse(options, args);
      }
      catch (ParseException pe)
      {
      LOG.error("Bootstrap Physical Config: failed to parse command-line options.", pe);
        throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
      }

      if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR))
      {
        String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
        PropertyConfigurator.configure(log4jPropFile);
        LOG.info("Using custom logging settings from file " + log4jPropFile);
      }
      else
      {
        PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
        ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);

        Logger.getRootLogger().removeAllAppenders();
        Logger.getRootLogger().addAppender(defaultAppender);

        LOG.info("Using default logging settings");
      }

      if (cmd.hasOption(HELP_OPT_CHAR))
      {
        printCliHelp(options);
        System.exit(0);
      }

      if (cmd.hasOption(BOOTSTRAP_SOURCES_PROP_OPT_CHAR))
      {
        _sSources = new ArrayList<String>();
        String srcListStr = cmd.getOptionValue(BOOTSTRAP_SOURCES_PROP_OPT_CHAR);
          LOG.info("Going to run cleaner for only these sources : " + srcListStr);
          String[] srcList = srcListStr.split(",");
          for (String s: srcList)
            _sSources.add(s);
      }

      if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR) )
          throw new RuntimeException("Bootstrap config is not provided");

      String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
      LOG.info("Loading bootstrap DB config from properties file " + propFile);

      _sBootstrapConfigProps = new Properties();
    FileInputStream f = new FileInputStream(propFile);
    try
    {
    _sBootstrapConfigProps.load(f);
    } finally {
    f.close();
    }
      if (cmd.hasOption(CLEANER_CMD_LINE_PROPS_OPT_CHAR))
      {
        String cmdLinePropString = cmd.getOptionValue(CLEANER_CMD_LINE_PROPS_OPT_CHAR);
        updatePropsFromCmdLine(_sBootstrapConfigProps, cmdLinePropString);
      }
  }
View Full Code Here

    Options options = new Options( );
   
    options.addOption("i", "file path", true, "sdmx file path.");
    options.addOption("l", "log file path", true, "File path where the logs will be generated");
   
    CommandLine commandLine = parser.parse( options, args );
   
    if(commandLine.hasOption('i'))
      sdmxFilePath = commandLine.getOptionValue('i');
       
    if(commandLine.hasOption('l'))
      logFilePath = commandLine.getOptionValue('l');
   
    if(sdmxFilePath.equals("") || logFilePath.equals(""))
    {
     
      return;
View Full Code Here

      options.addOption(log4jPropsOption);
      options.addOption(validationType);
      options.addOption(validationSamplePct);


      CommandLine cmd = null;
      try
      {
        cmd = cliParser.parse(options, args);
      }
      catch (ParseException pe)
      {
        LOG.fatal("Bootstrap Physical Config: failed to parse command-line options.", pe);
        throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
      }

      if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR))
      {
        String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
        PropertyConfigurator.configure(log4jPropFile);
        LOG.info("Using custom logging settings from file " + log4jPropFile);
      }
      else
      {
        PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
        ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);

        Logger.getRootLogger().removeAllAppenders();
        Logger.getRootLogger().addAppender(defaultAppender);
        Logger.getRootLogger().setLevel(Level.INFO)//using info as the default log level
        LOG.info("Using default logging settings. Log Level is :" + Logger.getRootLogger().getLevel());
      }

      if (cmd.hasOption(HELP_OPT_CHAR))
      {
        printCliHelp(options);
        System.exit(0);
      }

      if (! cmd.hasOption(PHYSICAL_CONFIG_OPT_CHAR))
        throw new RuntimeException("Sources Config is not provided; use --help for usage");

      if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR) )
        throw new RuntimeException("Bootstrap config is not provided; use --help for usage");

      _sSourcesConfigFile = cmd.getOptionValue(PHYSICAL_CONFIG_OPT_CHAR);

      String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
      LOG.info("Loading bootstrap DB config from properties file " + propFile);

      _sBootstrapConfigProps = new Properties();
      _sBootstrapConfigProps.load(new FileInputStream(propFile));
      if (!cmd.hasOption(VALIDATION_TYPE_OPT_CHAR))
      {
        _validationType = "normal";
      }
      else
      {
        String vtype = cmd.getOptionValue(VALIDATION_TYPE_OPT_CHAR);
        if (vtype.equals("point") || vtype.equals("normal") || vtype.equals("pointBs"))
        {
          _validationType = vtype;
        }
        else
        {
          throw new RuntimeException("Validation type has to be one of 'normal' or 'point' or 'pointBs'");
        }
      }
      if (cmd.hasOption(VALIDATION_SAMPLE_PCT_CHAR))
      {
         try
         {
           _validationSamplePct = Double.parseDouble(cmd.getOptionValue(VALIDATION_SAMPLE_PCT_CHAR));
           if (_validationSamplePct < 0.0 || _validationSamplePct > 100.0)
           {
             throw new RuntimeException("Error in specifying: " + VALIDATION_SAMPLE_PCT_LONG_NAME +
                 "Should be between 0.0 and 100.0. It was " + _validationSamplePct);
           }
View Full Code Here

    options.addOption("h", "help", false, "Print this usage information.");
    options.addOption("i", "inputFilepath", true, "Local ToC file.");
    options.addOption("o", "outputFilePath", true, "Output directory path to generate the file.");
    options.addOption("f", "format", true, "RDF format for serialization (RDF/XML, TURTLE, N-TRIPLES).");

    CommandLine commandLine = parser.parse( options, args );
   
    if( commandLine.hasOption('h') ) {
        usage();
        return;
     }
   
    if(commandLine.hasOption('i'))
      inputFilePath = commandLine.getOptionValue('i');
    if(commandLine.hasOption('o'))
      outputFilePath = commandLine.getOptionValue('o');
   
    if(commandLine.hasOption('f'))
      serialization = commandLine.getOptionValue('f');
   
    if(serialization.equals("") || outputFilePath.equals(""))
    {
      usage();
      return;
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.