using System; using System.Collections.Generic; namespace Unity.PlasticSCM.Editor.Hub { internal class CommandLineArguments { internal static Dictionary Build(string[] args) { Dictionary result = new Dictionary( StringComparer.OrdinalIgnoreCase); if (args == null) return result; List 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 TrimArgs(string[] args) { List trimmedArguments = new List(); foreach (string argument in args) trimmedArguments.Add(argument.Trim()); return trimmedArguments; } static bool IsKeyValueArgumentAtIndex( List trimmedArguments, int index) { if (index + 1 > trimmedArguments.Count -1) return false; return !trimmedArguments[index + 1].StartsWith("-"); } } }