Add Override on Method Fetch for string[] args
This commit is contained in:
parent
afc61dbd4e
commit
1edea6bf44
@ -15,13 +15,12 @@ public class ArgumentFetcher
|
|||||||
ValidArguments = temp.Concat(new[] { HelpArg }).ToArray();
|
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();
|
Dictionary<Argument, string[]> ret = new();
|
||||||
string[] parts = argumentString.Split(' ');
|
for (int i = 0; i < args.Length; i++)
|
||||||
for (int i = 0; i < parts.Length; i++)
|
|
||||||
{
|
{
|
||||||
string flag = parts[i];
|
string flag = args[i];
|
||||||
if(flag.Length < 1)
|
if(flag.Length < 1)
|
||||||
continue;
|
continue;
|
||||||
if (!(flag.StartsWith('-') && flag.Length == 2 || flag.StartsWith("--")))
|
if (!(flag.StartsWith('-') && flag.Length == 2 || flag.StartsWith("--")))
|
||||||
@ -37,13 +36,13 @@ public class ArgumentFetcher
|
|||||||
}
|
}
|
||||||
|
|
||||||
int lastParameterIndex = i + argument.ParameterCount;
|
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})");
|
throw new ArgumentException($"Not enough Parameters provided for flag {flag}. (Expected {argument.ParameterCount})");
|
||||||
|
|
||||||
List<string> parameters = new();
|
List<string> parameters = new();
|
||||||
for (; i < lastParameterIndex; i++)
|
for (; i < lastParameterIndex; i++)
|
||||||
{
|
{
|
||||||
string param = parts[i + 1];
|
string param = args[i + 1];
|
||||||
if(param.StartsWith('-'))
|
if(param.StartsWith('-'))
|
||||||
throw new ArgumentException($"Not enough Parameters provided for flag {flag}. (Expected {argument.ParameterCount})");
|
throw new ArgumentException($"Not enough Parameters provided for flag {flag}. (Expected {argument.ParameterCount})");
|
||||||
if(param.StartsWith('"') && param.EndsWith('"'))
|
if(param.StartsWith('"') && param.EndsWith('"'))
|
||||||
@ -55,4 +54,9 @@ public class ArgumentFetcher
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Dictionary<Argument, string[]> Fetch(string argumentString)
|
||||||
|
{
|
||||||
|
return Fetch(argumentString.Split(' '));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user