forked from harp-tech/toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateInterfaceCommand.cs
More file actions
35 lines (30 loc) · 1.36 KB
/
GenerateInterfaceCommand.cs
File metadata and controls
35 lines (30 loc) · 1.36 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
using System.CommandLine;
using Harp.Generators;
namespace Harp.Toolkit.Generate;
class GenerateInterfaceCommand : Command
{
public GenerateInterfaceCommand()
: base("interface", "Generate reactive programming API and async API.")
{
MetadataPathArgument metadataPathArgument = new();
OutputPathOption outputPathOption = new();
Option<string> namespaceOption = new("-ns", "--namespace")
{
Description = "The namespace for the generated code. The default is `Harp.DeviceName`."
};
Arguments.Add(metadataPathArgument);
Options.Add(namespaceOption);
Options.Add(outputPathOption);
SetAction(parseResult =>
{
var outputPath = parseResult.GetRequiredValue(outputPathOption);
var metadataPath = parseResult.GetRequiredValue(metadataPathArgument);
var ns = parseResult.GetValue(namespaceOption);
var deviceMetadata = GeneratorHelper.ReadDeviceMetadata(metadataPath.FullName);
var generator = new InterfaceGenerator(deviceMetadata, ns ?? $"Harp.{deviceMetadata.Device}");
var implementation = generator.GenerateImplementation();
if (GeneratorHelper.AssertNoGeneratorErrors(generator.Errors))
GenerateCommand.WriteFileContents(outputPath.FullName, implementation);
});
}
}