<commit_before>package org.opencb.cellbase.app.cli;

import com.beust.jcommander.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by imedina on 03/02/15.
 */
public class CliOptionsParser {

    private final JCommander jcommander;

    private final GeneralOptions generalOptions;
    private final CommonCommandOptions commonCommandOptions;

    private DownloadCommandOptions downloadCommandOptions;
    private BuildCommandOptions buildCommandOptions;
    private LoadCommandOptions loadCommandOptions;
    private QueryCommandOptions queryCommandOptions;


    public CliOptionsParser() {
        generalOptions = new GeneralOptions();

        jcommander = new JCommander(generalOptions);
        jcommander.setProgramName("cellbase.sh");

        commonCommandOptions = new CommonCommandOptions();

        downloadCommandOptions = new DownloadCommandOptions();
        buildCommandOptions = new BuildCommandOptions();
        loadCommandOptions = new LoadCommandOptions();
        queryCommandOptions = new QueryCommandOptions();

        jcommander.addCommand("download", downloadCommandOptions);
        jcommander.addCommand("build", buildCommandOptions);
        jcommander.addCommand("load", loadCommandOptions);
        jcommander.addCommand("query", queryCommandOptions);

    }

    public void parse(String[] args) throws ParameterException {
        jcommander.parse(args);
    }

    public String getCommand() {
        return (jcommander.getParsedCommand() != null) ? jcommander.getParsedCommand(): "";
    }

    public void printUsage(){
        if(getCommand().isEmpty()) {
            jcommander.usage();
        } else {
            jcommander.usage(getCommand());
        }
    }

    public class GeneralOptions {


        @Parameter(names = {"-h", "--help"}, help = true)
        public boolean help;
        @Parameter(names = {"--version"})
        public boolean version;

    }

    public class CommonCommandOptions {

        @Parameter(names = {"-h", "--help"}, help = true)
        public boolean help;
        @Parameter(names = {"-L", "--log-level"}, description = "This parameter set the level of the logging", required = false, arity = 1)
        public String logLevel = "info";

        @Parameter(names = {"-v", "--verbose"}, description = "This parameter set the level of the logging", required = false, arity = 1)
        public boolean verbose;

        @Parameter(names = {"-C", "--conf"}, description = "This parameter set the level of the logging", required = false, arity = 1)
        public String conf;

    }


    @Parameters(commandNames = {"download"}, commandDescription = "Description")
    public class DownloadCommandOptions {


        @ParametersDelegate
        public CommonCommandOptions commonOptions = commonCommandOptions;

        @Parameter(names = {"-s", "--species"}, description = "", required = false, variableArity = true)
        public List<String> species = Arrays.asList("Homo sapiens");


        @Parameter(names = {"-a", "--assembly"}, description = "", required = false, arity = 1)
        public String assembly;

        @Parameter(names = {"-o", "--output-dir"}, description = "", required = false, arity = 1)
        public String outputDir = "/tmp";

        @Parameter(names = {"--sequence"}, description = "", required = false)
        public boolean sequence = false;

        @Parameter(names = {"--gene"}, description = "", required = false)
        public boolean gene = false;

        @Parameter(names = {"--variation"}, description = "", required = false)
        public boolean variation = false;

        @Parameter(names = {"--regulation"}, description = "", required = false)
        public boolean regulation = false;

        @Parameter(names = {"--protein"}, description = "", required = false)
        public boolean protein = false;

    }


    @Parameters(commandNames = {"build"}, commandDescription = "Description")
    public class BuildCommandOptions {


        @ParametersDelegate
        public CommonCommandOptions commonOptions = commonCommandOptions;

        @Parameter(names = {"-b", "--build"}, description = "", required = true, arity = 1)
        public String build;

        @Parameter(names = {"-i", "--input"}, description = "", required = true, arity = 1)
        public String input;

        @Parameter(names = {"-o", "--output"}, description = "", required = false, arity = 1)
        public String output = "/tmp";

        @Parameter(names = {"--reference-genome-file"}, description = "", required = false)
        public String referenceGenomeFile;

        @Parameter(names = {"--species"}, description = "", required = false)
        public String species;

        @Parameter(names = {"--assembly"}, description = "", required = false)
        public String assembly;

    }


    @Parameters(commandNames = {"load"}, commandDescription = "Description")
    public class LoadCommandOptions {


        @ParametersDelegate
        public CommonCommandOptions commonOptions = commonCommandOptions;

        @Parameter(names = {"-d", "--data"}, description = "", required = true, arity = 1)
        public String load;

        @Parameter(names = {"-l", "--loader"}, description = "", required = true, arity = 1)
        public String loader = "org.opencb.cellbase.mongodb.loader.MongoDBCellBaseLoader";

        @DynamicParameter(names = "-D", description = "Dynamic parameters go here", hidden = true)
        public Map<String, String> loaderParams = new HashMap<>();

        @Parameter(names = {"-i", "--input-file"}, description = "", required = false, arity = 1)
        public String inputFile;

        @Parameter(names = {"--input-dir"}, description = "", required = false, arity = 1)
        public String inputDir;

        @Parameter(names = {"--host"}, description = "", required = false, arity = 1)
        public String host;

        @Parameter(names = {"--port"}, description = "", required = false)
        public int port;
<commit_msg>CliOptionsParser: 'loader' parameter made not mandatory beacause it has a default value<commit_after>package org.opencb.cellbase.app.cli;

import com.beust.jcommander.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by imedina on 03/02/15.
 */
public class CliOptionsParser {

