Skip to content

Commit

Permalink
fix: allow the CLI to be used in NET6 and NET7
Browse files Browse the repository at this point in the history
  • Loading branch information
buehler committed Jan 16, 2024
1 parent be6ec33 commit 20db12c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/KubeOps.Cli/Certificates/CertificateGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ public static (X509Certificate Certificate, AsymmetricCipherKeyPair Key) CreateS
certificateGenerator.AddExtension(
X509Extensions.SubjectAlternativeName,
false,
new GeneralNames(new[]
{
new GeneralNames([
new GeneralName(GeneralName.DnsName, $"{serverName}.{serverNamespace}.svc"),
new GeneralName(GeneralName.DnsName, $"*.{serverNamespace}.svc"),
new GeneralName(GeneralName.DnsName, "*.svc"),
}));
]));

// Subject Public Key
const int keyStrength = 256;
Expand Down
2 changes: 1 addition & 1 deletion src/KubeOps.Cli/KubeOps.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions src/KubeOps.Cli/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class Options
"The path the command will write the files to. If omitted, prints output to console.");

public static readonly Option<string?> TargetFramework = new(
new[] { "--target-framework", "--tfm" },
["--target-framework", "--tfm"],
description: "Target framework of projects in the solution to search for entities. " +
"If omitted, the newest framework is used.");

Expand All @@ -32,12 +32,12 @@ internal static class Options
"If omitted, all projects are searched.");

public static readonly Option<bool> Force = new(
new[] { "--force", "-f" },
["--force", "-f"],
() => false,
description: "Do not bother the user with questions and just do it.");

public static readonly Option<bool> ClearOutputPath = new(
new[] { "--clear-out" },
["--clear-out"],
() => false,
description: "Clear the output path before generating resources.");
}
11 changes: 10 additions & 1 deletion src/KubeOps.Cli/Transpilation/AssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;

Expand All @@ -22,6 +23,10 @@ namespace KubeOps.Cli.Transpilation;
/// <summary>
/// AssemblyLoader.
/// </summary>
[SuppressMessage(
"Usage",
"CA2252:This API requires opting into preview features",
Justification = "It is the CLI that uses the libraries.")]
internal static partial class AssemblyLoader
{
static AssemblyLoader()
Expand Down Expand Up @@ -192,6 +197,10 @@ public static IEnumerable<EntityMetadata> GetConvertedEntities(this MetadataLoad
.Distinct()
.Select(t => context.ToEntityMetadata(t.BaseType!.GenericTypeArguments[0]).Metadata);

#if NET7_0_OR_GREATER
[GeneratedRegex(".*")]
private static partial Regex DefaultRegex();
#else
private static Regex DefaultRegex() => new(".*");
#endif
}
7 changes: 7 additions & 0 deletions src/KubeOps.Cli/Transpilation/TfmComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ namespace KubeOps.Cli.Transpilation;
/// </summary>
internal sealed partial class TfmComparer : IComparer<string>
{
#if NET7_0_OR_GREATER
[GeneratedRegex(
"[(]?(?<tfm>(?<name>(netcoreapp|net|netstandard){1})(?<major>[0-9]+)[.](?<minor>[0-9]+))[)]?",
RegexOptions.Compiled)]
public static partial Regex TfmRegex();
#else
public static Regex TfmRegex() =>
new(
"[(]?(?<tfm>(?<name>(netcoreapp|net|netstandard){1})(?<major>[0-9]+)[.](?<minor>[0-9]+))[)]?",
RegexOptions.Compiled);
#endif

public int Compare(string? x, string? y)
{
Expand Down

0 comments on commit 20db12c

Please sign in to comment.