Skip to content

Commit eff6f38

Browse files
committed
Update sample app
1 parent e7a3fcd commit eff6f38

2 files changed

Lines changed: 55 additions & 3 deletions

File tree

SampleApp/Program.cs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,63 @@
11
using System;
2+
using MatthiWare.CommandLine;
23

34
namespace SampleApp
45
{
56
class Program
67
{
7-
static void Main(string[] args)
8+
static int Main(string[] args)
89
{
9-
foreach (var arg in args)
10-
Console.WriteLine(arg);
10+
var parser = new CommandLineParser<Options>();
11+
12+
// setup
13+
parser.Configure(opt => opt.MyInt)
14+
.ShortName("-i")
15+
.LongName("--int")
16+
.Required();
17+
18+
parser.Configure(opt => opt.MyString)
19+
.ShortName("-s")
20+
.LongName("--string")
21+
.Required();
22+
23+
parser.Configure(opt => opt.MyBool)
24+
.ShortName("-b")
25+
.LongName("--bool")
26+
.Required();
27+
28+
parser.Configure(opt => opt.MyDouble)
29+
.ShortName("-d")
30+
.LongName("--double")
31+
.Required();
32+
33+
var result = parser.Parse(args);
34+
35+
if (result.HasErrors)
36+
{
37+
Console.Error.WriteLine(result.Error);
38+
Console.ReadKey();
39+
40+
return -1;
41+
}
42+
43+
var options = result.Result;
44+
45+
Console.WriteLine($"MyInt: {options.MyInt}");
46+
Console.WriteLine($"MyString: {options.MyString}");
47+
Console.WriteLine($"MyBool: {options.MyBool}");
48+
Console.WriteLine($"MyDouble: {options.MyDouble}");
1149

1250
Console.ReadKey();
51+
52+
return 0;
53+
}
54+
55+
private class Options
56+
{
57+
public int MyInt { get; set; }
58+
public string MyString { get; set; }
59+
public bool MyBool { get; set; }
60+
public double MyDouble { get; set; }
1361
}
1462
}
1563
}

SampleApp/SampleApp.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55
<TargetFramework>netcoreapp2.1</TargetFramework>
66
</PropertyGroup>
77

8+
<ItemGroup>
9+
<ProjectReference Include="..\CommandLineParser\CommandLineParser.csproj" />
10+
</ItemGroup>
11+
812
</Project>

0 commit comments

Comments
 (0)