Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding capability to search subdirectories in Yaml Validator #690

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/YamlValidator/YamlLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,39 @@
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 flag should be required to specify recursive folder search
try
{
foreach (var filename in Directory.EnumerateFiles(filePath, "*" + Constants.YamlFileExtension, SearchOption.AllDirectories))
cwduncan marked this conversation as resolved.
Show resolved Hide resolved
{
var fileName = Path.GetFileName(filename);
var yamlText = Utility.ReadFileData(filename);
deserializedYaml.Add(fileName, yamlText);
}
}
catch (UnauthorizedAccessException ex)
{
Console.WriteLine($"Unauthorized access exception: {ex.Message}");
}
}
else
{
throw new ArgumentException("Invalid path type");
}

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