Search in sources :

Example 1 with Getopt

use of gnu.getopt.Getopt in project ACS by ACS-Community.

the class CDBChecker method checkArgs.

/**
	 * Checks the command line arguments given to the program and capture the given flags.
	 * @param args command line arguments
	 * @return True if arguments are OK, false otherwise 
	 */
protected boolean checkArgs(String[] args) {
    boolean retVal = true;
    int c;
    LongOpt[] longopts = new LongOpt[5];
    longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
    longopts[1] = new LongOpt("network", LongOpt.NO_ARGUMENT, null, 'n');
    longopts[2] = new LongOpt("verbose", LongOpt.NO_ARGUMENT, null, 'v');
    longopts[3] = new LongOpt("recursive", LongOpt.NO_ARGUMENT, null, 'r');
    longopts[4] = new LongOpt("checkIdlTypes", LongOpt.NO_ARGUMENT, null, 'c');
    Getopt myGetOpt = new Getopt("cdbChecker", args, "rhncvaW;", longopts);
    // We'll do our own error handling
    myGetOpt.setOpterr(false);
    while ((c = myGetOpt.getopt()) != -1) {
        switch(c) {
            case 'n':
                this.network = true;
                break;
            case 'r':
                this.recursive = false;
                break;
            case 'v':
                this.verbose = true;
                break;
            case 'h':
                retVal = false;
                break;
            case 'c':
                this.checkidl = true;
                break;
            case 'W':
                System.out.println("[Error] : you tried a -W with an incorrect long option name");
                globalErrorFlag = true;
                retVal = false;
                break;
            case '?':
                if (0 == myGetOpt.getOptopt()) {
                    System.out.println("[Error] : the long option '" + args[myGetOpt.getOptind() - 1] + "' is not valid");
                } else {
                    System.out.println("[Error] : the option '" + (char) myGetOpt.getOptopt() + "' is not valid");
                }
                globalErrorFlag = true;
                retVal = false;
                break;
            default:
                globalErrorFlag = true;
                retVal = false;
                break;
        }
    }
    // do the following only if we aren't already needing to pretVal is not false)
    if (retVal) {
        // check for the additional (optional) command line arguments, XMLPath and XSDPath
        for (int i = myGetOpt.getOptind(); i < args.length; i++) {
            if (myGetOpt.getOptind() == i) {
                if (args[i].startsWith("/") || args[i].matches("[a-zA-Z]:.*")) {
                    this.XMLPath = args[i];
                } else {
                    System.out.println("[Error] : XMLPath must start with '/'");
                    globalErrorFlag = true;
                    retVal = false;
                }
            } else {
                if (args[i].startsWith("/") || args[i].matches("[a-zA-Z]:.*")) {
                    this.XSDPath = args[i];
                } else {
                    System.out.println("[Error] : XSDPath must start with '/'");
                    globalErrorFlag = true;
                    retVal = false;
                }
                break;
            }
        }
        if (retVal && null == this.XMLPath) {
            String acsCdbPath = System.getenv("ACS_CDB");
            if (null != acsCdbPath) {
                acsCdbPath += File.separator + "CDB";
                System.out.println("*** XML path not specified; defaulting to $ACS_CDB" + File.separator + "CDB: " + acsCdbPath);
                XMLPath = acsCdbPath;
            } else {
                System.out.println("\n[Error] XML path not specified and $ACS_CDB environment variable not set; no default possible.");
                globalErrorFlag = true;
                retVal = false;
            }
        }
    }
    return retVal;
}
Also used : Getopt(gnu.getopt.Getopt) LongOpt(gnu.getopt.LongOpt)

Example 2 with Getopt

use of gnu.getopt.Getopt in project smscgateway by RestComm.

the class Main method processCommandLine.

