private static void printHelp(final PrintStream ps) { printUsage(ps); ps.println(); ps.println("Available options are :"); int maxCol = 0; for (final CmdOption opt : options.getOptions()) { final int col = 2 + opt.getPrototype().length(); if (col > maxCol) maxCol = col; } for (final CmdOption opt : options.getOptions()) { final StringBuffer sb = new StringBuffer(" "); sb.append(opt.getPrototype()); while (sb.length() < maxCol) sb.append(' '); sb.append(" ").append(opt.getDescription()); ps.println(sb); } }
/** * @param args * @throws InvalidCommandLineException */ public void run(String[] args) { int dot = args[0].lastIndexOf(java.io.File.pathSeparatorChar); if (dot == -1) { executableOpt = new CmdArgument( ID_PREFIX + "Executable", null, "executable", "The path of the compiler executable, or simply its name if it ", "EXECUTABLE", null, false); } else { executableOpt = new CmdArgument( ID_PREFIX + "Executable", args[0].substring(+1, args[0].length()), "executable", "The path of the compiler executable, or simply its name if it ", "EXECUTABLE", null, false); } options.addOptions( executableOpt, helpOpt, preprocessOpt, compileOpt, inputFileOpt, outputFileOpt, flagsOpt, defineOpt, includeDirOpt, preIncludeFileOpt, dependencyFileOpt); try { cmdLine = CommandLine.parseArgs(options, false, args); } catch (InvalidCommandLineException e) { System.out.println(e.getMessage()); System.out.println(); printHelp(System.out); System.exit(-1); } // If help is asked, print it and exit. if (helpOpt.isPresent(cmdLine)) { printHelp(System.out); System.exit(0); } // If two actions are specified exit. if (compileOpt.isPresent(cmdLine) && preprocessOpt.isPresent(cmdLine)) { printActionHelp(System.out); System.exit(-1); } // If no action are specified exit. if (!compileOpt.isPresent(cmdLine) && !preprocessOpt.isPresent(cmdLine)) { printActionHelp(System.out); System.exit(-1); } if (!inputFileOpt.isPresent(cmdLine)) { printInputHelp(System.out); System.exit(-1); } if (!outputFileOpt.isPresent(cmdLine)) { printOutputHelp(System.out); System.exit(-1); } if (!(new File(inputFileOpt.getValue(cmdLine))).isFile()) { printMissingInputFileHelp(System.out); System.exit(-1); } if (preprocessOpt.isPresent(cmdLine)) { executor.preprocess(cmdLine); System.exit(0); } if (dependencyFileOpt.isPresent(cmdLine)) { printDependencyWhileCompilingHelp(System.out); System.exit(-1); } if (compileOpt.isPresent(cmdLine)) { executor.compile(cmdLine); System.exit(0); } }