Skip to content

Commit

Permalink
Adding capability to search subdirectories in Yaml Validator (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwduncan authored Jul 2, 2024
1 parent c311fc2 commit cfd5604
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/YamlValidator/YamlLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,44 @@
using System.Collections.ObjectModel;

namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;

public class YamlLoader
{
public IReadOnlyDictionary<string, string> Load(string filePath, string pathType)
{
var deserializedYaml = new Dictionary<string, string>();

if (pathType == Constants.FileTypeName)
{
var fileName = Path.GetFileName(filePath);
var yamlText = Utility.ReadFileData(filePath);
deserializedYaml.Add(fileName, yamlText);
return new ReadOnlyDictionary<string, string>(deserializedYaml);
}

// to do: address edge case of .yml files
var files = Directory.GetFiles(filePath, $"*{Constants.YamlFileExtension}");
foreach (var file in files)
else if (pathType == Constants.FolderTypeName)
{
var fileName = Path.GetFileName(file);
var yamlText = Utility.ReadFileData(file);
deserializedYaml.Add(fileName, yamlText);
// TODO: Determine if argument flag should be required to specify recursive folder search
try
{
var yamlFiles = Directory.EnumerateFiles(filePath, "*" + Constants.YamlFileExtension, SearchOption.AllDirectories);
foreach (var filename in yamlFiles)
{
var fileName = Path.GetFileName(filename);
var yamlText = Utility.ReadFileData(filename);
deserializedYaml.Add(fileName, yamlText);
}
}
catch (UnauthorizedAccessException ex)
{
Console.WriteLine($"Unauthorized access exception: {ex.Message}");
}
catch (IOException ex)
{
Console.WriteLine($"IO exception: {ex.Message}");
}
}
else
{
throw new ArgumentException("Invalid path type");
}

return new ReadOnlyDictionary<string, string>(deserializedYaml);
Expand Down

0 comments on commit cfd5604

Please sign in to comment.