1
0

Add Override on Method Fetch for string[] args

This commit is contained in:
glax 2024-06-01 23:40:48 +02:00
parent afc61dbd4e
commit 1edea6bf44

View File

@ -15,13 +15,12 @@ public class ArgumentFetcher
ValidArguments = temp.Concat(new[] { HelpArg }).ToArray();
}
public Dictionary<Argument, string[]> Fetch(string argumentString)
public Dictionary<Argument, string[]> Fetch(string[] args)
{
Dictionary<Argument, string[]> ret = new();
string[] parts = argumentString.Split(' ');
for (int i = 0; i < parts.Length; i++)
for (int i = 0; i < args.Length; i++)
{
string flag = parts[i];
string flag = args[i];
if(flag.Length < 1)
continue;
if (!(flag.StartsWith('-') && flag.Length == 2 || flag.StartsWith("--")))
@ -37,13 +36,13 @@ public class ArgumentFetcher
}
int lastParameterIndex = i + argument.ParameterCount;
if(lastParameterIndex >= parts.Length)
if(lastParameterIndex >= args.Length)
throw new ArgumentException($"Not enough Parameters provided for flag {flag}. (Expected {argument.ParameterCount})");
List<string> parameters = new();
for (; i < lastParameterIndex; i++)
{
string param = parts[i + 1];
string param = args[i + 1];
if(param.StartsWith('-'))
throw new ArgumentException($"Not enough Parameters provided for flag {flag}. (Expected {argument.ParameterCount})");
if(param.StartsWith('"') && param.EndsWith('"'))
@ -55,4 +54,9 @@ public class ArgumentFetcher
}
return ret;
}
public Dictionary<Argument, string[]> Fetch(string argumentString)
{
return Fetch(argumentString.Split(' '));
}
}