Search in sources :

Example 6 with CmdLineRegisteredOption

use of alma.acs.util.CmdLineRegisteredOption in project ACS by ACS-Community.

the class ComponentRefTracker method setOptions.

boolean setOptions(String[] args) {
    CmdLineArgs cmdArgs = new CmdLineArgs();
    CmdLineRegisteredOption optHelp = new CmdLineRegisteredOption("--help", "-h", 0);
    cmdArgs.registerOption(optHelp);
    CmdLineRegisteredOption optCurl = new CmdLineRegisteredOption("-curl", 1);
    cmdArgs.registerOption(optCurl);
    CmdLineRegisteredOption optPingDelaySec = new CmdLineRegisteredOption("-delaySec", 1);
    cmdArgs.registerOption(optPingDelaySec);
    CmdLineRegisteredOption optCheckExists = new CmdLineRegisteredOption("-checkExists", 0);
    cmdArgs.registerOption(optCheckExists);
    CmdLineRegisteredOption optInteractive = new CmdLineRegisteredOption("-interactive", 0);
    cmdArgs.registerOption(optInteractive);
    cmdArgs.parseArgs(args);
    if (cmdArgs.isSpecified(optHelp)) {
        System.out.println("Usage: acsStartJava " + getClass().getName() + "\n\t" + optCurl.getName() + " <curl> " + "\n\t" + "[ " + optInteractive.getName() + " | " + optPingDelaySec.getName() + " <delay in s between component calls> ]" + "\n\t" + "[ " + optCheckExists.getName() + " ]");
        return false;
    } else {
        if (cmdArgs.isSpecified(optInteractive)) {
            inputReader = new BufferedReader(new InputStreamReader(System.in));
        }
        if (cmdArgs.isSpecified(optPingDelaySec)) {
            if (inputReader != null) {
                m_logger.info("Ignoring setting for ping delay because only manual component calls will be used.");
            } else {
                pingDelaySec = Integer.parseInt(cmdArgs.getValues(optPingDelaySec)[0].trim());
            }
        } else {
            if (inputReader == null) {
                pingDelaySec = 5;
            }
        }
        if (cmdArgs.isSpecified(optCurl)) {
            targetCompUrl = cmdArgs.getValues(optCurl)[0].trim();
        } else {
            throw new IllegalArgumentException("Option '" + optCurl.getName() + "' must be specified.");
        }
        if (cmdArgs.isSpecified(optCheckExists)) {
            checkExists = true;
        }
    }
    return true;
}
Also used : CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) CmdLineArgs(alma.acs.util.CmdLineArgs)

Example 7 with CmdLineRegisteredOption

use of alma.acs.util.CmdLineRegisteredOption in project ACS by ACS-Community.

the class OrbConfigurator method setDefaultOptions.

/**
	 * Sets values for default options that can be overwritten by calling <code>setOptions</code>.
	 * TODO: call this method from ctor
	 */
protected void setDefaultOptions() {
    ArrayList<CmdLineRegisteredOption> options = new ArrayList<CmdLineRegisteredOption>();
    // adapted from maciContainer.cpp
    CmdLineRegisteredOption orbDottedDecAdr = new CmdLineRegisteredOption("-ORBDottedDecimalAddresses", 1);
    options.add(orbDottedDecAdr);
    options.add(new CmdLineRegisteredOption("-ORBEndpoint", 1));
    options.add(new CmdLineRegisteredOption("-ORBInitRef", 1));
//from C++ Container 
//      // enable ORBDottedDecimalAddresses option
//      if (strCmdLn.find("-ORBDottedDecimalAddresses")==ACE_CString::npos)
//	strCmdLn += " -ORBDottedDecimalAddresses 1";
//
//      // add defaut Container's endpoint if no other specified
//      if (strCmdLn.find("-ORBEndpoint")==ACE_CString::npos)
//	{
//	  ACE_TCHAR hostname[200];
//	  ACE_OS::hostname (hostname, 200);
//
//	  strCmdLn += " -ORBEndpoint iiop://";
//	  strCmdLn += hostname;
//	  strCmdLn += ":3 0 5 0";                                // to be done with #define
//	}
//
}
Also used : CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) ArrayList(java.util.ArrayList)

Example 8 with CmdLineRegisteredOption

use of alma.acs.util.CmdLineRegisteredOption in project ACS by ACS-Community.

the class OrbacusConfigurator method _declareOptions.

/**
	 * @see alma.acs.container.corba.OrbConfigurator#_declareOptions()
	 */
protected CmdLineRegisteredOption[] _declareOptions() {
    ArrayList<CmdLineRegisteredOption> options = new ArrayList<CmdLineRegisteredOption>();
    //something like this		
    options.add(new CmdLineRegisteredOption("-ORBthreaded", 0));
    options.add(new CmdLineRegisteredOption("-ORBproperty", 1));
    return options.toArray(new CmdLineRegisteredOption[0]);
}
Also used : CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) ArrayList(java.util.ArrayList)