    private final JCommander jcommander;

    private final GeneralOptions generalOptions;
    private final CommonCommandOptions commonCommandOptions;

    private DownloadCommandOptions downloadCommandOptions;
    private BuildCommandOptions buildCommandOptions;
    private LoadCommandOptions loadCommandOptions;
    private QueryCommandOptions queryCommandOptions;


    public CliOptionsParser() {
        generalOptions = new GeneralOptions();

        jcommander = new JCommander(generalOptions);
        jcommander.setProgramName("cellbase.sh");

        commonCommandOptions = new CommonCommandOptions();

        downloadCommandOptions = new DownloadCommandOptions();
        buildCommandOptions = new BuildCommandOptions();
        loadCommandOptions = new LoadCommandOptions();
        queryCommandOptions = new QueryCommandOptions();

        jcommander.addCommand("download", downloadCommandOptions);
        jcommander.addCommand("build", buildCommandOptions);
        jcommander.addCommand("load", loadCommandOptions);
        jcommander.addCommand("query", queryCommandOptions);

    }

    public void parse(String[] args) throws ParameterException {
        jcommander.parse(args);
    }

    public String getCommand() {
        return (jcommander.getParsedCommand() != null) ? jcommander.getParsedCommand(): "";
    }

    public void printUsage(){
        if(getCommand().isEmpty()) {
            jcommander.usage();
        } else {
            jcommander.usage(getCommand());
        }
    }

    public class GeneralOptions {


        @Parameter(names = {"-h", "--help"}, help = true)
        public boolean help;
        @Parameter(names = {"--version"})
        public boolean version;

    }

    public class CommonCommandOptions {

        @Parameter(names = {"-h", "--help"}, help = true)
        public boolean help;
        @Parameter(names = {"-L", "--log-level"}, description = "This parameter set the level of the logging", required = false, arity = 1)
        public String logLevel = "info";

        @Parameter(names = {"-v", "--verbose"}, description = "This parameter set the level of the logging", required = false, arity = 1)
        public boolean verbose;

        @Parameter(names = {"-C", "--conf"}, description = "This parameter set the level of the logging", required = false, arity = 1)
        public String conf;

    }


    @Parameters(commandNames = {"download"}, commandDescription = "Description")
    public class DownloadCommandOptions {


        @ParametersDelegate
        public CommonCommandOptions commonOptions = commonCommandOptions;

        @Parameter(names = {"-s", "--species"}, description = "", required = false, variableArity = true)
        public List<String> species = Arrays.asList("Homo sapiens");


        @Parameter(names = {"-a", "--assembly"}, description = "", required = false, arity = 1)
        public String assembly;

        @Parameter(names = {"-o", "--output-dir"}, description = "", required = false, arity = 1)
        public String outputDir = "/tmp";

        @Parameter(names = {"--sequence"}, description = "", required = false)
        public boolean sequence = false;

        @Parameter(names = {"--gene"}, description = "", required = false)
        public boolean gene = false;

        @Parameter(names = {"--variation"}, description = "", required = false)
        public boolean variation = false;

        @Parameter(names = {"--regulation"}, description = "", required = false)
        public boolean regulation = false;

        @Parameter(names = {"--protein"}, description = "", required = false)
        public boolean protein = false;

    }


    @Parameters(commandNames = {"build"}, commandDescription = "Description")
    public class BuildCommandOptions {


        @ParametersDelegate
        public CommonCommandOptions commonOptions = commonCommandOptions;

        @Parameter(names = {"-b", "--build"}, description = "", required = true, arity = 1)
        public String build;

        @Parameter(names = {"-i", "--input"}, description = "", required = true, arity = 1)
        public String input;

        @Parameter(names = {"-o", "--output"}, description = "", required = false, arity = 1)
        public String output = "/tmp";

        @Parameter(names = {"--reference-genome-file"}, description = "", required = false)
        public String referenceGenomeFile;

        @Parameter(names = {"--species"}, description = "", required = false)
        public String species;

        @Parameter(names = {"--assembly"}, description = "", required = false)
        public String assembly;

    }


    @Parameters(commandNames = {"load"}, commandDescription = "Description")
    public class LoadCommandOptions {


        @ParametersDelegate
        public CommonCommandOptions commonOptions = commonCommandOptions;

        @Parameter(names = {"-d", "--data"}, description = "", required = true, arity = 1)
        public String load;

        @Parameter(names = {"-l", "--loader"}, description = "", required = false, arity = 1)
        public String loader = "org.opencb.cellbase.mongodb.loader.MongoDBCellBaseLoader";

        @DynamicParameter(names = "-D", description = "Dynamic parameters go here", hidden = true)
        public Map<String, String> loaderParams = new HashMap<>();

        @Parameter(names = {"-i", "--input-file"}, description = "", required = false, arity = 1)
        public String inputFile;

        @Parameter(names = {"--input-dir"}, description = "", required = false, arity = 1)
        public String inputDir;

        @Parameter(names = {"--host"}, description = "", required = false, arity = 1)
        public String host;

        @Parameter(names = {"--port"}, description = "", required = false)
        public int port;

{'fraction_non_alphanumeric': 0.1296858338118284, 'fraction_numerical': 0.0031170535641046673, 'mean_word_length': 2.986919555264879, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6101268', 'n_tokens_mistral': 3116, 'n_tokens_neox': 2948, 'n_words': 879}