Java tutorial
/******************************************************************************* * This file is part of minipas. * * minipas is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * minipas is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with minipas. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ package ar.com.ergio.uncoma.cei; import java.io.IOException; import java.util.Arrays; import java.util.logging.ConsoleHandler; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import ar.com.ergio.uncoma.cei.lex.Scanner; /** * Main Class for compiler. * * @author Emiliano Pereyra * */ public class MiniPas { private static final Logger ROOT_LOG = Logger.getLogger("ar.com.ergio.uncoma.cei"); /** * @param args * @throws IOException */ @SuppressWarnings("static-access") public static void main(String[] args) throws IOException { // Config logging system -- TODO improve this Handler console = new ConsoleHandler(); ROOT_LOG.addHandler(console); // Create cmdline options - TODO - I18N final Options options = new Options(); options.addOption(new Option("help", "Muestra este mensaje")); options.addOption(new Option("version", "Muestra la informaci\u00f3 de versi\u00f3n y termina")); options.addOption(new Option("debug", "Muestra informaci\u00f3n para depuraci\u00f3n")); options.addOption( OptionBuilder.withArgName("file").hasArg().withDescription("Archivo de log").create("logFile")); final CommandLineParser cmdlineParser = new GnuParser(); final HelpFormatter formatter = new HelpFormatter(); try { final CommandLine cmdline = cmdlineParser.parse(options, args); // Process command line args -- TODO Improve this if (args.length == 0 || cmdline.hasOption("help")) { formatter.printHelp("minipas", options, true); } else if (cmdline.hasOption("version")) { System.out.println("MiniPas versi\u00f3n: 0.0.1"); } else if (cmdline.hasOption("debug")) { ROOT_LOG.setLevel(Level.FINE); } else { ROOT_LOG.fine("Arguments: " + Arrays.toString(args)); final Scanner scanner = new Scanner(args[0]); while (scanner.hasTokens()) { System.out.println(scanner.nextToken()); } } } catch (ParseException e) { formatter.printHelp("minipas", options, true); } } }