forked from editorconfig/editorconfig-core-net
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArgumentsParser.cs
More file actions
58 lines (52 loc) · 1.62 KB
/
ArgumentsParser.cs
File metadata and controls
58 lines (52 loc) · 1.62 KB
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
using System;
using System.Linq;
namespace EditorConfig.App
{
internal class ArgumentsParser
{
public string[] FileNames { get; private set; }
public string ConfigFileName { get; private set; }
public Version DevelopVersion { get; private set; }
public bool PrintHelp { get; private set; }
public bool PrintVersion { get; private set; }
public ArgumentsParser(string[] args)
{
if (args.Length == 0)
throw new ApplicationArgumentException("Must specify at least one FILEPATH");
while (args.Length > 0 && args[0].StartsWith("-"))
{
switch (args[0])
{
case "-h":
case "--help":
PrintHelp = true;
return;
case "-v":
case "--version":
PrintVersion = true;
return;
case "-f":
if (args.Length == 1 || args[1].StartsWith("-"))
throw new ApplicationArgumentException("Option '-f' needs argument <path>");
ConfigFileName = args[1];
args = args.Skip(2).ToArray();
break;
case "-b":
if (args.Length == 1 || args[1].StartsWith("-"))
throw new ApplicationArgumentException("Option '-b' needs argument <version>");
Version version = null;
if (!Version.TryParse(args[1], out version))
throw new ApplicationArgumentException("Option '-b' argument '{0}' is not valid version", args[1]);
DevelopVersion = version;
args = args.Skip(2).ToArray();
break;
default:
throw new ApplicationArgumentException("Unknown option '{0}'", args[0]);
}
}
if (args.Length == 0)
throw new ApplicationArgumentException("You need to specify at least one file");
FileNames = args;
}
}
}