From 9bf919e3af0e5bd8d60ef25e4eaba3df875503f6 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Sat, 4 Dec 2021 10:47:52 +0100 Subject: [PATCH] feat: Recursive configuration search --- src/GCRealTimeMon/Program.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/GCRealTimeMon/Program.cs b/src/GCRealTimeMon/Program.cs index 26c7af6..51b3855 100644 --- a/src/GCRealTimeMon/Program.cs +++ b/src/GCRealTimeMon/Program.cs @@ -205,8 +205,23 @@ static async Task HandleConsoleInputAsync(IDisposable session, IConsoleOut conso // Case: Neither -g nor -c was specified => fall back to the Default config. else { + // Search if there is a file named .gcmon from the current folder to the root of the current folder volume; + // If not found, use the default configuration. + var currentfolder = new DirectoryInfo(System.Environment.CurrentDirectory); + var root = currentfolder.Root; + var configPath = Path.Combine(currentfolder.FullName, ".gcmon"); + bool founded; + while ((founded = File.Exists(configPath)) == false && currentfolder != root) + { + currentfolder = currentfolder.Parent; + configPath = Path.Combine(currentfolder.FullName, ".gcmon"); + } + if (founded == false) + { + configPath = defaultPath; + } // the default .yaml file is at the same location as the CLI global tool / console application - return await ConfigurationReader.ReadConfigurationAsync(defaultPath); + return await ConfigurationReader.ReadConfigurationAsync(configPath); } }