Skip to content

Commit

Permalink
fix upgrade appsettings
Browse files Browse the repository at this point in the history
  • Loading branch information
bjosttveit committed Sep 26, 2023
1 parent 806d405 commit e829a24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
28 changes: 15 additions & 13 deletions cli-tools/altinn-app-cli/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,8 +44,18 @@ static async Task<int> 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();
Expand Down Expand Up @@ -114,16 +125,7 @@ static async Task<int> 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(() =>
Expand Down Expand Up @@ -221,13 +223,13 @@ static async Task<int> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

namespace altinn_app_cli.v7Tov8.AppSettingsRewriter;


/// <summary>
/// Rewrites the appsettings.*.json files
/// </summary>
public class AppSettingsRewriter
{
/// <summary>
/// The pattern used to search for appsettings.*.json files
/// </summary>
public static readonly string APP_SETTINGS_FILE_PATTERN = "appsettings*.json";

private Dictionary<string, JsonObject> appSettingsJsonCollection;

private readonly IList<string> warnings = new List<string>();

/// <summary>
Expand All @@ -18,7 +25,7 @@ public class AppSettingsRewriter
public AppSettingsRewriter(string appSettingsFolder)
{
appSettingsJsonCollection = new Dictionary<string, JsonObject>();
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);
Expand Down

0 comments on commit e829a24

Please sign in to comment.