• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

net-daemon / netdaemon / 5787397855

pending completion
5787397855

push

github

web-flow
Add version output to code generator (#904)

* Added version information on code generation

* Fixed warnings

* Fixed comments

791 of 1112 branches covered (71.13%)

Branch coverage included in aggregate %.

10 of 10 new or added lines in 3 files covered. (100.0%)

3711 of 4350 relevant lines covered (85.31%)

48.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/HassModel/NetDaemon.HassModel.CodeGenerator/Program.cs
1
using System.Globalization;
2
using Microsoft.Extensions.Configuration;
3
using NetDaemon.Client.Settings;
4

5
#pragma warning disable CA1303
6

7
var configurationRoot = GetConfigurationRoot();
×
8
var haSettings = configurationRoot.GetSection("HomeAssistant").Get<HomeAssistantSettings>() ?? new HomeAssistantSettings();
×
9
var generationSettings = configurationRoot.GetSection("CodeGeneration").Get<CodeGenerationSettings>() ?? new CodeGenerationSettings();
×
10

11
if (args.Any(arg => arg.ToLower(CultureInfo.InvariantCulture) == "-help"))
×
12
{
×
13
    ShowUsage();
×
14
    return 0;
×
15
}
16

17
//This is used as a command line switch rather than a configuration key. There is no key value following it to interpret.
18
generationSettings.GenerateOneFilePerEntity = args.Any(arg => arg.ToLower(CultureInfo.InvariantCulture) == "-fpe");
×
19

20
var controller = new Controller(generationSettings, haSettings);
×
21
VersionHelper.PrintVersion();
×
22
await controller.RunAsync().ConfigureAwait(false);
×
23

24
Console.WriteLine();
×
25
Console.WriteLine("Code Generated successfully!");
×
26

27
return 0;
×
28

29
IConfigurationRoot GetConfigurationRoot()
30
{
×
31
    var env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
×
32
    var builder = new ConfigurationBuilder()
×
33
        // default path is the folder of the currently executing root assembly
×
34
        .AddJsonFile("appsettings.json", true, true)
×
35
        .AddJsonFile($"appsettings.{env}.json", true, true)
×
36

×
37
        // Also look in the current directory which will typically be the project folder
×
38
        // of the users code and have a appsettings.development.json with the correct HA connection settings
×
39
        .SetBasePath(Environment.CurrentDirectory)
×
40
        .AddJsonFile("appsettings.json", true, true)
×
41
        .AddJsonFile("appsettings.development.json", true, true)
×
42
        .AddUserSecrets<Program>()
×
43

×
44
        // finally override with Environment vars or commandline
×
45
        .AddEnvironmentVariables()
×
46
        .AddCommandLine(args, new Dictionary<string, string>()
×
47
        {
×
48
            ["-o"] = "CodeGeneration:OutputFile",
×
49
            ["-f"] = "CodeGeneration:OutputFolder",
×
50
            ["-ns"] = "CodeGeneration:Namespace",
×
51
            ["-host"] = "HomeAssistant:Host",
×
52
            ["-port"] = "HomeAssistant:Port",
×
53
            ["-ssl"] = "HomeAssistant:Ssl",
×
54
            ["-token"] = "HomeAssistant:Token",
×
55
            ["-bypass-cert"] = "HomeAssistant:InsecureBypassCertificateErrors",
×
56
        });
×
57

58
    return builder.Build();
×
59
}
×
60

61
void ShowUsage()
62
{
×
63
    Console.WriteLine(@"
×
64
    Usage: nd-codegen [options] -ns namespace -o outfile
×
65
    Options:
×
66
        -f           : Name of folder to output files (folder name only)
×
67
        -fpe         : Create separate file per entity (ignores -o option)
×
68
        -host        : Host of the netdaemon instance
×
69
        -port        : Port of the NetDaemon instance
×
70
        -ssl         : true if NetDaemon instance use ssl
×
71
        -token       : A long lived HomeAssistant token
×
72
        -bypass-cert : Ignore certificate errors (insecure)
×
73

×
74
    These settings is valid when installed codegen as global dotnet tool.
×
75
            ");
×
76
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc