Skip to content

Commit

Permalink
Add version output to code generator (#904)
Browse files Browse the repository at this point in the history
* Added version information on code generation

* Fixed warnings

* Fixed comments
  • Loading branch information
helto4real authored Aug 7, 2023
1 parent 6fc1af2 commit 8382bd0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ public static CompilationUnitSyntax BuildCompilationUnit(string namespaceName, p
.NormalizeWhitespace();
}

private static readonly string GeneratorVersion = Assembly.GetAssembly(typeof(Generator))!.GetName().Version!.ToString();

private static SyntaxTrivia[] GetFileHeader()
{
string headerText = @$"
//------------------------------------------------------------------------------
// <auto-generated>
// Generated using NetDaemon CodeGenerator nd-codegen v{GeneratorVersion}
// Generated using NetDaemon CodeGenerator nd-codegen v{VersionHelper.GeneratorVersion}
// At: {DateTime.Now:O}
//
// *** Make sure the version of the codegen tool and your nugets Joysoftware.NetDaemon.* have the same version.***
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Reflection;

namespace NetDaemon.HassModel.CodeGenerator.Helpers;

#pragma warning disable CA1303

/// <summary>
/// Helper class for managing NetDaemon version tasks
/// </summary>
public static class VersionHelper
{
/// <summary>
/// Returns current version of NetDaemon
/// </summary>
public static string GeneratorVersion { get; } =
Assembly.GetAssembly(typeof(Generator))!.GetName().Version!.ToString();

/// <summary>
/// Pretty prints version information to console
/// </summary>
public static void PrintVersion()
{
Console.Write("Codegen version: ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(GeneratorVersion);
Console.ResetColor();
}
}
1 change: 1 addition & 0 deletions src/HassModel/NetDaemon.HassModel.CodeGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
generationSettings.GenerateOneFilePerEntity = args.Any(arg => arg.ToLower(CultureInfo.InvariantCulture) == "-fpe");

var controller = new Controller(generationSettings, haSettings);
VersionHelper.PrintVersion();
await controller.RunAsync().ConfigureAwait(false);

Console.WriteLine();
Expand Down

0 comments on commit 8382bd0

Please sign in to comment.