private void processCommandLine(String[] args) {
    String programName = System.getProperty("program.name", "Mobicents Media Server");
    int c;
    String arg;
    LongOpt[] longopts = new LongOpt[2];
    longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
    longopts[1] = new LongOpt("host", LongOpt.REQUIRED_ARGUMENT, null, 'b');
    Getopt g = new Getopt("SMSC", args, "-:b:h", longopts);
    // We'll do our own error handling
    g.setOpterr(false);
    // 
    while ((c = g.getopt()) != -1) {
        switch(c) {
            // 
            case 'b':
                arg = g.getOptarg();
                System.setProperty(SMSC_HLR_BIND_ADDRESS, arg);
                break;
            case 'h':
                System.out.println("usage: " + programName + " [options]");
                System.out.println();
                System.out.println("options:");
                System.out.println("    -h, --help                    Show this help message");
                System.out.println("    -b, --host=<host or ip>       Bind address for all Mobicents SMSC services");
                System.out.println();
                System.exit(0);
                break;
            case ':':
                System.out.println("You need an argument for option " + (char) g.getOptopt());
                System.exit(0);
                break;
            // 
            case '?':
                System.out.println("The option '" + (char) g.getOptopt() + "' is not valid");
                System.exit(0);
                break;
            // 
            default:
                System.out.println("getopt() returned " + c);
                break;
        }
    }
    if (System.getProperty(SMSC_HLR_BIND_ADDRESS) == null) {
        System.setProperty(SMSC_HLR_BIND_ADDRESS, "127.0.0.1");
    }
}
Also used : Getopt(gnu.getopt.Getopt) LongOpt(gnu.getopt.LongOpt)

Example 3 with Getopt

use of gnu.getopt.Getopt in project gate-core by GateNLP.

the class ValueComparator method parseArguments.

/**
 * Parses the report arguments.
 *
 * @param args
 *          A string array containing the command line arguments.
 */
@Override
public void parseArguments(String[] args) {
    Getopt g = new Getopt("gate.util.reporting.PRTimeReporter", args, "i:m:z:s:o:l:h");
    int choice;
    String argSuppressZeroTimeEntries = null;
    while ((choice = g.getopt()) != -1) {
        switch(choice) {
            // -i inputFile
            case 'i':
                String argInPath = g.getOptarg();
                if (argInPath != null) {
                    setBenchmarkFile(new File(argInPath));
                }
                break;
            // -m printMedia
            case 'm':
                String argPrintMedia = g.getOptarg();
                if (argPrintMedia != null) {
                    setPrintMedia(argPrintMedia);
                } else {
                    setPrintMedia(printMedia);
                }
                break;
            // -z suppressZeroTimeEntries
            case 'z':
                argSuppressZeroTimeEntries = g.getOptarg();
                if (argSuppressZeroTimeEntries == null) {
                    setSuppressZeroTimeEntries(suppressZeroTimeEntries);
                }
                break;
            // -s sortOrder
            case 's':
                String argSortOrder = g.getOptarg();
                if (argSortOrder != null) {
                    setSortOrder(argSortOrder);
                } else {
                    setSortOrder(sortOrder);
                }
                break;
            // -o ReportFile
            case 'o':
                String argOutPath = g.getOptarg();
                if (argOutPath != null) {
                    setReportFile(new File(argOutPath));
                }
                break;
            // -l logical start
            case 'l':
                String argLogicalStart = g.getOptarg();
                if (argLogicalStart != null) {
                    setLogicalStart(argLogicalStart);
                }
                break;
            // -h
            case 'h':
            case '?':
                usage();
                System.exit(STATUS_NORMAL);
                break;
            default:
                usage();
                System.exit(STATUS_ERROR);
                break;
        }
    // getopt switch
    }
    if (argSuppressZeroTimeEntries != null) {
        if (argSuppressZeroTimeEntries.trim().equalsIgnoreCase("true")) {
            setSuppressZeroTimeEntries(true);
        } else if (argSuppressZeroTimeEntries.trim().equalsIgnoreCase("false")) {
            setSuppressZeroTimeEntries(false);
        } else {
            System.err.println("Suppress Zero Time Entries: parameter value" + NL + " passed is invalid. Please provide true or false as value.");
            usage();
            System.exit(STATUS_ERROR);
        }
    }
}
Also used : Getopt(gnu.getopt.Getopt) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 4 with Getopt

use of gnu.getopt.Getopt in project gate-core by GateNLP.

the class FileWatcher method parseArguments.

/**
 * Parses the report command lime arguments.
 *
 * @param args array containing the command line arguments.
 */
