Example usage for org.apache.commons.cli HelpFormatter HelpFormatter

List of usage examples for org.apache.commons.cli HelpFormatter HelpFormatter

Introduction

In this page you can find the example usage for org.apache.commons.cli HelpFormatter HelpFormatter.

Prototype

HelpFormatter

Source Link

Usage

From source file:com.guye.baffle.obfuscate.Main.java

public static void main(String[] args) throws IOException, BaffleException {
    Options opt = new Options();

    opt.addOption("c", "config", true, "config file path,keep or mapping");

    opt.addOption("o", "output", true, "output mapping writer file");

    opt.addOption("v", "verbose", false, "explain what is being done.");

    opt.addOption("h", "help", false, "print help for the command.");

    opt.getOption("c").setArgName("file list");

    opt.getOption("o").setArgName("file path");

    String formatstr = "baffle [-c/--config filepaths list ][-o/--output filepath][-h/--help] ApkFile TargetApkFile";

    HelpFormatter formatter = new HelpFormatter();
    CommandLineParser parser = new PosixParser();
    CommandLine cl = null;/*from  w  ww.j av a  2  s .  c  o  m*/
    try {
        // ?Options?
        cl = parser.parse(opt, args);

    } catch (ParseException e) {
        formatter.printHelp(formatstr, opt); // ???
        return;
    }

    if (cl == null || cl.getArgs() == null || cl.getArgs().length == 0) {
        formatter.printHelp(formatstr, opt);
        return;
    }

    // ?-h--help??
    if (cl.hasOption("h")) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp(formatstr, "", opt, "");
        return;
    }

    // ???DirectoryName
    String[] str = cl.getArgs();
    if (str == null || str.length != 2) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("not specify apk file or taget apk file", opt);
        return;
    }

    if (str[1].equals(str[0])) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("apk file can not rewrite , please specify new target file", opt);
        return;
    }
    File apkFile = new File(str[0]);
    if (!apkFile.exists()) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("apk file not exists", opt);
        return;
    }

    File[] configs = null;
    if (cl.hasOption("c")) {
        String cfg = cl.getOptionValue("c");
        String[] fs = cfg.split(",");
        int len = fs.length;
        configs = new File[fs.length];
        for (int i = 0; i < len; i++) {
            configs[i] = new File(fs[i]);
            if (!configs[i].exists()) {
                HelpFormatter hf = new HelpFormatter();
                hf.printHelp("config file " + fs[i] + " not exists", opt);
                return;
            }
        }
    }

    File mappingfile = null;
    if (cl.hasOption("o")) {
        String mfile = cl.getOptionValue("o");
        mappingfile = new File(mfile);

        if (mappingfile.getParentFile() != null) {
            mappingfile.getParentFile().mkdirs();
        }

    }

    if (cl.hasOption('v')) {
        Logger.getLogger(Obfuscater.LOG_NAME).setLevel(Level.CONFIG);
    } else {
        Logger.getLogger(Obfuscater.LOG_NAME).setLevel(Level.OFF);
    }

    Logger.getLogger(Obfuscater.LOG_NAME).addHandler(new ConsoleHandler());

    Obfuscater obfuscater = new Obfuscater(configs, mappingfile, apkFile, str[1]);

    obfuscater.obfuscate();
}

From source file:find.Main.java

public static void main(String[] args) throws Exception {
    Options options = getOptions();/* www. j  a  v  a  2  s  . c o  m*/
    try {

        CommandLineParser parser = new GnuParser();

        CommandLine line = parser.parse(options, args);
        File dir = new File(line.getOptionValue("dir", "."));
        String name = line.getOptionValue("name", "jar");
        Collection files = FindFile.find(dir, name);
        System.out.println("listing files in " + dir + " containing " + name);
        for (Iterator it = files.iterator(); it.hasNext();) {
            System.out.println("\t" + it.next() + "\n");
        }
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("find", options);
    }
}

From source file:ar.com.ergio.uncoma.cei.MiniPas.java