Example 9 with CmdLineRegisteredOption

use of alma.acs.util.CmdLineRegisteredOption in project ACS by ACS-Community.

the class LogAssistant method parseCommandLine.

/**
	 * Parse the command line and fill the internal variables
	 * Throws an IllegalStateException if an error arises while parsing
	 * like for example invalid parameters.
	 * 
	 * @param params The parameters in the command line
	 * @throws IllegalStateException If the parameters in the command line are invalid
	 */
private void parseCommandLine(String[] params) throws IllegalStateException {
    CmdLineArgs cmdLineArgs = new CmdLineArgs();
    // help / usage is a special case
    CmdLineRegisteredOption helpCmd = new CmdLineRegisteredOption("-h", "-help", 0);
    cmdLineArgs.registerOption(helpCmd);
    if (params.length == 1) {
        cmdLineArgs.parseArgs(params);
        if (cmdLineArgs.isSpecified(helpCmd)) {
            command = 'h';
            return;
        }
    }
    if (params.length < 5) {
        // destination
        throw new IllegalStateException("Wrong number of params");
    }
    CmdLineRegisteredOption extractCmd = new CmdLineRegisteredOption("-x", "-extract", 0);
    cmdLineArgs.registerOption(extractCmd);
    CmdLineRegisteredOption splitCmd = new CmdLineRegisteredOption("-p", "-split", 0);
    cmdLineArgs.registerOption(splitCmd);
    CmdLineRegisteredOption csvOtuputFormat = new CmdLineRegisteredOption("-csv", 0);
    cmdLineArgs.registerOption(csvOtuputFormat);
    CmdLineRegisteredOption txtOtuputFormat = new CmdLineRegisteredOption("-txt", 0);
    cmdLineArgs.registerOption(txtOtuputFormat);
    CmdLineRegisteredOption xmlOtuputFormat = new CmdLineRegisteredOption("-xml", 0);
    cmdLineArgs.registerOption(xmlOtuputFormat);
    CmdLineRegisteredOption twikiOtuputFormat = new CmdLineRegisteredOption("-twiki", 0);
    cmdLineArgs.registerOption(twikiOtuputFormat);
    CmdLineRegisteredOption startTime = new CmdLineRegisteredOption("-s", "-start", 1);
    cmdLineArgs.registerOption(startTime);
    CmdLineRegisteredOption endTime = new CmdLineRegisteredOption("-e", "-end", 1);
    cmdLineArgs.registerOption(endTime);
    CmdLineRegisteredOption filterName = new CmdLineRegisteredOption("-f", "-filter", 1);
    cmdLineArgs.registerOption(filterName);
    CmdLineRegisteredOption time = new CmdLineRegisteredOption("-t", "-time", 1);
    cmdLineArgs.registerOption(time);
    CmdLineRegisteredOption number = new CmdLineRegisteredOption("-n", "-num", 1);
    cmdLineArgs.registerOption(number);
    CmdLineRegisteredOption columns = new CmdLineRegisteredOption("-l", "-col", 0);
    cmdLineArgs.registerOption(columns);
    CmdLineRegisteredOption dstFileOption = new CmdLineRegisteredOption("-dest", 1);
    cmdLineArgs.registerOption(dstFileOption);
    CmdLineRegisteredOption sourceFilesOption = new CmdLineRegisteredOption("-src", 1);
    cmdLineArgs.registerOption(sourceFilesOption);
    cmdLineArgs.parseArgs(params);
    // Command==Extract
    if (cmdLineArgs.isSpecified(extractCmd)) {
        command = 'x';
    }
    // Command==split
    if (cmdLineArgs.isSpecified(splitCmd)) {
        command = 'p';
    }
    // Start date
    if (cmdLineArgs.isSpecified(startTime)) {
        String[] val = cmdLineArgs.getValues(startTime);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("Start date missing/wrong " + TIME_FORMAT);
        }
        try {
            startDate = getDate(val[0]);
        } catch (ParseException e) {
            throw new IllegalStateException("Wrong date format " + TIME_FORMAT);
        }
    }
    // End date
    if (cmdLineArgs.isSpecified(endTime)) {
        String[] val = cmdLineArgs.getValues(endTime);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("End date missing/wrong " + TIME_FORMAT);
        }
        try {
            endDate = getDate(val[0]);
        } catch (ParseException e) {
            throw new IllegalStateException("Wrong date format " + TIME_FORMAT);
        }
    }
    // Filter name
    if (cmdLineArgs.isSpecified(filterName)) {
        String[] val = cmdLineArgs.getValues(filterName);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("Wrong or missing filter name");
        }
        filterFileName = val[0];
    }
    // Time
    if (cmdLineArgs.isSpecified(time)) {
        String[] val = cmdLineArgs.getValues(time);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("Wrong or missing time (minutes)");
        }
        try {
            minutes = Integer.parseInt(val[0]);
        } catch (NumberFormatException e) {
            throw new IllegalStateException("Wrong format for the time (minutes)");
        }
    }
    // Number
    if (cmdLineArgs.isSpecified(number)) {
        String[] val = cmdLineArgs.getValues(number);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("Wrong or missing time (minutes)");
        }
        try {
            num = Integer.parseInt(val[0]);
        } catch (NumberFormatException e) {
            throw new IllegalStateException("Wrong format for the number of logs");
        }
    }
    // Col
    if (cmdLineArgs.isSpecified(columns)) {
        String[] val = cmdLineArgs.getValues(columns);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("Wrong or missing time (minutes)");
        }
        cols = val[0];
    }
    // Output format
    // How many output options?
    int count = 0;
    if (cmdLineArgs.isSpecified(csvOtuputFormat)) {
        System.out.println("Set output format to CSV");
        converter = new CSVConverter(cols);
        count++;
    }
    if (cmdLineArgs.isSpecified(xmlOtuputFormat)) {
        System.out.println("Set output format to XML");
        converter = new XMLConverter();
        count++;
    }
    if (cmdLineArgs.isSpecified(txtOtuputFormat)) {
        System.out.println("Set output format to plain ASCII text");
        converter = new TextConverter(cols);
        count++;
    }
    if (cmdLineArgs.isSpecified(twikiOtuputFormat)) {
        System.out.println("Set output format to Twiki table");
        converter = new TwikiTableConverter(cols);
        count++;
    }
    if (count == 0) {
        // No converter ==> Use XML by default
        converter = new XMLConverter();
        System.out.println("No output format specified: using default XML.");
    } else if (count > 1) {
        // Too many output formats
        throw new IllegalStateException("Too many output format specified.");
    }
    // SOURCES
    if (cmdLineArgs.isSpecified(sourceFilesOption)) {
        sourceFileNames = cmdLineArgs.getValues(sourceFilesOption);
        if (sourceFileNames == null || sourceFileNames.length < 1) {
            throw new IllegalStateException("Wrong or missing source file names");
        }
    } else {
    // This is not an error: if the param is missing, the
    // the tool read logs from the command line
    }
    // DESTINATION
    if (cmdLineArgs.isSpecified(dstFileOption)) {
        String[] val = cmdLineArgs.getValues(dstFileOption);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("Wrong or missing time (minutes)");
        }
        destFileName = val[0];
    } else {
        throw new IllegalStateException("No destination file in command line.");
    }
}
Also used : CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) ParseException(java.text.ParseException) CmdLineArgs(alma.acs.util.CmdLineArgs)

