Package jargs.gnu

Examples of jargs.gnu.CmdLineParser


        if (args.length<2) {
            System.out.println("No arguments specified!\n");
            throw new InvalidParameterException("No arguments specified!");
        }

        CmdLineParser parser = new CmdLineParser();
        CmdLineParser.Option host = parser.addStringOption('h', PARAM_HOST);
        CmdLineParser.Option port = parser.addIntegerOption('p', PARAM_PORT);
        CmdLineParser.Option command = parser.addStringOption('c', PARAM_COMMAND);

        String pCmd = "undefined";
        try {
            parser.parse(args);
            String pHost = (String)parser.getOptionValue(host, DEFAULT_HOST);
            int pPort = (Integer)parser.getOptionValue(port, DEFAULT_PORT);
            pCmd = (String)parser.getOptionValue(command);       
            if (pCmd==null) {
                System.out.println("Unknown Command: "+ArrayUtils.toString(args));
                System.out.println("Exit now");
                throw new IllegalArgumentException("no ValidCommand specified!");
            }
           
            ValidCommands parsedCommand = ValidCommands.valueOf(pCmd.toUpperCase());
            String[] otherArgs = parser.getRemainingArgs();
           
            if (parsedCommand.getNrOfParams() < otherArgs.length) {
              String err = "Invalid parameter count, expected: "+parsedCommand.getNrOfParams()+", provided: "+otherArgs.length;
              System.out.println(err);
              throw new InvalidParameterException(err);
View Full Code Here

TOP

Related Classes of jargs.gnu.CmdLineParser

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.