/**
 * @param args/*from   w  w w. j  a v  a2s. co  m*/
 * @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);
    }
}

From source file:net.sourceforge.dita4publishers.tools.ditadxpunpacker.DitaDxpUnpacker.java

/**
 * @param args/*from   w  w  w .  j  a  v  a  2 s .  c  o  m*/
 */
public static void main(String[] args) {

    Options cmdlineOptions = configureOptions();

    CommandLineParser parser = new PosixParser();

    CommandLine cmdline = null;
    try {
        // parse the command line arguments
        cmdline = parser.parse(cmdlineOptions, args);
    } catch (ParseException exp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(DitaDxpUnpacker.class.getSimpleName(), cmdlineOptions);
        System.exit(-1);
    }

    if (!cmdline.hasOption(INPUT_OPTION_ONE_CHAR)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(DitaDxpUnpacker.class.getSimpleName(), cmdlineOptions);
        System.exit(-1);
    }

    DitaDxpUnpacker app = new DitaDxpUnpacker(cmdline);
    try {
        app.run();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

}

From source file:baldrickv.s3streamingtool.S3StreamingTool.java

public static void main(String args[]) throws Exception {
    BasicParser p = new BasicParser();

    Options o = getOptions();/* www.  ja  v  a2s.co  m*/

    CommandLine cl = p.parse(o, args);

    if (cl.hasOption('h')) {
        HelpFormatter hf = new HelpFormatter();
        hf.setWidth(80);

        StringBuilder sb = new StringBuilder();

        sb.append("\n");
        sb.append("Upload:\n");
        sb.append("    -u -r creds -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Download:\n");
        sb.append("    -d -r creds -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Upload encrypted:\n");
        sb.append("    -u -r creds -z -k secret_key -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Download encrypted:\n");
        sb.append("    -d -r creds -z -k secret_key -s 50M -b my_bucket -f hda1.dump -t 10\n");
        sb.append("Cleanup in-progress multipart uploads\n");
        sb.append("    -c -r creds -b my_bucket\n");
        System.out.println(sb.toString());

        hf.printHelp("See above", o);

        return;
    }

    int n = 0;
    if (cl.hasOption('d'))
        n++;
    if (cl.hasOption('u'))
        n++;
    if (cl.hasOption('c'))
        n++;
    if (cl.hasOption('m'))
        n++;

    if (n != 1) {
        System.err.println("Must specify at exactly one of -d, -u, -c or -m");
        System.exit(-1);
    }

    if (cl.hasOption('m')) {
        //InputStream in = new java.io.BufferedInputStream(System.in,1024*1024*2);
        InputStream in = System.in;
        System.out.println(TreeHashGenerator.calculateTreeHash(in));
        return;
    }

    require(cl, 'b');

    if (cl.hasOption('d') || cl.hasOption('u')) {
        require(cl, 'f');
    }
    if (cl.hasOption('z')) {
        require(cl, 'k');
    }

    AWSCredentials creds = null;

    if (cl.hasOption('r')) {
        creds = Utils.loadAWSCredentails(cl.getOptionValue('r'));
    } else {
        if (cl.hasOption('i') && cl.hasOption('e')) {
            creds = new BasicAWSCredentials(cl.getOptionValue('i'), cl.getOptionValue('e'));
        } else {

            System.out.println("Must specify either credential file (-r) or AWS key ID and secret (-i and -e)");
            System.exit(-1);
        }
    }

    S3StreamConfig config = new S3StreamConfig();
    config.setEncryption(false);
    if (cl.hasOption('z')) {
        config.setEncryption(true);
        config.setSecretKey(Utils.loadSecretKey(cl.getOptionValue("k")));
    }

    if (cl.hasOption("encryption-mode")) {
        config.setEncryptionMode(cl.getOptionValue("encryption-mode"));
    }
    config.setS3Bucket(cl.getOptionValue("bucket"));
    if (cl.hasOption("file")) {
        config.setS3File(cl.getOptionValue("file"));
    }

    if (cl.hasOption("threads")) {
        config.setIOThreads(Integer.parseInt(cl.getOptionValue("threads")));
    }

    if (cl.hasOption("blocksize")) {
        String s = cl.getOptionValue("blocksize");
        s = s.toUpperCase();
        int multi = 1;

        int end = 0;
        while ((end < s.length()) && (s.charAt(end) >= '0') && (s.charAt(end) <= '9')) {
            end++;
        }
        int size = Integer.parseInt(s.substring(0, end));

        if (end < s.length()) {
            String m = s.substring(end);
            if (m.equals("K"))
                multi = 1024;
            else if (m.equals("M"))
                multi = 1048576;
            else if (m.equals("G"))
                multi = 1024 * 1024 * 1024;
            else if (m.equals("KB"))
                multi = 1024;
            else if (m.equals("MB"))
                multi = 1048576;
            else if (m.equals("GB"))
                multi = 1024 * 1024 * 1024;
            else {
                System.out.println("Unknown suffix on block size.  Only K,M and G understood.");
                System.exit(-1);
            }

        }
        size *= multi;
        config.setBlockSize(size);
    }

    Logger.getLogger("").setLevel(Level.FINE);

    S3StreamingDownload.log.setLevel(Level.FINE);
    S3StreamingUpload.log.setLevel(Level.FINE);

    config.setS3Client(new AmazonS3Client(creds));
    config.setGlacierClient(new AmazonGlacierClient(creds));
    config.getGlacierClient().setEndpoint("glacier.us-west-2.amazonaws.com");

    if (cl.hasOption("glacier")) {
        config.setGlacier(true);
        config.setStorageInterface(new StorageGlacier(config.getGlacierClient()));
    } else {
        config.setStorageInterface(new StorageS3(config.getS3Client()));
    }
    if (cl.hasOption("bwlimit")) {
        config.setMaxBytesPerSecond(Double.parseDouble(cl.getOptionValue("bwlimit")));

    }

    if (cl.hasOption('c')) {
        if (config.getGlacier()) {
            GlacierCleanupMultipart.cleanup(config);
        } else {
            S3CleanupMultipart.cleanup(config);
        }
        return;
    }
    if (cl.hasOption('d')) {
        config.setOutputStream(System.out);
        S3StreamingDownload.download(config);
        return;
    }
    if (cl.hasOption('u')) {
        config.setInputStream(System.in);
        S3StreamingUpload.upload(config);
        return;
    }

}

From source file:edu.usc.pgroup.floe.client.commands.SwitchAlternate.java

/**
 * Entry point for Scale command.//from   w  w  w  . j a  va 2s.  com
 * @param args command line arguments sent by the floe.py script.
 */
public static void main(final String[] args) {

    Options options = new Options();

    Option appOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Application Name").create("app");

    Option pelletNameOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Pellet Name").create("pellet");

    Option alternateOption = OptionBuilder.withArgName("alternate").hasArg().withType(new String())
            .withDescription("The new alternate to switch to.").create("alternate");

    options.addOption(appOption);
    options.addOption(pelletNameOption);
    options.addOption(alternateOption);

    CommandLineParser parser = new BasicParser();
    CommandLine line;

    try {
        line = parser.parse(options, args);

    } catch (ParseException e) {
        LOGGER.error("Invalid command: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("scale options", options);
        return;
    }

    String app = line.getOptionValue("app");
    String pellet = line.getOptionValue("pellet");
    String alternate = line.getOptionValue("alternate");

    LOGGER.info("Application: {}", app);
    LOGGER.info("Pellet: {}", pellet);
    LOGGER.info("alternate: {}", alternate);

    try {

        FloeClient.getInstance().getClient().switchAlternate(app, pellet, alternate);
    } catch (TException e) {
        LOGGER.error("Error while connecting to the coordinator: {}", e);
    }
}

From source file:com.haulmont.mp2xls.MessagePropertiesProcessor.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption(READ_OPT, "read", false, "read messages from project and save to XLS");
    options.addOption(WRITE_OPT, "write", false, "load messages from XLS and write to project");
    options.addOption(OVERWRITE_OPT, "overwrite", false,
            "overwrite existing messages by changed messages from XLS file");
    options.addOption(PROJECT_DIR_OPT, "projectDir", true, "project root directory");
    options.addOption(XLS_FILE_OPT, "xlsFile", true, "XLS file with translations");
    options.addOption(LOG_FILE_OPT, "logFile", true, "log file");
    options.addOption(LANGUAGES_OPT, "languages", true,
            "list of locales separated by comma, for example: 'de,fr'");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd;/*from w w w.  j  a  va 2s.c o  m*/
    try {
        cmd = parser.parse(options, args);
        if ((!cmd.hasOption(READ_OPT) && !cmd.hasOption(WRITE_OPT)) || !cmd.hasOption(PROJECT_DIR_OPT)
                || !cmd.hasOption(XLS_FILE_OPT) || !cmd.hasOption(LANGUAGES_OPT)) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Messages To/From XLS Convertor", options);
            System.exit(-1);
        }
        if (cmd.hasOption(READ_OPT) && cmd.hasOption(WRITE_OPT)) {
            System.out.println("Please provide either 'read' or 'write' option");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Messages To/From XLS Convertor", options);
            System.exit(-1);
        }

        Set<String> languages = getLanguages(cmd.getOptionValue(LANGUAGES_OPT));

        if (cmd.hasOption(READ_OPT)) {
            LocalizationsBatch localizationsBatch = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT));
            localizationsBatch.setScanLocalizationIds(languages);

            LocalizationBatchExcelWriter.exportToXls(localizationsBatch, cmd.getOptionValue(XLS_FILE_OPT));

        } else if (cmd.hasOption(WRITE_OPT)) {
            LocalizationsBatch sourceLocalization = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT));
            sourceLocalization.setScanLocalizationIds(languages);

            LocalizationsBatch fileLocalization = new LocalizationsBatch(cmd.getOptionValue(XLS_FILE_OPT),
                    cmd.getOptionValue(PROJECT_DIR_OPT));
            fileLocalization.setScanLocalizationIds(languages);

            LocalizationBatchFileWriter fileWriter = new LocalizationBatchFileWriter(sourceLocalization,
                    fileLocalization);
            String logFile = StringUtils.isNotEmpty(cmd.getOptionValue(LOG_FILE_OPT))
                    ? cmd.getOptionValue(LOG_FILE_OPT)
                    : "log.xls";
            fileWriter.process(logFile, cmd.hasOption(OVERWRITE_OPT));
        }
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:com.google.api.codegen.DiscoveryFragmentGeneratorTool.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "show usage");
    options.addOption(Option.builder().longOpt("discovery_doc")
            .desc("The Discovery doc representing the service description.").hasArg().argName("DISCOVERY-DOC")
            .required(true).build());//from   www. j  a v  a  2 s .  co m
    options.addOption(Option.builder().longOpt("overrides").desc("The path to the sample config overrides file")
            .hasArg().argName("OVERRIDES").build());
    options.addOption(Option.builder().longOpt("gapic_yaml").desc("The GAPIC YAML configuration file or files.")
            .hasArg().argName("GAPIC-YAML").required(true).build());
    options.addOption(Option.builder("o").longOpt("output")
            .desc("The directory in which to output the generated fragments.").hasArg()
            .argName("OUTPUT-DIRECTORY").build());
    options.addOption(Option.builder().longOpt("auth_instructions")
            .desc("An @-delimited map of language to auth instructions URL: lang:URL@lang:URL@...").hasArg()
            .argName("AUTH-INSTRUCTIONS").build());

    CommandLine cl = (new DefaultParser()).parse(options, args);
    if (cl.hasOption("help")) {
        HelpFormatter formater = new HelpFormatter();
        formater.printHelp("CodeGeneratorTool", options);
    }

    generate(cl.getOptionValue("discovery_doc"), cl.getOptionValues("gapic_yaml"),
            cl.getOptionValue("overrides", ""), cl.getOptionValue("output", ""),
            cl.getOptionValue("auth_instructions", ""));
}

