<commit_before>#include "synctool.h"

/* Command line options */
bool gUseColors = true;
bool gFastMode = false;
bool gVerbose = false;
string gSyncMode = "";

template <typename T>
bool handle_arg(string arg, string name, T& var, T yes)
{
	if (arg == string(string("--") + name) || arg == string(string("-") + name))
	{
		var = yes; return true;
	}
	return false;
}

template <typename T>
bool handle_arg(string arg, string name, T& var, T yes, T no)
{
	if (arg == string(string("--") + name) || arg == string(string("-") + name) || arg == string(string("-") + name.substr(0,1)))
	{
		var = yes; return true;
	}
	else if (arg == string(string("--no-") + name) || arg == string(string("-no-") + name))
	{
		var = no; return true;
	}
	return false;
}

int main(int argc, char** argv)
{
	bool interactive = false;
	string src = "", dst = "";

	/* Handle command-line arguments */
	for (int i = 1; i < argc; i++)
	{
		bool isArg = false;

		isArg |= handle_arg(argv[i], "color",       gUseColors,  true, false);
		isArg |= handle_arg(argv[i], "fast",        gFastMode,   true, false);
		isArg |= handle_arg(argv[i], "verbose",     gVerbose,    true, false);
		isArg |= handle_arg(argv[i], "interactive", interactive, true, false);

		isArg |= handle_arg<string>(argv[i], "append", gSyncMode, "append");
		isArg |= handle_arg<string>(argv[i], "mirror", gSyncMode, "mirror");

		if (!isArg && ((!isDirectory(argv[i])) || ((src != "") && (dst != ""))))
			logMessage("Warning: Unknown option: " + string(argv[i]));
		else if (!isArg && src == "")
			src = argv[i];
		else if (!isArg && dst == "")
			dst = argv[i];
	}

	if (interactive)
	{
		logMessage("Entering interactive mode...");

		if (src == "")
		{
			logMessage("Enter source directory: ");
			cin >> src;
		}

		if (dst == "")
		{
			logMessage("Enter destination directory: ");
			cin >> dst;
		}

		while (gSyncMode != "mirror" && gSyncMode != "append")
		{
			logMessage("Choose sync mode [mirror/append]: ");
			cin >> gSyncMode;
		}
	}
	else if (gSyncMode == "")
	{
		gSyncMode = "mirror";
	}

	if (src == "" || dst == "")
	{
		logMessage("Error: Source and destination not specified");
		printHelp();
	}

	if (src == dst)
		die(EXIT_FAILURE, "Error: Source and destination can't be the same");

	assertCanOpenDirectory(src);
	assertCanOpenDirectory(dst);
	doSync(src, dst);

	die(EXIT_SUCCESS, "Done!");
}
<commit_msg>Fixed possibly wrong handling of single letter options<commit_after>#include "synctool.h"

/* Command line options */
bool gUseColors = true;
bool gFastMode = false;
bool gVerbose = false;
string gSyncMode = "";

template <typename T>
bool handle_arg(string arg, string name, T& var, T yes)
{
	if (arg == string(string("--") + name) || arg == string(string("-") + name) || arg == string(string("-") + name.substr(0,1)))
	{
		var = yes; return true;
	}
	return false;
}

template <typename T>
bool handle_arg(string arg, string name, T& var, T yes, T no)
{
	if (arg == string(string("--") + name) || arg == string(string("-") + name) || arg == string(string("-") + name.substr(0,1)))
	{
		var = yes; return true;
	}
	else if (arg == string(string("--no-") + name) || arg == string(string("-no-") + name))
	{
		var = no; return true;
	}
	return false;
}

int main(int argc, char** argv)
{
	bool interactive = false;
	string src = "", dst = "";

	/* Handle command-line arguments */
	for (int i = 1; i < argc; i++)
	{
		bool isArg = false;

		isArg |= handle_arg(argv[i], "color",       gUseColors,  true, false);
		isArg |= handle_arg(argv[i], "fast",        gFastMode,   true, false);
		isArg |= handle_arg(argv[i], "verbose",     gVerbose,    true, false);
		isArg |= handle_arg(argv[i], "interactive", interactive, true, false);

		isArg |= handle_arg<string>(argv[i], "append", gSyncMode, "append");
		isArg |= handle_arg<string>(argv[i], "mirror", gSyncMode, "mirror");

		if (!isArg && ((!isDirectory(argv[i])) || ((src != "") && (dst != ""))))
			logMessage("Warning: Unknown option: " + string(argv[i]));
		else if (!isArg && src == "")
			src = argv[i];
		else if (!isArg && dst == "")
			dst = argv[i];
	}

	if (interactive)
	{
		logMessage("Entering interactive mode...");

		if (src == "")
		{
			logMessage("Enter source directory: ");
			cin >> src;
		}

		if (dst == "")
		{
			logMessage("Enter destination directory: ");
			cin >> dst;
		}

		while (gSyncMode != "mirror" && gSyncMode != "append")
		{
			logMessage("Choose sync mode [mirror/append]: ");
			cin >> gSyncMode;
		}
	}
	else if (gSyncMode == "")
	{
		gSyncMode = "mirror";
	}

	if (src == "" || dst == "")
	{
		logMessage("Error: Source and destination not specified");
		printHelp();
	}

	if (src == dst)
		die(EXIT_FAILURE, "Error: Source and destination can't be the same");

	assertCanOpenDirectory(src);
	assertCanOpenDirectory(dst);
	doSync(src, dst);

	die(EXIT_SUCCESS, "Done!");
}

{'fraction_non_alphanumeric': 0.19966996699669967, 'fraction_numerical': 0.0016501650165016502, 'mean_word_length': 3.6986434108527133, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '3693581', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1723, 'n_words': 460}