feat: rework of argument read. Added possibility to analyze only one user.

This commit is contained in:
Savely Savianok
2025-02-11 20:51:33 +03:00
parent df34347920
commit 1e40bbd735
4 changed files with 58 additions and 22 deletions

38
ArgumentReader.cs Normal file
View File

@@ -0,0 +1,38 @@
namespace TelegramMessageCounter;
public static class ArgumentReader
{
public static DataRequest ReadArguments(string[] args)
{
string? login = null;
string? username = null;
if (args.Length > 0 && args.Any(x => x == "--help"))
{
Console.WriteLine("Usage: TelegramMessageCounter --login (phone number) --user (username) <path>" +
"\n login - Phone number of telegram. If argument is empty, waiting for Keyboard interrupt" +
"\nuser - Username of telegram for individual stats. If argument is empty, analyzing all user history" +
"\n path - Path to save results file. If argument is empty, path will be \"results.txt\"\n");
Environment.Exit(0);
}
if (args.Any(x => x == "--user"))
{
var userNameArgIndex = args.ToList().IndexOf("--user");
username = args[userNameArgIndex+1];
}
if (args.Any(x => x == "--login" || x == "-L"))
{
var userNameArgIndex = args.ToList().IndexOf("--login");
if (userNameArgIndex == -1)
{
userNameArgIndex = args.ToList().IndexOf("-L");
}
login = args[userNameArgIndex+1];
}
string? path = args.Length > 1 ? args.Last() : null;
return new(login, username, (path ?? default)!);
}
}