-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathOptions.cs
101 lines (98 loc) · 2.5 KB
/
Options.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Reflection;
namespace SharpConflux
{
internal class Options
{
internal bool help = false;
internal string url = null;
internal string ua = "Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko";
internal bool cloud = false;
internal bool onprem = false;
internal string user = null;
internal string pwd = null;
internal bool basic = false;
internal bool form = false;
internal string apitoken = null;
internal string pat = null;
internal string cookies = null;
internal string query = null;
internal string cql = null;
internal string limit = "10";
internal string view = null;
internal bool pretty = false;
internal string download = null;
internal bool b64 = false;
internal string path = null;
internal bool spaces = false;
internal string upload = null;
internal bool ParseArguments(string[] args)
{
FieldInfo[] fields = typeof(Options).GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
var parsedOptions = new HashSet<string>();
foreach (string arg in args)
{
if (arg.StartsWith("/"))
{
var unknown = true;
string[] argParts = arg.Split(new[] { ':' }, 2);
string optionName = argParts[0].TrimStart('/').ToLower();
foreach (FieldInfo field in fields)
{
if (optionName == field.Name.ToLower())
{
if (parsedOptions.Add(optionName))
{
if (argParts.Length == 1)
{
try
{
field.SetValue(this, true);
}
catch (ArgumentException)
{
Console.WriteLine($"[-] No value specified for argument '{optionName}'");
return false;
}
}
else
{
string optionValue = argParts[1];
try
{
field.SetValue(this, optionValue);
}
catch (ArgumentException)
{
try
{
field.SetValue(this, int.Parse(optionValue));
}
catch (FormatException)
{
Console.WriteLine($"[-] Invalid value specified for argument '{optionName}'");
return false;
}
}
}
unknown = false;
}
else
{
Console.WriteLine($"[-] '{optionName}' argument can only be specified once");
return false;
}
}
}
if (unknown)
{
Console.WriteLine($"[-] Unknown argument '{optionName}'");
return false;
}
}
}
return true;
}
}
}