List of usage examples for org.apache.commons.cli MissingArgumentException getMessage
public String getMessage()
From source file:com.speed.ob.Obfuscator.java
public static void main(String[] args) { Options options = new Options(); options.addOption("a", "all", false, "enable all obfuscations"); options.addOption("s", "strings", false, "enable string obfuscation"); options.addOption("l", "lexical", false, "enable lexical obfuscation"); options.addOption("c", "control-flow", false, "enable control flow obfuscation"); options.addOption("C", "config", true, "use <arg> as a config file"); options.addOption("f", "file", true, "obfuscate file <arg>"); options.addOption("o", "out", true, "output obfuscated file(s) to directory <arg>"); options.addOption("h", "help", false, "shows this help message and then exits"); CommandLineParser parser = new GnuParser(); HelpFormatter formatter = new HelpFormatter(); try {//from ww w.ja va 2s. c o m CommandLine cmd = parser.parse(options, args); parse(cmd, parser, options, formatter); } catch (MissingArgumentException e) { System.out.println(e.getMessage()); formatter.printHelp("java com.speed.ob.Obfuscate", options, true); } catch (ParseException e) { e.printStackTrace(); } }
From source file:mitm.common.tools.PfxTool.java
public static void main(String[] args) throws Exception { PfxTool tool = new PfxTool(); try {/*from w w w . j a va 2 s. c o m*/ tool.handleCommandline(args); } catch (MissingArgumentException e) { System.err.println("Not all required parameters are specified. " + e.getMessage()); System.exit(3); } catch (MissingOptionException e) { System.err.println("Not all required options are specified. " + e.getMessage()); System.exit(4); } catch (UnrecognizedOptionException e) { System.err.println("Unknown option specified. " + e.getMessage()); System.exit(4); } }
From source file:com.j2biz.pencil.Starter.java
private static void exitCauseMissingArgument(MissingArgumentException e) { System.err.println("Missing Argument-Value. " + e.getMessage()); System.exit(-1);/*from w w w .java 2s .c o m*/ }
From source file:com.itmanwuiso.checksums.FileDuplicateChecker.java
private static boolean setSettings(String[] args) { Options opt = options();/* w ww . j ava 2 s . c om*/ List<String> hashes = new LinkedList<String>(); if (null == writers) { writers = new LinkedList<ResultWriter>(); } try { cmd = parser.parse(opt, args); if (cmd.hasOption("h") || cmd.hasOption("help")) { lvFormater.printHelp(FileDuplicateChecker.class.toString(), opt); return false; } // Verbose quite = !cmd.hasOption("v"); // START Hashes if (cmd.hasOption("as")) { hashes.add(HashComputer.HASH_MD5); hashes.add(HashComputer.HASH_SHA1); hashes.add(HashComputer.HASH_SHA256); hashes.add(HashComputer.HASH_SHA512); } else { if (cmd.hasOption("md5")) { hashes.add(HashComputer.HASH_MD5); } if (cmd.hasOption("sha1")) { hashes.add(HashComputer.HASH_SHA1); } if (cmd.hasOption("sha256")) { hashes.add(HashComputer.HASH_SHA256); } if (cmd.hasOption("sha512")) { hashes.add(HashComputer.HASH_SHA512); } } if (hashes.isEmpty()) { throw new ParseException("at least one hash must be given."); } else { FileDuplicateChecker.hashers = new String[hashes.size()]; int i = 0; for (String hash : hashes) { FileDuplicateChecker.hashers[i++] = hash; } } // END Hashes // START Path if (cmd.hasOption("p")) { rootPath = cmd.getOptionValue("p"); recursive = cmd.hasOption('r'); } else { throw new ParseException("Path is missing."); } // END Path // Start Format if (cmd.hasOption("fj")) { String fileName = cmd.getOptionValue("fj"); logger.error(fileName); File f = new File(fileName); writers.add(new ResultJSONWriter(f)); } else if (cmd.hasOption("fx")) { throw new ParseException(null); } else { throw new ParseException(null); } // END Format } catch (MissingArgumentException e) { if (null != e.getMessage()) { System.out.println(e.getMessage()); } lvFormater.printHelp(FileDuplicateChecker.class.toString(), opt); return false; } catch (ParseException pvException) { if (null != pvException.getMessage()) { System.out.println(pvException.getMessage()); } lvFormater.printHelp(FileDuplicateChecker.class.toString(), opt); return false; } return true; }
From source file:jp.andeb.obbutil.ObbUtilMain.java
private static boolean doAdd(String[] args) { final CommandLine commandLine; try {//w w w. j a v a2 s . c o m final CommandLineParser parser = new GnuParser(); commandLine = parser.parse(OPTIONS_FOR_ADD, args); } catch (MissingArgumentException e) { System.err.println("??????: " + e.getOption().getOpt()); printUsage(PROGNAME); return false; } catch (MissingOptionException e) { System.err.println("??????: " + e.getMissingOptions()); printUsage(PROGNAME); return false; } catch (UnrecognizedOptionException e) { System.err.println("????: " + e.getOption()); printUsage(PROGNAME); return false; } catch (ParseException e) { System.err.println(e.getMessage()); printUsage(PROGNAME); return false; } final String pkgName = commandLine.getOptionValue(PACKAGE_NAME.getOpt()); final String versionStr = commandLine.getOptionValue(OBB_VERSION.getOpt()); final Integer version = toInteger(versionStr); if (version == null) { System.err.println("??????: " + versionStr); printUsage(PROGNAME); return false; } final boolean isOverlay = commandLine.hasOption(OVERLAY_FLAG.getOpt()); final String saltStr = commandLine.getOptionValue(SALT.getOpt()); final byte[] salt; if (saltStr == null) { salt = null; } else { salt = toByteArray(saltStr, ObbInfoV1.SALT_LENGTH); if (salt == null) { System.err.println("????: " + saltStr); printUsage(PROGNAME); return false; } } final String[] nonRecognizedArgs = commandLine.getArgs(); if (nonRecognizedArgs.length == 0) { System.err.println("????????"); printUsage(PROGNAME); return false; } if (nonRecognizedArgs.length != 1) { System.err.println("???????"); printUsage(PROGNAME); return false; } final File targetFile = new File(nonRecognizedArgs[0]); final RandomAccessFile targetRaFile; try { targetRaFile = new RandomAccessFile(targetFile, "rw"); } catch (FileNotFoundException e) { System.err.println("????: " + targetFile.getPath()); return false; } try { try { final ObbInfoV1 info = ObbInfoV1.fromFile(targetRaFile); System.err.println( "?? OBB ???????: " + info.toString()); return false; } catch (IOException e) { System.err .println("????????: " + targetFile.getPath()); return false; } catch (NotObbException e) { // } int flag = 0; if (isOverlay) { flag |= ObbInfoV1.FLAG_OVERLAY; } if (salt != null) { flag |= ObbInfoV1.FLAG_SALTED; } final ObbInfoV1 obbInfo = new ObbInfoV1(flag, salt, pkgName, version.intValue()); final ByteBuffer obbInfoBytes = obbInfo.toBytes(); // ??? targetRaFile.setLength(targetRaFile.length() + obbInfoBytes.remaining()); targetRaFile.seek(targetRaFile.length() - obbInfoBytes.remaining()); targetRaFile.write(obbInfoBytes.array(), obbInfoBytes.arrayOffset(), obbInfoBytes.remaining()); } catch (IOException e) { System.err.println("OBB ?????????: " + targetFile.getPath()); return false; } finally { try { targetRaFile.close(); } catch (IOException e) { System.err.println("OBB ?????????: " + targetFile.getPath()); return false; } } System.err.println("OBB ??????????: " + targetFile.getPath()); return true; }
From source file:com.hp.mqm.clt.CliParserTest.java
@Test public void testArgs_missingArgument() throws ParseException { CommandLineParser parser = new DefaultParser(); try {// w w w. j a v a 2s.com parser.parse(options, new String[] { "-i", "-d" }); Assert.fail(); } catch (MissingArgumentException e) { Assert.assertEquals("Missing argument for option: d", e.getMessage()); } }
From source file:com.coprtools.core.CopyrightToolsEngine.java
@Override public void run() { LOGGER.setLevel(Level.SEVERE); try {/* w ww.j a v a 2 s .co m*/ this.cli.parse(); if (cli.hasOption(OptionConstants.HELP_SHORT)) { cli.showUsage(); } else if (cli.getArguments().length == 0) { throw new MissingArgumentException("Missing command!"); } else { String textConsoleCommand = cli.getArguments()[0]; String rootFolderPath = cli.getOptionValue(OptionConstants.ROOT_SHORT); String noticePath = cli.getOptionValue(OptionConstants.NOTICE_SHORT); String[] extensions = cli.getOptionValues(OptionConstants.EXTENSION_SHORT); String newNotice = null; if (cli.hasOption(OptionConstants.NEW_NOTICE_SHORT) && !cli.hasOption(OptionConstants.STRING_SHORT)) { String newNoticePath = cli.getOptionValue(OptionConstants.NEW_NOTICE_SHORT); File newNoticeFile = new File(newNoticePath); newNotice = this.manipulator.readFromFile(newNoticeFile); } File rootDir = new File(rootFolderPath); File destinationFolder = null; if (cli.hasOption(OptionConstants.OUTPUT_SHORT)) { String destinationPath = cli.getOptionValue(OptionConstants.OUTPUT_SHORT); destinationFolder = new File(destinationPath); this.manipulator.copyFolder(rootDir, destinationFolder); rootDir = destinationFolder; } // Enables logging and creates a log file in the root path if (cli.hasOption(OptionConstants.INFO_LONG)) { this.enableLogging(rootDir.getAbsolutePath()); } String notice = null; if (cli.hasOption(OptionConstants.STRING_SHORT)) { notice = cli.getOptionValue(OptionConstants.NOTICE_SHORT); newNotice = cli.getOptionValue(OptionConstants.NEW_NOTICE_SHORT); } else { File noticeFile = new File(noticePath); notice = this.manipulator.readFromFile(noticeFile); if (cli.hasOption(OptionConstants.BLANK_SHORT)) { notice = insertBlankSpace(notice); } } CommandType commandType = resolveCommandType(textConsoleCommand); AbstractCommand command = commandFactory.create(commandType, notice, extensions, this.manipulator, newNotice); command.executeRecursively(rootDir); if (!command.isHasError()) { writer.writeLine(UserMessagesConstants.SUCCESFULL_OPERATION_MESSAGE); } else { writer.writeLine(UserMessagesConstants.FAILD_OPERTION_MESSAGE, rootDir.getAbsolutePath() + File.separator + InserterConstants.LOG_FILENAME); } if (this.fileHandler != null) { this.fileHandler.close(); LOGGER.removeHandler(this.fileHandler); } } } catch (MissingArgumentException e) { LOGGER.log(Level.SEVERE, e.getMessage()); } catch (ArgumentParseException e) { LOGGER.log(Level.SEVERE, "Error while parsing arguments: " + e.getMessage()); } catch (FileNotFoundException e) { LOGGER.log(Level.SEVERE, e.getMessage()); } catch (SecurityException e) { LOGGER.log(Level.SEVERE, "Security violation has occurred: " + e.getMessage()); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage()); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Unknown exception: " + e.getClass().getName() + " " + e.getMessage()); } }
From source file:com.aliyun.odps.ship.optionparser.ParseUploadCommandTest.java
/** * ?-fd=?-fd<br/>//from w w w . j a v a 2 s . c o m */ @Test public void testLostOption() throws Exception { String[] args; try { args = new String[] { "upload", "src/test/resources/test_data.txt", "test_table/ds='2113',pt='pttest'", "-fd" }; OptionsBuilder.buildUploadOption(args); fail("need fail"); } catch (MissingArgumentException e) { assertTrue(e.getMessage(), e.getMessage().indexOf("Missing argument") >= 0); } }
From source file:org.apache.cassandra.tools.Shuffle.java
/** * Execute./* ww w .ja va 2 s . c om*/ * * @param args arguments passed on the command line * @throws Exception when face meets palm */ public static void main(String[] args) throws Exception { CommandLine cmd = null; try { cmd = processArguments(args); } catch (MissingArgumentException e) { System.err.println(e.getMessage()); System.exit(1); } // Sub command argument. if (cmd.getArgList().size() < 1) { System.err.println("Missing sub-command argument."); printShuffleHelp(); System.exit(1); } String subCommand = (String) (cmd.getArgList()).get(0); String hostName = (cmd.getOptionValue("host") != null) ? cmd.getOptionValue("host") : DEFAULT_HOST; String port = (cmd.getOptionValue("port") != null) ? cmd.getOptionValue("port") : Integer.toString(DEFAULT_JMX_PORT); String username = cmd.getOptionValue("username"); String password = cmd.getOptionValue("password"); String thriftHost = (cmd.getOptionValue("thrift-host") != null) ? cmd.getOptionValue("thrift-host") : hostName; String thriftPort = (cmd.getOptionValue("thrift-port") != null) ? cmd.getOptionValue("thrift-port") : "9160"; String onlyDc = cmd.getOptionValue("only-dc"); boolean thriftFramed = cmd.hasOption("thrift-framed") ? true : false; boolean andEnable = cmd.hasOption("and-enable") ? true : false; int portNum = -1, thriftPortNum = -1; // Parse JMX port number if (port != null) { try { portNum = Integer.parseInt(port); } catch (NumberFormatException ferr) { System.err.printf("%s is not a valid JMX port number.%n", port); System.exit(1); } } else portNum = DEFAULT_JMX_PORT; // Parse Thrift port number if (thriftPort != null) { try { thriftPortNum = Integer.parseInt(thriftPort); } catch (NumberFormatException ferr) { System.err.printf("%s is not a valid port number.%n", thriftPort); System.exit(1); } } else thriftPortNum = 9160; Shuffle shuffler = new Shuffle(hostName, portNum, thriftHost, thriftPortNum, thriftFramed, username, password); try { if (subCommand.equals("create")) shuffler.shuffle(andEnable, onlyDc); else if (subCommand.equals("ls")) shuffler.ls(); else if (subCommand.startsWith("en")) shuffler.enable(); else if (subCommand.startsWith("dis")) shuffler.disable(); else if (subCommand.equals("clear")) shuffler.clear(); else { System.err.println("Unknown subcommand: " + subCommand); printShuffleHelp(); System.exit(1); } } catch (ShuffleError err) { shuffler.writeln(err); System.exit(1); } finally { shuffler.close(); } System.exit(0); }
From source file:org.apache.directory.server.tools.BaseCommand.java
public CommandLine getCommandLine(String command, String[] args) { Options all = allOptions(command);/*from w w w . j a v a2 s . c o m*/ CommandLineParser parser = new PosixParser(); CommandLine cmdline = null; try { cmdline = parser.parse(all, args); } catch (AlreadySelectedException ase) { System.err.println("Command line parsing failed for " + command + ". Reason: already selected " + ase.getMessage()); System.exit(1); } catch (MissingArgumentException mae) { System.err.println("Command line parsing failed for " + command + ". Reason: missing argument " + mae.getMessage()); System.exit(1); } catch (MissingOptionException moe) { System.err.println( "Command line parsing failed for " + command + ". Reason: missing option " + moe.getMessage()); System.exit(1); } catch (UnrecognizedOptionException uoe) { System.err.println("Command line parsing failed for " + command + ". Reason: unrecognized option" + uoe.getMessage()); System.exit(1); } catch (ParseException pe) { System.err.println("Command line parsing failed for " + command + ". Reason: " + pe.getClass()); System.exit(1); } return cmdline; }