-
Notifications
You must be signed in to change notification settings - Fork 0
/
Option.cs
53 lines (47 loc) · 1.11 KB
/
Option.cs
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
using System;
using System.Collections.Generic;
namespace App {
class Option {
// Data
public IList<string> Command = new List<string>();
public string Username;
public string Password;
public string Input;
public string To;
public bool O;
// Methods
public Option(string[] args) {
for (var i = 0; i < args.Length;) {
var a = args[i++];
if (a.StartsWith("--")) Flag(args, ref i, a.Substring(2));
else if (a.StartsWith("-")) { foreach (var v in a.Substring(1)) Flag(args, ref i, v.ToString()); }
else Command.Add(a);
}
}
private void Flag(string[] a, ref int i, string v) {
switch (v.ToLower()) {
case "u":
case "username":
Username = i < a.Length ? a[i++] : "";
break;
case "p":
case "password":
Password = i < a.Length ? a[i++] : "";
break;
case "i":
case "input":
Input = i < a.Length ? a[i++] : "";
break;
case "t":
case "to":
To = i < a.Length ? a[i++] : "";
break;
case "0":
O = true;
break;
default:
throw new ArgumentException(string.Format("Bad flag: \"{0}\"", v));
}
}
}
}