Package org.jostraca.comp.gnu.getopt

Examples of org.jostraca.comp.gnu.getopt.Getopt


    ArrayList    additionalConfigFiles     = new ArrayList();
    ArrayList    cmdlinetemplates          = new ArrayList();


    // parse command line
    Getopt g = new Getopt( CMD_NAME, pArgs, ":"+CMD_SPEC_Options );
    g.setOpterr( false ); // handle errors manually
    int    c;
    String arg;

    while( -1 != ( c = g.getopt() ) ) {

      switch( c ) {

      case ARG_CONFIG : // configuration file
        configPath = g.getOptarg();
        usingDefaultConf = false;
        break;

      case ARG_ADD_CONFIG : // additional configuration file
        String addConfigPath = g.getOptarg();
        pAdditionalConfig.add( addConfigPath );
        break;

      case ARG_WRITER_FORMAT : // writer format
        String writerFormatPath = g.getOptarg().trim();
        checkDataFile( "WriterFormat", writerFormatPath );
        cmdLineOptions.set( Property.main_CodeWriterFormat, writerFormatPath );
        break;

      case ARG_TEMPLATE_DOC : // show documentation
        cmdLineOptions.set( Property.main_ShowDocumentation, Standard.YES );
        break;

      case ARG_OUTPUT_FOLDER : // output folder
        String outputFolder = g.getOptarg().trim();
        checkFolder( "Output", outputFolder );
        cmdLineOptions.set( Property.main_OutputFolder, outputFolder );
        break;

      case ARG_WORK_FOLDER : // work folder
        String workFolder = g.getOptarg().trim();
        checkFolder( "Work", workFolder );
        cmdLineOptions.set( Property.main_WorkFolder, workFolder );
        break;

      case ARG_TEMPLATE_LIST : // templates listed in separate file
        String templateList = g.getOptarg().trim();
        checkDataFile( "Template list", templateList );
        addTemplatesFromFile( new File( templateList ), cmdlinetemplates );
        usingTemplateListFile = true;
        break;

      case ARG_ARGUMENT : // template arguments
        codeWriterOptions.append( g.getOptarg() );
        codeWriterOptions.append( Standard.SPACE );
        break;

      case ARG_ALL_TEMPLATES : // all arguments are templates
        argumentsAreTemplateNames = true;
        break;

      case ARG_BACKUP_FOLDER : // set backup folder and make backups
        String backupFolder = g.getOptarg().trim();
        cmdLineOptions.set( Property.main_BackupFolder, backupFolder );
        cmdLineOptions.set( Property.main_MakeBackup, Standard.YES );
        break;

      case ARG_NO_BACKUP : // don't backup
        cmdLineOptions.set( Property.main_MakeBackup, Standard.NO );
        break;

      case ARG_META_FOLDER : // set meta folder and store metadata
        String metaFolder = g.getOptarg().trim();
        cmdLineOptions.set( Property.main_MetaFolder, metaFolder );
        cmdLineOptions.set( Property.main_EnableMeta, Standard.YES );
        break;

      case ARG_NO_META : // don't store metadata
        cmdLineOptions.set( Property.main_EnableMeta, Standard.NO );
        break;

      case ARG_COMPILE : // compile code writer
        cmdLineOptions.set( Property.main_CompileCodeWriter, Standard.YES );
        break;

      case ARG_NO_COMPILE : // don't compile code writer
        cmdLineOptions.set( Property.main_CompileCodeWriter, Standard.NO );
        break;

      case ARG_GENERATE : // execute code writer, that is, generate output files
        cmdLineOptions.set( Property.main_ExecuteCodeWriter, Standard.YES );
        break;

      case ARG_NO_GENERATE : // don't execute code writer, that is, don't generate output files
        cmdLineOptions.set( Property.main_ExecuteCodeWriter, Standard.NO );
        break;

      case ARG_DUMP : // dump template, settings, etc
        String dumpSpec = g.getOptarg().trim();
        Service.parseDumpSpec( dumpSpec, cmdLineOptions );
        break;

      case ARG_DEFINE : // config setting
        // REVIEW: this parsing should be somewhere else, probably TextUtil
        String nameValue = g.getOptarg().trim();
        int equalsPos = nameValue.indexOf("=");
        if( -1 != equalsPos ) {
          cmdLineOptions.set
            ( nameValue.substring(0, equalsPos).trim(),
              nameValue.substring(equalsPos + 1).trim()
              );
        }
        break;

      case ARG_NON_STANDARD : // non-standard options
        String nsOptions = g.getOptarg();
        parseNonStandardOptions( nsOptions, cmdLineOptions, sUserMessageHandler );
        break;

      case ARG_LOW_VERBOSE : // low verbosity
        cmdLineOptions.set( Property.main_MessageLevel, UserMessageHandler.TypeNameUtil.getNameForType( UserMessageHandler.WARN ) );
        break;

      case ARG_HIGH_VERBOSE : // high verbosity
        cmdLineOptions.set( Property.main_MessageLevel, UserMessageHandler.TypeNameUtil.getNameForType( UserMessageHandler.DEBUG ) );
        break;

      case ':': // missing argument to option
        throw new JostracaException( "Option " + (char)g.getOptopt() + " requires an argument." );

      default: // everything else is a template or a template srgument
        break;
      }
    }
   
    // get template path specifiers and arguments
    int start   = g.getOptind();
    int numArgs = pArgs.length;
    for( int tpsI = start; tpsI < numArgs; tpsI++ ) {
      String argument = pArgs[tpsI].trim();
      if( ( ( !usingTemplateListFile && start == tpsI )
            || argumentsAreTemplateNames
View Full Code Here


    ArrayList    additionalConfigFiles     = new ArrayList();
    ArrayList    cmdlinetemplates          = new ArrayList();


    // parse command line
    Getopt g = new Getopt( CMD_NAME, pArgs, ":"+CMD_SPEC_Options );
    g.setOpterr( false ); // handle errors manually
    int    c;
    String arg;

    while( -1 != ( c = g.getopt() ) ) {

      switch( c ) {

      case ARG_CONFIG : // configuration file
        configPath = g.getOptarg();
        usingDefaultConf = false;
        break;

      case ARG_ADD_CONFIG : // additional configuration file
        String addConfigPath = g.getOptarg();
        pAdditionalConfig.add( addConfigPath );
        break;

      case ARG_WRITER_FORMAT : // writer format
        String writerFormatPath = g.getOptarg().trim();
        checkDataFile( "WriterFormat", writerFormatPath );
        cmdLineOptions.set( Property.main_CodeWriterFormat, writerFormatPath );
        break;

      case ARG_TEMPLATE_DOC : // show documentation
        cmdLineOptions.set( Property.main_ShowDocumentation, Standard.YES );
        break;

      case ARG_OUTPUT_FOLDER : // output folder
        String outputFolder = g.getOptarg().trim();
        checkFolder( "Output", outputFolder );
        cmdLineOptions.set( Property.main_OutputFolder, outputFolder );
        break;

      case ARG_WORK_FOLDER : // work folder
        String workFolder = g.getOptarg().trim();
        checkFolder( "Work", workFolder );
        cmdLineOptions.set( Property.main_WorkFolder, workFolder );
        break;

      case ARG_TEMPLATE_LIST : // templates listed in separate file
        String templateList = g.getOptarg().trim();
        checkDataFile( "Template list", templateList );
        addTemplatesFromFile( new File( templateList ), cmdlinetemplates );
        usingTemplateListFile = true;
        break;

      case ARG_ARGUMENT : // template arguments
        codeWriterOptions.append( g.getOptarg() );
        codeWriterOptions.append( Standard.SPACE );
        break;

      case ARG_ALL_TEMPLATES : // all arguments are templates
        argumentsAreTemplateNames = true;
        break;

      case ARG_BACKUP_FOLDER : // set backup folder and make backups
        String backupFolder = g.getOptarg().trim();
        cmdLineOptions.set( Property.main_BackupFolder, backupFolder );
        cmdLineOptions.set( Property.main_MakeBackup, Standard.YES );
        break;

      case ARG_NO_BACKUP : // don't backup
        cmdLineOptions.set( Property.main_MakeBackup, Standard.NO );
        break;

      case ARG_META_FOLDER : // set meta folder and store metadata
        String metaFolder = g.getOptarg().trim();
        cmdLineOptions.set( Property.main_MetaFolder, metaFolder );
        cmdLineOptions.set( Property.main_EnableMeta, Standard.YES );
        break;

      case ARG_NO_META : // don't store metadata
        cmdLineOptions.set( Property.main_EnableMeta, Standard.NO );
        break;

      case ARG_COMPILE : // compile code writer
        cmdLineOptions.set( Property.main_CompileCodeWriter, Standard.YES );
        break;

      case ARG_NO_COMPILE : // don't compile code writer
        cmdLineOptions.set( Property.main_CompileCodeWriter, Standard.NO );
        break;

      case ARG_GENERATE : // execute code writer, that is, generate output files
        cmdLineOptions.set( Property.main_ExecuteCodeWriter, Standard.YES );
        break;

      case ARG_NO_GENERATE : // don't execute code writer, that is, don't generate output files
        cmdLineOptions.set( Property.main_ExecuteCodeWriter, Standard.NO );
        break;

      case ARG_DUMP : // dump template, settings, etc
        String dumpSpec = g.getOptarg().trim();
        Service.parseDumpSpec( dumpSpec, cmdLineOptions );
        break;

      case ARG_DEFINE : // config setting
        // REVIEW: this parsing should be somewhere else, probably TextUtil
        String nameValue = g.getOptarg().trim();
        int equalsPos = nameValue.indexOf("=");
        if( -1 != equalsPos ) {
          cmdLineOptions.set
            ( nameValue.substring(0, equalsPos).trim(),
              nameValue.substring(equalsPos + 1).trim()
              );
        }
        break;

      case ARG_NON_STANDARD : // non-standard options
        String nsOptions = g.getOptarg();
        parseNonStandardOptions( nsOptions, cmdLineOptions, sUserMessageHandler );
        break;

      case ARG_LOW_VERBOSE : // low verbosity
        cmdLineOptions.set( Property.main_MessageLevel, UserMessageHandler.TypeNameUtil.getNameForType( UserMessageHandler.WARN ) );
        break;

      case ARG_HIGH_VERBOSE : // high verbosity
        cmdLineOptions.set( Property.main_MessageLevel, UserMessageHandler.TypeNameUtil.getNameForType( UserMessageHandler.DEBUG ) );
        break;

      case ':': // missing argument to option
        throw new JostracaException( "Option " + (char)g.getOptopt() + " requires an argument." );

      default: // everything else is a template or a template srgument
        break;
      }
    }
   
    // get template path specifiers and arguments
    int start   = g.getOptind();
    int numArgs = pArgs.length;
    for( int tpsI = start; tpsI < numArgs; tpsI++ ) {
      String argument = pArgs[tpsI].trim();
      if( ( ( !usingTemplateListFile && start == tpsI )
            || argumentsAreTemplateNames
View Full Code Here

TOP

Related Classes of org.jostraca.comp.gnu.getopt.Getopt

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.