From e829a24fd915ce30fe790b4a2099c59f5b598de4 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 26 Sep 2023 13:29:12 +0200 Subject: [PATCH] fix upgrade appsettings --- cli-tools/altinn-app-cli/Program.cs | 28 ++++++++++--------- .../AppSettingsRewriter.cs | 9 +++++- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/cli-tools/altinn-app-cli/Program.cs b/cli-tools/altinn-app-cli/Program.cs index 613a9577e..876fbf2e0 100644 --- a/cli-tools/altinn-app-cli/Program.cs +++ b/cli-tools/altinn-app-cli/Program.cs @@ -1,4 +1,5 @@ using System.CommandLine; +using System.CommandLine.Invocation; using System.Reflection; using altinn_app_cli.v7Tov8.AppSettingsRewriter; using altinn_app_cli.v7Tov8.CodeRewriters; @@ -43,8 +44,18 @@ static async Task Main(string[] args) rootCommand.AddCommand(versionCommand); upgradeCommand.SetHandler( - async (projectFolder, projectFile, processFile, appSettingsFolder, targetVersion, skipCodeUpgrade, skipProcessUpgrade, skipCsprojUpgrade, skipAppSettingsUpgrade) => + async (InvocationContext context) => { + var projectFolder = context.ParseResult.GetValueForOption(projectFolderOption)!; + var projectFile = context.ParseResult.GetValueForOption(projectFileOption)!; + var processFile = context.ParseResult.GetValueForOption(processFileOption)!; + var appSettingsFolder = context.ParseResult.GetValueForOption(appSettingsFolderOption)!; + var targetVersion = context.ParseResult.GetValueForOption(targetVersionOption)!; + var skipCodeUpgrade = context.ParseResult.GetValueForOption(skipCodeUpgradeOption)!; + var skipProcessUpgrade = context.ParseResult.GetValueForOption(skipProcessUpgradeOption)!; + var skipCsprojUpgrade = context.ParseResult.GetValueForOption(skipCsprojUpgradeOption)!; + var skipAppSettingsUpgrade = context.ParseResult.GetValueForOption(skipAppSettingsUpgradeOption)!; + if (projectFolder == "CurrentDirectory") { projectFolder = Directory.GetCurrentDirectory(); @@ -114,16 +125,7 @@ static async Task Main(string[] args) { Console.WriteLine("Upgrade completed with errors. Please check for errors in the log above."); } - }, - projectFolderOption, - projectFileOption, - processFileOption, - appSettingsFolderOption, - targetVersionOption, - skipCodeUpgradeOption, - skipProcessUpgradeOption, - skipCsprojUpgradeOption, - skipAppSettingsUpgradeOption + } ); versionCommand.SetHandler(() => @@ -221,13 +223,13 @@ static async Task UpgradeAppSettings(string appSettingsFolder) return 1; } - if (Directory.GetFiles(appSettingsFolder, "appsettings.*.json").Count() == 0) + if (Directory.GetFiles(appSettingsFolder, AppSettingsRewriter.APP_SETTINGS_FILE_PATTERN).Count() == 0) { Console.WriteLine($"No appsettings.*.json files found in {appSettingsFolder}"); return 1; } - Console.WriteLine("Trying to upgrade appsettings.*.json files"); + Console.WriteLine("Trying to upgrade appsettings*.json files"); AppSettingsRewriter rewriter = new(appSettingsFolder); rewriter.Upgrade(); await rewriter.Write(); diff --git a/cli-tools/altinn-app-cli/v7Tov8/AppSettingsRewriter/AppSettingsRewriter.cs b/cli-tools/altinn-app-cli/v7Tov8/AppSettingsRewriter/AppSettingsRewriter.cs index 68d6cd178..860d2b1b3 100644 --- a/cli-tools/altinn-app-cli/v7Tov8/AppSettingsRewriter/AppSettingsRewriter.cs +++ b/cli-tools/altinn-app-cli/v7Tov8/AppSettingsRewriter/AppSettingsRewriter.cs @@ -4,12 +4,19 @@ namespace altinn_app_cli.v7Tov8.AppSettingsRewriter; + /// /// Rewrites the appsettings.*.json files /// public class AppSettingsRewriter { + /// + /// The pattern used to search for appsettings.*.json files + /// + public static readonly string APP_SETTINGS_FILE_PATTERN = "appsettings*.json"; + private Dictionary appSettingsJsonCollection; + private readonly IList warnings = new List(); /// @@ -18,7 +25,7 @@ public class AppSettingsRewriter public AppSettingsRewriter(string appSettingsFolder) { appSettingsJsonCollection = new Dictionary(); - foreach (var file in Directory.GetFiles(appSettingsFolder, "appsettings.*.json")) + foreach (var file in Directory.GetFiles(appSettingsFolder, APP_SETTINGS_FILE_PATTERN)) { var json = File.ReadAllText(file); var appSettingsJson = JsonNode.Parse(json);