-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
56 lines (53 loc) · 1.64 KB
/
Program.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
using System;
namespace SuperSimpleParser
{
class Program
{
static void Test(string commanLine)
{
CommandLineParser parser = CommandLineParser.Parse(commanLine);
parser.Dump();
Console.WriteLine("---");
}
static void Main(string[] args)
{
// Ignore argument with no switch
Test(Environment.CommandLine);
// If you want to get module name add a switch
Test("-program " + Environment.CommandLine);
// You can use " ou ' for string, -zip will produce "true", same switch used more than one = get a list
Test("-t [email protected] -f [email protected] -o \"Test mail\" -b body.txt -j report1.pdf -j report2.pdf -zip");
// You can read from a file that contain \r \n
Test(System.IO.File.ReadAllText("TextFile1.txt"));
CommandLineParser parser = CommandLineParser.Parse("--angle 180 -type deg -visible -path #with sharp separator# -env TEMP");
Console.WriteLine(parser.GetInt32("angle") + 10);
Console.WriteLine(parser.GetString("type"));
Console.WriteLine(parser.GetBool("visible"));
Console.WriteLine(parser.GetString("path"));
Console.WriteLine(parser.GetEnv("env"));
/*
Output
---
program=D:\dev\SuperSimpleParser\bin\Debug\netcoreapp3.1\SuperSimpleParser.dll
---
o=Test mail
b=body.txt
j=report1.pdf, report2.pdf
zip=true
---
o=Test mail
b=body.txt
j=report.pdf, second file.txt
zip=true
---
190
deg
True
*/
}
}
}