Search in sources :

Example 6 with CmdLineArgs

use of alma.acs.util.CmdLineArgs 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 CmdLineArgs

use of alma.acs.util.CmdLineArgs 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 8 with CmdLineArgs

use of alma.acs.util.CmdLineArgs 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)

Example 9 with CmdLineArgs

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

the class CommandLineParser method parse.

/**
	 * Parse the command line.
	 * 
	 * @throws Exception In case of error parsing the command line
	 */
private void parse(String[] args) throws Exception {
    CmdLineArgs cmdLineArgs = new CmdLineArgs();
    // Register the options
    CmdLineRegisteredOption helpCmd = new CmdLineRegisteredOption("-h", "--help", 0);
    cmdLineArgs.registerOption(helpCmd);
    CmdLineRegisteredOption filterCmd = new CmdLineRegisteredOption("-f", "--filter", 0);
    cmdLineArgs.registerOption(filterCmd);
    CmdLineRegisteredOption engineFilterCmd = new CmdLineRegisteredOption("-e", "--engineFilter", 0);
    cmdLineArgs.registerOption(engineFilterCmd);
    CmdLineRegisteredOption discardCmd = new CmdLineRegisteredOption("-d", "--discard", 0);
    cmdLineArgs.registerOption(discardCmd);
    CmdLineRegisteredOption doNotConnectCmd = new CmdLineRegisteredOption("-dnc", "--DoNotConnect", 0);
    cmdLineArgs.registerOption(doNotConnectCmd);
    CmdLineRegisteredOption unlimitedCmd = new CmdLineRegisteredOption("-u", "--unlimited", 0);
    cmdLineArgs.registerOption(unlimitedCmd);
    CmdLineRegisteredOption loadCmd = new CmdLineRegisteredOption("-l", "--load", 0);
    cmdLineArgs.registerOption(loadCmd);
    CmdLineRegisteredOption audienceCmd = new CmdLineRegisteredOption("-a", "--audience", 0);
    cmdLineArgs.registerOption(audienceCmd);
    // Parse
    cmdLineArgs.parseArgs(args);
    // Get values
    if (cmdLineArgs.isSpecified(helpCmd)) {
        help = true;
    }
    if (cmdLineArgs.isSpecified(filterCmd)) {
        String[] val = cmdLineArgs.getValues(filterCmd);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("Filter file name missing");
        }
        filterFileName = val[0];
    }
    if (cmdLineArgs.isSpecified(engineFilterCmd)) {
        String[] val = cmdLineArgs.getValues(engineFilterCmd);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("Engine filter file name missing");
        }
        engineFilterFileName = val[0];
    }
    if (cmdLineArgs.isSpecified(discardCmd)) {
        String[] val = cmdLineArgs.getValues(discardCmd);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("Discard level missing ");
        }
        discardLevel = LogTypeHelper.fromLogTypeDescription(val[0]);
        if (discardLevel == null && !(val[0].compareToIgnoreCase("None") == 0)) {
            throw new Exception("Invalid discard level " + val[0]);
        }
    }
    if (cmdLineArgs.isSpecified(doNotConnectCmd)) {
        doNotConnect = true;
    }
    if (cmdLineArgs.isSpecified(unlimitedCmd)) {
        unlimited = true;
    }
    if (cmdLineArgs.isSpecified(loadCmd)) {
        String[] val = cmdLineArgs.getValues(loadCmd);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("File name of logs to load mssing");
        }
        fileToLoad = val[0];
    }
    if (cmdLineArgs.isSpecified(audienceCmd)) {
        String[] val = cmdLineArgs.getValues(audienceCmd);
        if (val == null || val.length < 1) {
            throw new IllegalStateException("Audience mssing");
        }
        audience = AudienceInfo.fromShortName(val[0]);
    }
}
Also used : CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) CmdLineArgs(alma.acs.util.CmdLineArgs)

Aggregations

CmdLineArgs (alma.acs.util.CmdLineArgs)9 CmdLineRegisteredOption (alma.acs.util.CmdLineRegisteredOption)9 BufferedReader (java.io.BufferedReader)2 File (java.io.File)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