From source file:net.cliftonsnyder.svgchart.Main.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("c", "stylesheet", true, "CSS stylesheet (default: " + SVGChart.DEFAULT_STYLESHEET + ")");
    options.addOption("h", "height", true, "chart height");
    options.addOption("i", "input-file", true, "input file [default: stdin]");
    options.addOption("o", "output-file", true, "output file [default: stdout]");
    options.addOption("w", "width", true, "chart width");
    options.addOption("?", "help", false, "print a brief help message");

    Option type = new Option("t", "type", true, "chart type " + Arrays.toString(SVGChart.TYPES));
    type.setRequired(true);//from w w  w .  j a v a 2  s  .  co  m
    options.addOption(type);

    CommandLineParser parser = new GnuParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine line = null;
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
        if (line.hasOption("help")) {
            formatter.printHelp(USAGE, options);
            System.exit(0);
        }
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("unable to parse command line: " + exp.getMessage());
        formatter.printHelp(USAGE, options);
        System.exit(1);
    }

    SVGChart chart = null;
    String tmp = line.getOptionValue("type");
    Matcher m = null;
    for (Pattern p : SVGChart.TYPE_PATTERNS) {
        if ((m = p.matcher(tmp)).matches()) {
            switch (m.group().charAt(0)) {
            case 'l':
                // DEBUG
                System.err.println("line");
                break;
            case 'b':
                System.err.println("bar");
                chart = new BarChart();
                break;
            case 'p':
                System.err.println("pie");
                break;
            default:
                System.err.println("unknown or unimplemented chart type: '" + tmp + "'");
                System.exit(1);
            }
        }
    }

    try {
        chart.setWidth(Double.parseDouble(line.getOptionValue("width", "" + SVGChart.DEFAULT_WIDTH)));
    } catch (NumberFormatException e) {
        System.err.println(
                "unable to parse command line: invalid width value '" + line.getOptionValue("width") + "'");
        System.exit(1);
    }

    try {
        chart.setHeight(Double.parseDouble(line.getOptionValue("height", "" + SVGChart.DEFAULT_HEIGHT)));
    } catch (NumberFormatException e) {
        System.err.println(
                "unable to parse command line: invalid height value '" + line.getOptionValue("height") + "'");
        System.exit(1);
    }

    InputStream in = System.in;
    tmp = line.getOptionValue("input-file", "-");
    if ("-".equals(tmp)) {
        in = System.in;
    } else {
        try {
            in = new FileInputStream(tmp);
        } catch (FileNotFoundException e) {
            System.err.println("input file not found: '" + tmp + "'");
            System.exit(1);
        }
    }

    PrintStream out = System.out;
    tmp = line.getOptionValue("output-file", "-");
    if ("-".equals(tmp)) {
        out = System.out;
    } else {
        try {
            out = new PrintStream(new FileOutputStream(tmp));
        } catch (FileNotFoundException e) {
            System.err.println("output file not found: '" + tmp + "'");
            System.exit(1);
        }
    }

    tmp = line.getOptionValue("stylesheet", SVGChart.DEFAULT_STYLESHEET);
    chart.setStyleSheet(tmp);

    try {
        chart.parseInput(in);
    } catch (IOException e) {
        System.err.println("I/O error while reading input");
        System.exit(1);
    } catch (net.cliftonsnyder.svgchart.parse.ParseException e) {
        System.err.println("error parsing input: " + e.getMessage());
    }

    chart.createChart();

    try {
        chart.printChart(out, true);
    } catch (IOException e) {
        System.err.println("error serializing output");
        System.exit(1);
    }
}

