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