diff --git a/sdk/provisioning/Generator/src/GenerateOptions.cs b/sdk/provisioning/Generator/src/GenerateOptions.cs new file mode 100644 index 000000000000..5f1d3bbf2757 --- /dev/null +++ b/sdk/provisioning/Generator/src/GenerateOptions.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using CommandLine; + +namespace Generator; + +internal class GenerateOptions +{ + [Option(longName: "filter", shortName: 'f', Required = false, Hidden = false)] + public string? Filter { get; set; } + + [Option(longName: "schema", shortName: 's', Required = false, Default = true, Hidden = false)] + public bool GenerateSchema { get; set; } +} diff --git a/sdk/provisioning/Generator/src/Generator.csproj b/sdk/provisioning/Generator/src/Generator.csproj index 33cb230332f2..9366ee83fee9 100644 --- a/sdk/provisioning/Generator/src/Generator.csproj +++ b/sdk/provisioning/Generator/src/Generator.csproj @@ -9,6 +9,7 @@ + diff --git a/sdk/provisioning/Generator/src/Program.cs b/sdk/provisioning/Generator/src/Program.cs index ceec20488f00..c846378b96ce 100644 --- a/sdk/provisioning/Generator/src/Program.cs +++ b/sdk/provisioning/Generator/src/Program.cs @@ -1,97 +1,117 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Collections.Generic; using Azure.Provisioning.Generator.Model; using Azure.Provisioning.Generator.Specifications; +using CommandLine; +using System; +using System.Collections.Generic; -// Collect all the specs to generate -List baselineSpecs = -[ - new ArmSpecification(), - new ResourcesSpecification(), - new AuthorizationSpecification(), - new ManagedServiceIdentitiesSpecification(), -]; -List rpSpecs = -[ - new AppContainersSpecification(), - new AppServiceSpecification(), - new AppConfigurationSpecification(), - new ApplicationInsightsSpecification(), - new CommunicationSpecification(), - new CognitiveServicesSpecification(), - new ContainerRegistrySpecification(), - new ContainerServiceSpecification(), - new CosmosDBSpecification(), - //new DnsSpecification(), // the Dns's mgmt SDK is majority hand-crafted, therefore here we just use this to generate a scaffold, and then hand-craft the rest. - new EventGridSpecification(), - new EventHubsSpecification(), - new FrontDoorSpecification(), - new KeyVaultSpecification(), - new KubernetesSpecification(), - new KubernetesConfigurationSpecification(), - new KustoSpecification(), - new NetworkSpecification(), - new OperationalInsightsSpecification(), - new PostgreSqlSpecification(), - new RedisSpecification(), - new RedisEnterpriseSpecification(), - new SearchSpecification(), - new ServiceBusSpecification(), - new SignalRSpecification(), - new SqlSpecification(), - new StorageSpecification(), - new WebPubSubSpecification(), -]; +namespace Generator; -// Generate the specs -Dictionary failures = []; -foreach (Specification spec in baselineSpecs) +internal static class Program { - try - { - Console.WriteLine($"Generating {spec.Name}..."); - spec.Build(); - } - catch (Exception ex) + public static int Main(string[] args) { - failures[spec.Name] = ex.Message; + return Parser.Default.ParseArguments(args) + .MapResult( + Generate, + errs => 1); } -} -// defines the filter to be the first argument -string? filter = null; -if (args.Length > 0) -{ - filter = args[0]; - Console.WriteLine($"Filtering to only generate specifications matching '{filter}'"); -} -foreach (Specification spec in rpSpecs) -{ - if (filter is not null && spec.Name != filter) - { - Console.WriteLine($"Skipping {spec.Name}..."); - continue; - } - try - { - Console.WriteLine($"Generating {spec.Name}..."); - spec.Build(); - } - catch (Exception ex) - { - failures[spec.Name] = ex.Message; - } -} -Console.WriteLine("\n\nFinished generating all specifications.\n\n"); -if (failures.Count > 0) -{ - Console.ForegroundColor = ConsoleColor.Red; - foreach (KeyValuePair failure in failures) + + private static int Generate(GenerateOptions options) { - Console.WriteLine($"{failure.Key}: {failure.Value}"); - Console.WriteLine("\n\n"); + // Collect all the specs to generate + List baselineSpecs = + [ + new ArmSpecification(), + new ResourcesSpecification(), + new AuthorizationSpecification(), + new ManagedServiceIdentitiesSpecification(), + ]; + List rpSpecs = + [ + new AppContainersSpecification(), + new AppServiceSpecification(), + new AppConfigurationSpecification(), + new ApplicationInsightsSpecification(), + new CommunicationSpecification(), + new CognitiveServicesSpecification(), + new ContainerRegistrySpecification(), + new ContainerServiceSpecification(), + new CosmosDBSpecification(), + //new DnsSpecification(), // the Dns's mgmt SDK is majority hand-crafted, therefore here we just use this to generate a scaffold, and then hand-craft the rest. + new EventGridSpecification(), + new EventHubsSpecification(), + new FrontDoorSpecification(), + new KeyVaultSpecification(), + new KubernetesSpecification(), + new KubernetesConfigurationSpecification(), + new KustoSpecification(), + new NetworkSpecification(), + new OperationalInsightsSpecification(), + new PostgreSqlSpecification(), + new RedisSpecification(), + new RedisEnterpriseSpecification(), + new SearchSpecification(), + new ServiceBusSpecification(), + new SignalRSpecification(), + new SqlSpecification(), + new StorageSpecification(), + new WebPubSubSpecification(), + ]; + + // Generate the specs + Dictionary failures = []; + foreach (Specification spec in baselineSpecs) + { + try + { + Console.WriteLine($"Generating {spec.Name}..."); + // spec.Build(options.GenerateSchema); + spec.Build(); + } + catch (Exception ex) + { + failures[spec.Name] = ex.Message; + } + } + // defines the filter to be the first argument + string? filter = options.Filter; + if (filter is not null) + { + Console.WriteLine($"Filtering to only generate specifications matching '{filter}'"); + } + foreach (Specification spec in rpSpecs) + { + if (filter is not null && spec.Name != filter) + { + Console.WriteLine($"Skipping {spec.Name}..."); + continue; + } + try + { + Console.WriteLine($"Generating {spec.Name}..."); + // spec.Build(options.GenerateSchema); + spec.Build(); + } + catch (Exception ex) + { + failures[spec.Name] = ex.Message; + } + } + Console.WriteLine("\n\nFinished generating all specifications.\n\n"); + if (failures.Count > 0) + { + Console.ForegroundColor = ConsoleColor.Red; + foreach (KeyValuePair failure in failures) + { + Console.WriteLine($"{failure.Key}: {failure.Value}"); + Console.WriteLine("\n\n"); + } + } + Console.WriteLine($"{failures.Count} Failure{(failures.Count == 1 ? "" : "s")}.\n"); + + return failures.Count == 0 ? 0 : 1; } } -Console.WriteLine($"{failures.Count} Failure{(failures.Count == 1 ? "" : "s")}.\n"); \ No newline at end of file