@Override
public void parseArguments(String[] args) {
    Getopt g = new Getopt("gate.util.reporting.DocTimeReporter", args, "i:m:d:p:o:l:h");
    int c;
    String argNoOfDocs = null;
    while ((c = g.getopt()) != -1) {
        switch(c) {
            // -i inputFile
            case 'i':
                String argInPath = g.getOptarg();
                if (argInPath != null) {
                    setBenchmarkFile(new File(argInPath));
                }
                break;
            // -m printMedia
            case 'm':
                String argPrintMedia = g.getOptarg();
                if (argPrintMedia != null) {
                    setPrintMedia(argPrintMedia);
                }
                break;
            // -d noOfDocs
            case 'd':
                argNoOfDocs = g.getOptarg();
                if (argNoOfDocs == null) {
                    setMaxDocumentInReport(maxDocumentInReport);
                }
                break;
            // -p prName
            case 'p':
                String argPrName = g.getOptarg();
                if (argPrName != null) {
                    setPRMatchingRegex(argPrName);
                } else {
                    setPRMatchingRegex(PRMatchingRegex);
                }
                break;
            // -o Report File
            case 'o':
                String argOutPath = g.getOptarg();
                if (argOutPath != null) {
                    setReportFile(new File(argOutPath));
                }
                break;
            // -l logical start
            case 'l':
                String argLogicalStart = g.getOptarg();
                if (argLogicalStart != null) {
                    setLogicalStart(argLogicalStart);
                }
                break;
            // -h usage information
            case 'h':
            case '?':
                usage();
                System.exit(STATUS_NORMAL);
                break;
            default:
                usage();
                System.exit(STATUS_ERROR);
                break;
        }
    // getopt switch
    }
    if (argNoOfDocs != null) {
        try {
            setMaxDocumentInReport(Integer.parseInt(argNoOfDocs));
        } catch (NumberFormatException e) {
            e.printStackTrace();
            usage();
            System.exit(STATUS_ERROR);
        }
    }
}
Also used : Getopt(gnu.getopt.Getopt) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 5 with Getopt

use of gnu.getopt.Getopt in project i2p.i2p by i2p.

the class SAMStreamSend method main.

public static void main(String[] args) {
    Getopt g = new Getopt("SAM", args, "sxhb:m:o:p:u:v:w:");
    boolean isSSL = false;
    boolean isMaster = false;
    int mode = STREAM;
    String version = "3.3";
    String host = "127.0.0.1";
    String port = "7656";
    String user = null;
    String password = null;
    String opts = "inbound.length=0 outbound.length=0";
    int c;
    while ((c = g.getopt()) != -1) {
        switch(c) {
            case 's':
                isSSL = true;
                break;
            case 'x':
                isMaster = true;
                break;
            case 'm':
                mode = Integer.parseInt(g.getOptarg());
                if (mode < 0 || mode > V1RAW) {
                    System.err.println(USAGE);
                    return;
                }
                break;
            case 'v':
                version = g.getOptarg();
                break;
            case 'b':
                host = g.getOptarg();
                break;
            case 'o':
                opts = opts + ' ' + g.getOptarg();
                break;
            case 'p':
                port = g.getOptarg();
                break;
            case 'u':
                user = g.getOptarg();
                break;
            case 'w':
                password = g.getOptarg();
                break;
            case 'h':
            case '?':
            case ':':
            default:
                System.err.println(USAGE);
                return;
        }
    // switch
    }
    // while
    int startArgs = g.getOptind();
    if (args.length - startArgs != 2) {
        System.err.println(USAGE);
        return;
    }
    if (isMaster) {
        mode += MASTER;
        version = "3.3";
    }
    if ((user == null && password != null) || (user != null && password == null)) {
        System.err.println("both user and password or neither");
        return;
    }
    if (user != null && password != null && VersionComparator.comp(version, "3.2") < 0) {
        System.err.println("user/password require 3.2");
        return;
    }
    I2PAppContext ctx = I2PAppContext.getGlobalContext();
    SAMStreamSend sender = new SAMStreamSend(ctx, host, port, args[startArgs], args[startArgs + 1]);
    sender.startup(version, isSSL, mode, user, password, opts);
}
Also used : Getopt(gnu.getopt.Getopt) I2PAppContext(net.i2p.I2PAppContext)

Aggregations

Getopt (gnu.getopt.Getopt)26 File (java.io.File)11 IOException (java.io.IOException)10 LongOpt (gnu.getopt.LongOpt)9 I2PAppContext (net.i2p.I2PAppContext)5 BufferedReader (java.io.BufferedReader)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 ArrayList (java.util.ArrayList)4 FileInputStream (java.io.FileInputStream)3 RandomAccessFile (java.io.RandomAccessFile)3 Properties (java.util.Properties)3 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 SocketException (java.net.SocketException)2 UnknownHostException (java.net.UnknownHostException)2 HashMap (java.util.HashMap)2 OrderedProperties (net.i2p.util.OrderedProperties)2 KeyCode_FileBased (automenta.rdp.keymapping.KeyCode_FileBased)1 KeyCode_FileBased_Localised (automenta.rdp.rdp.KeyCode_FileBased_Localised)1