forked from idkiller/UsageRateTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptionParser.cs
executable file
·86 lines (77 loc) · 2.46 KB
/
OptionParser.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
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace UsageRateTool
{
class OptionParser
{
IEnumerable<string> _sources;
IEnumerable<string> _targets;
bool _isbase;
const string SourceOption = "-s";
const string TargetOption = "-t";
const string BaseOption = "-b";
const string HelpOption = "-h";
string option = null;
public OptionParser(string[] args)
{
List<string> sources = new List<string>();
List<string> targets = new List<string>();
List<string> others = new List<string>();
bool isbase = false;
foreach (var arg in args)
{
if (arg == SourceOption)
{
option = SourceOption;
}
else if (arg == TargetOption)
{
option = TargetOption;
}
else if (arg == BaseOption)
{
isbase = true;
}
else if (arg == HelpOption)
{
return;
}
else
{
if (option == SourceOption)
{
sources.Add(arg);
}
else if (option == TargetOption)
{
targets.Add(arg);
}
else
{
others.Add(arg);
}
}
}
if (sources.Count == 0)
{
sources.AddRange(others);
}
_sources = sources;
_targets = targets;
_isbase = isbase;
}
public void Help()
{
var name = this.GetType().Assembly.GetName().Name;
Console.WriteLine($"Usage: {name} <source dll>");
Console.WriteLine($"Usage: {name} [{SourceOption}] <source dlls> [{TargetOption}] <target dlls>");
Console.WriteLine($"Usage: {name} [{BaseOption}] [{SourceOption}] <source dlls> [{TargetOption}] <target dlls>");
Console.WriteLine($"Usage: {name} [{HelpOption}]");
}
public IEnumerable<string> Sources => _sources;
public IEnumerable<string> Targets => _targets;
public bool IsBase => _isbase;
}
}