<commit_before>package de.baumato.loc.configuration;

import static de.baumato.loc.messages.Messages.DIR_DOES_NOT_EXIST;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.ParserProperties;
import org.kohsuke.args4j.spi.StringArrayOptionHandler;

/**
 * Holds the command line arguments
 *
 * @author baumato
 *
 */
public class Configuration {

	@Option(
			name = "-d",
			required = true,
			usage = "ARGUMENT_DIRECTORY_USAGE",
			metaVar = "PATH",
			hidden = false,
			aliases = { "--directory" })
	private Path directory;

	@Option(
			name = "-e",
			required = false,
			usage = "ARGUMENT_EXCLUDE_DIRS_USAGE",
			metaVar = "FOLDER_NAMES",
			hidden = false,
			aliases = { "--excludeDirs" },
			handler = StringArrayOptionHandler.class)
	private List<String> excludeDirs = new ArrayList<>();

	@Option(
			name = "-v",
			required = false,
			usage = "ARGUMENT_VERBOSE_USAGE",
			metaVar = "BOOLEAN",
			hidden = false,
			aliases = { "--verbose" })
	private boolean verbose;

	public static Configuration ofCmdLine(String... args) throws InvalidCommandLineArgumentsException {
		Configuration conf = new Configuration();
		CmdLineParser parser = new CmdLineParser(conf, ParserProperties.defaults().withUsageWidth(80));
		try {
			parser.parseArgument(args);
			if (!Files.isDirectory(conf.directory)) {<commit_msg>use toFile().exists() because according to sonar it is faster<commit_after>package de.baumato.loc.configuration;

import static de.baumato.loc.messages.Messages.DIR_DOES_NOT_EXIST;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.ParserProperties;
import org.kohsuke.args4j.spi.StringArrayOptionHandler;

/**
 * Holds the command line arguments
 *
 * @author baumato
 *
 */
public class Configuration {

	@Option(
			name = "-d",
			required = true,
			usage = "ARGUMENT_DIRECTORY_USAGE",
			metaVar = "PATH",
			hidden = false,
			aliases = { "--directory" })
	private Path directory;

	@Option(
			name = "-e",
			required = false,
			usage = "ARGUMENT_EXCLUDE_DIRS_USAGE",
			metaVar = "FOLDER_NAMES",
			hidden = false,
			aliases = { "--excludeDirs" },
			handler = StringArrayOptionHandler.class)
	private List<String> excludeDirs = new ArrayList<>();

	@Option(
			name = "-v",
			required = false,
			usage = "ARGUMENT_VERBOSE_USAGE",
			metaVar = "BOOLEAN",
			hidden = false,
			aliases = { "--verbose" })
	private boolean verbose;

	public static Configuration ofCmdLine(String... args) throws InvalidCommandLineArgumentsException {
		Configuration conf = new Configuration();
		CmdLineParser parser = new CmdLineParser(conf, ParserProperties.defaults().withUsageWidth(80));
		try {
			parser.parseArgument(args);
			if (!conf.directory.toFile().exists()) {
{'fraction_non_alphanumeric': 0.12280140709945635, 'fraction_numerical': 0.004477134633834346, 'mean_word_length': 4.3561643835616435, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4739057', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1011, 'n_words': 220}