<commit_before>/*******************************************************************************
 * Copyright © 2018 EMBL - European Bioinformatics Institute
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the
 * License.
 ******************************************************************************/

package org.mousephenotype.cda.ri.core;

import joptsimple.OptionParser;
import joptsimple.OptionSet;
import org.apache.commons.lang3.StringUtils;
import org.mousephenotype.cda.ri.core.services.CoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;

import javax.inject.Inject;
import java.io.IOException;
import java.util.Arrays;


@ComponentScan
public class ApplicationSend implements CommandLineRunner {

    private final Logger       logger        = LoggerFactory.getLogger(this.getClass());
    private       CoreService  coreService;

    private final String[] OPT_SUPPRESS = {"s", "suppress"};
    private final String[] OPT_HELP = {"h", "help"};

    private boolean help    = false;
    private boolean suppress = false;

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(ApplicationSend.class);
        app.setBannerMode(Banner.Mode.OFF);
        app.setLogStartupInfo(false);
        app.setWebEnvironment(false);
        app.run(args);
    }

    @Inject
    public ApplicationSend(CoreService coreService) {
        this.coreService = coreService;
    }


    public static final String USAGE = "Usage: [--help/-h] | [--suppress/-s]";

    /**
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {

        initialise(args);

        if (suppress) {

            logger.info("Generate and send gene status to all contacts.");
            coreService.generateAndSendAll();

        } else {

            logger.info("Generate and send gene status to contacts with gene status CHANGED since last e-mail.");
            coreService.generateAndSendDecorated();

        }
    }


    // PRIVATE / PROTECTED METHODS


    private void initialise(String[] args) throws IOException {

        OptionParser parser  = new OptionParser();
        OptionSet    options = parseOptions(parser, args);

        logger.info("Program Arguments: " + StringUtils.join(args, ", "));

        if (help) {
            parser.printHelpOn(System.out);
            System.exit(0);
        }
    }

    protected OptionSet parseOptions(OptionParser parser, String[] args) {

        OptionSet options = null;

        parser.acceptsAll(Arrays.asList(OPT_HELP), "Display help/usage information\t" + USAGE)
                .forHelp();

        parser.acceptsAll(Arrays.asList(OPT_SUPPRESS), "Suppress the decoration indicating whether or not a gene's status has changed since the last e-mail sent")
                .forHelp();

        try {

            options = parser.parse(args);

        } catch (Exception e) {

            System.out.println(e.getLocalizedMessage());
            System.out.println(usage());
            System.exit(1);
        }

        help = (options.has("help"));
        suppress = (options.has("suppress"));
<commit_msg>Tell OptionParser to allow unrecognized options.<commit_after>/*******************************************************************************
 * Copyright © 2018 EMBL - European Bioinformatics Institute
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the
 * License.
 ******************************************************************************/

package org.mousephenotype.cda.ri.core;

import joptsimple.OptionParser;
import joptsimple.OptionSet;
import org.apache.commons.lang3.StringUtils;
import org.mousephenotype.cda.ri.core.services.CoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;

import javax.inject.Inject;
import java.io.IOException;
import java.util.Arrays;


@ComponentScan
public class ApplicationSend implements CommandLineRunner {

    private final Logger       logger        = LoggerFactory.getLogger(this.getClass());
    private       CoreService  coreService;

    private final String[] OPT_SUPPRESS = {"s", "suppress"};
    private final String[] OPT_HELP = {"h", "help"};

    private boolean help    = false;
    private boolean suppress = false;

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(ApplicationSend.class);
        app.setBannerMode(Banner.Mode.OFF);
        app.setLogStartupInfo(false);
        app.setWebEnvironment(false);
        app.run(args);
    }

    @Inject
    public ApplicationSend(CoreService coreService) {
        this.coreService = coreService;
    }


    public static final String USAGE = "Usage: [--help/-h] | [--suppress/-s]";

    /**
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {

        initialise(args);

        if (suppress) {

            logger.info("Generate and send gene status to all contacts.");
            coreService.generateAndSendAll();

        } else {

            logger.info("Generate and send gene status to contacts with gene status CHANGED since last e-mail.");
            coreService.generateAndSendDecorated();

        }
    }


    // PRIVATE / PROTECTED METHODS


    private void initialise(String[] args) throws IOException {

        OptionParser parser  = new OptionParser();
        OptionSet    options = parseOptions(parser, args);

        logger.info("Program Arguments: " + StringUtils.join(args, ", "));

        if (help) {
            parser.printHelpOn(System.out);
            System.exit(0);
        }
    }

    protected OptionSet parseOptions(OptionParser parser, String[] args) {

        OptionSet options = null;

        parser.allowsUnrecognizedOptions();

        parser.acceptsAll(Arrays.asList(OPT_HELP), "Display help/usage information\t" + USAGE)
                .forHelp();

        parser.acceptsAll(Arrays.asList(OPT_SUPPRESS), "Suppress the decoration indicating whether or not a gene's status has changed since the last e-mail sent")
                .forHelp();

        try {

            options = parser.parse(args);

        } catch (Exception e) {

            System.out.println(e.getLocalizedMessage());
            System.out.println(usage());
            System.exit(1);
        }

        help = (options.has("help"));
        suppress = (options.has("suppress"));

{'fraction_non_alphanumeric': 0.13693210821847882, 'fraction_numerical': 0.003318019397651863, 'mean_word_length': 3.0148565573770494, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3755846', 'n_tokens_mistral': 2093, 'n_tokens_neox': 1984, 'n_words': 580}