Example 10 with CmdLineRegisteredOption

use of alma.acs.util.CmdLineRegisteredOption in project ACS by ACS-Community.

the class LogMonitor method parseCmdLineArgs.

/**
	 * Parse the command line
	 * 
	 * @param args The command line params
	 * @return true if the user asked for help
	 */
private boolean parseCmdLineArgs(String[] args) {
    CmdLineArgs cmdLineArgs = new CmdLineArgs();
    CmdLineRegisteredOption dumpOpt = new CmdLineRegisteredOption("-d", "--dump", 0);
    cmdLineArgs.registerOption(dumpOpt);
    CmdLineRegisteredOption textOpt = new CmdLineRegisteredOption("-t", "--text", 0);
    cmdLineArgs.registerOption(textOpt);
    CmdLineRegisteredOption helpOpt = new CmdLineRegisteredOption("-h", "--help", 0);
    cmdLineArgs.registerOption(helpOpt);
    CmdLineRegisteredOption foldOpt = new CmdLineRegisteredOption("-f", "--folder", 0);
    cmdLineArgs.registerOption(foldOpt);
    cmdLineArgs.parseArgs(args);
    if (cmdLineArgs.isSpecified(helpOpt)) {
        LogMonitor.printUsage();
        return true;
    }
    if (cmdLineArgs.isSpecified(textOpt)) {
        gui = false;
    } else {
        gui = true;
    }
    if (cmdLineArgs.isSpecified(dumpOpt)) {
        outputOnfiles = true;
    } else {
        outputOnfiles = false;
    }
    if (cmdLineArgs.isSpecified(foldOpt)) {
        String[] val = cmdLineArgs.getValues(foldOpt);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("Wrong or missing time (minutes)");
        }
        folder = val[0];
    }
    return false;
}
Also used : CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) CmdLineArgs(alma.acs.util.CmdLineArgs)

Aggregations

CmdLineRegisteredOption (alma.acs.util.CmdLineRegisteredOption)11 CmdLineArgs (alma.acs.util.CmdLineArgs)9 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 AcsJContainerEx (alma.JavaContainerError.wrappers.AcsJContainerEx)1 EntryFile (alma.acs.releasedoc.Cvs2clXmlEntry.EntryFile)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 ParseException (java.text.ParseException)1