-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathGenerateCommand.Definition.cs
71 lines (61 loc) · 2.73 KB
/
GenerateCommand.Definition.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
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
namespace GirTool;
public partial class GenerateCommand : Command
{
public GenerateCommand() : base(
name: "generate",
description: "Generate C# bindings from gir files"
)
{
var inputArgument = new Argument<string[]>(
name: "input",
description: "The names of gir files which should be processed"
);
var outputOption = new Option<string>(
aliases: new[] { "-o", "--output" },
description: "The directory to write the generated C# files to",
getDefaultValue: () => "./Libs"
);
var searchPathOptionLinux = new Option<string>(
aliases: new[] { "-sl", "--search-path-linux" },
description: "The directory which is searched for dependent linux gir files"
);
var searchPathOptionMacos = new Option<string>(
aliases: new[] { "-sm", "--search-path-macos" },
description: "The directory which is searched for dependent macos gir files"
);
var searchPathOptionWindows = new Option<string>(
aliases: new[] { "-sw", "--search-path-windows" },
description: "The directory which is searched for dependent windows gir files"
);
var disableAsyncOption = new Option<bool>(
aliases: new[] { "-d", "--disable-async" },
getDefaultValue: () => false,
description: "Generate files synchronously - useful for debugging"
);
var logLevelOption = new Option<LogLevel>(
aliases: new[] { "-l", "--log-level" },
getDefaultValue: () => LogLevel.Standard,
description: "Set the log level"
);
AddArgument(inputArgument);
AddOption(outputOption);
AddOption(searchPathOptionLinux);
AddOption(searchPathOptionMacos);
AddOption(searchPathOptionWindows);
AddOption(disableAsyncOption);
AddOption(logLevelOption);
this.SetHandler(context => Execute(
input: context.ParseResult.GetValueForArgument(inputArgument),
output: context.ParseResult.GetValueForOption(outputOption) ?? throw new Exception("Output unknown"),
searchPathLinux: context.ParseResult.GetValueForOption(searchPathOptionLinux),
searchPathMacos: context.ParseResult.GetValueForOption(searchPathOptionMacos),
searchPathWindows: context.ParseResult.GetValueForOption(searchPathOptionWindows),
disableAsync: context.ParseResult.GetValueForOption(disableAsyncOption),
logLevel: context.ParseResult.GetValueForOption(logLevelOption),
invocationContext: context
));
}
}