-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCommandLineOptions.cs
50 lines (32 loc) · 1.16 KB
/
CommandLineOptions.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
using Microsoft.Extensions.CommandLineUtils;
using ConsoleStarter.Commands;
using ConsoleStarter.CommandConfiguration;
namespace ConsoleStarter
{
public class CommandLineOptions
{
public static CommandLineOptions Parse(string[] args)
{
var options = new CommandLineOptions();
var app = new CommandLineApplication
{
Name = "console-starter",
FullName = ".NET Core Neat Console Starter"
};
app.HelpOption("-?|-h|--help");
var enthousiasticSwitch = app.Option("-e|--enthousiastically",
"Whether the app should be enthousiastic.",
CommandOptionType.NoValue);
RootCommandConfiguration.Configure(app, options);
var result = app.Execute(args);
if (result != 0)
{
return null;
}
options.IsEnthousiastic = enthousiasticSwitch.HasValue();
return options;
}
public ICommand Command { get; set; }
public bool IsEnthousiastic { get; set; }
}
}