File size: 1,599 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | using System;
using System.Collections.Generic;
namespace Unity.PlasticSCM.Editor.ProjectDownloader
{
internal class CommandLineArguments
{
internal static Dictionary<string, string> Build(string[] args)
{
Dictionary<string, string> result = new Dictionary<string, string>(
StringComparer.OrdinalIgnoreCase);
if (args == null)
return result;
List<string> trimmedArguments = TrimArgs(args);
int index = 1;
while (true)
{
if (index > trimmedArguments.Count - 1)
break;
if (IsKeyValueArgumentAtIndex(trimmedArguments, index))
{
result[trimmedArguments[index]] = trimmedArguments[index + 1];
index += 2;
continue;
}
result[trimmedArguments[index]] = null;
index += 1;
}
return result;
}
static List<string> TrimArgs(string[] args)
{
List<string> trimmedArguments = new List<string>();
foreach (string argument in args)
trimmedArguments.Add(argument.Trim());
return trimmedArguments;
}
static bool IsKeyValueArgumentAtIndex(
List<string> trimmedArguments,
int index)
{
if (index + 1 > trimmedArguments.Count -1)
return false;
return !trimmedArguments[index + 1].StartsWith("-");
}
}
}
|