From source file:com.genentech.struchk.sdfNormalizer.java

public static void main(String[] args) {
    long start = System.currentTimeMillis();
    int nMessages = 0;
    int nErrors = 0;
    int nStruct = 0;

    // create command line Options object
    Options options = new Options();
    Option opt = new Option("in", true, "input file [.ism,.sdf,...]");
    opt.setRequired(true);/*  www .j  a v  a  2 s .  c o m*/
    options.addOption(opt);

    opt = new Option("out", true, "output file");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("mol", true, "molFile used for output: ORIGINAL(def)|NORMALIZED|TAUTOMERIC");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("shortMessage", false,
            "Limit message to first 80 characters to conform with sdf file specs.");
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        exitWithHelp(options, e.getMessage());
        throw new Error(e); // avoid compiler errors
    }
    args = cmd.getArgs();

    if (args.length != 0) {
        System.err.print("Unknown options: " + args + "\n\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("sdfNormalizer", options);
        System.exit(1);
    }

    String molOpt = cmd.getOptionValue("mol");
    OUTMolFormat outMol = OUTMolFormat.ORIGINAL;
    if (molOpt == null || "original".equalsIgnoreCase(molOpt))
        outMol = OUTMolFormat.ORIGINAL;
    else if ("NORMALIZED".equalsIgnoreCase(molOpt))
        outMol = OUTMolFormat.NORMALIZED;
    else if ("TAUTOMERIC".equalsIgnoreCase(molOpt))
        outMol = OUTMolFormat.TAUTOMERIC;
    else {
        System.err.printf("Unkown option for -mol: %s\n", molOpt);
        System.exit(1);
    }

    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    boolean limitMessage = cmd.hasOption("shortMessage");

    try {
        oemolistream ifs = new oemolistream(inFile);
        oemolostream ofs = new oemolostream(outFile);

        URL cFile = OEStruchk.getResourceURL(OEStruchk.class, "Struchk.xml");

        // create OEStruchk from config file
        OEStruchk strchk = new OEStruchk(cFile, CHECKConfig.ASSIGNStructFlag, false);

        OEGraphMol mol = new OEGraphMol();
        StringBuilder sb = new StringBuilder(2000);
        while (oechem.OEReadMolecule(ifs, mol)) {
            if (!strchk.applyRules(mol, null))
                nErrors++;

            switch (outMol) {
            case NORMALIZED:
                mol.Clear();
                oechem.OEAddMols(mol, strchk.getTransformedMol("parent"));
                break;
            case TAUTOMERIC:
                mol.Clear();
                oechem.OEAddMols(mol, strchk.getTransformedMol(null));
                break;
            case ORIGINAL:
                break;
            }

            oechem.OESetSDData(mol, "CTISMILES", strchk.getTransformedIsoSmiles(null));
            oechem.OESetSDData(mol, "CTSMILES", strchk.getTransformedSmiles(null));
            oechem.OESetSDData(mol, "CISMILES", strchk.getTransformedIsoSmiles("parent"));
            oechem.OESetSDData(mol, "Strutct_Flag", strchk.getStructureFlag().getName());

            List<Message> msgs = strchk.getStructureMessages(null);
            nMessages += msgs.size();
            for (Message msg : msgs)
                sb.append(String.format("\t%s:%s", msg.getLevel(), msg.getText()));
            if (limitMessage)
                sb.setLength(Math.min(sb.length(), 80));

            oechem.OESetSDData(mol, "NORM_MESSAGE", sb.toString());

            oechem.OEWriteMolecule(ofs, mol);

            sb.setLength(0);
            nStruct++;
        }
        strchk.delete();
        mol.delete();
        ifs.close();
        ifs.delete();
        ofs.close();
        ofs.delete();

    } catch (Exception e) {
        throw new Error(e);
    } finally {
        System.err.printf("sdfNormalizer: Checked %d structures %d errors, %d messages in %dsec\n", nStruct,
                nErrors, nMessages, (System.currentTimeMillis() - start) / 1000);
    }
}