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

net-daemon / netdaemon / 6368659139

01 Oct 2023 06:28AM UTC coverage: 81.178% (-0.9%) from 82.053%
6368659139

push

github

web-flow
Validate version of nugets and nd-codegen match (#945)

810 of 1148 branches covered (0.0%)

Branch coverage included in aggregate %.

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

2938 of 3469 relevant lines covered (84.69%)

50.74 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
VersionHelper.PrintVersion();
×
21
DependencyValidator.ValidatePackageRefrences();
×
22

23
var controller = new Controller(generationSettings, haSettings);
×
24
await controller.RunAsync().ConfigureAwait(false);
×
25

26
Console.WriteLine();
×
27
Console.WriteLine("Code Generated successfully!");
×
28

29
return 0;
×
30

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

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

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

60
    return builder.Build();
×
61
}
62

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

×
76
    These settings is valid when installed codegen as global dotnet tool.
×
77
            ");
×
78
}
×
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

© 2025 Coveralls, Inc