tazel
A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.
Clonegit clone https://git.progmasoft.com/tazel
Reduce cyclomatic complexity of LogCommands.Registries
- Commit
26bfca7195cfeace00b461457b8884793ff08441- Author
- Leitwolf11 ·
- Parents
da68f48b4d7d
Changes
src/Progmasoft.Tazel/Cli/LogCommands.cs | 72 ++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/src/Progmasoft.Tazel/Cli/LogCommands.cs b/src/Progmasoft.Tazel/Cli/LogCommands.cs index 6ce89c1..1239efc 100644 --- a/src/Progmasoft.Tazel/Cli/LogCommands.cs +++ b/src/Progmasoft.Tazel/Cli/LogCommands.cs @@ -81,47 +81,61 @@ internal sealed class LogCommands(Reporter reporter, string workingDirectory, Ve private int Registries() { - string? moduleRoot = null; - try + var source = FindRegistriesFile(); + reporter.Plain($"source: {source ?? "built-in"}"); + if (source is not null && PrintRedactedRegistries(source)) { - moduleRoot = ModuleFiles.FindRoot(workingDirectory); + return 0; } - catch (ProjectException) + + reporter.Plain("1. portal-modules (built-in)"); + reporter.Plain("global-credential-providers: (none)"); + return 0; + } + + private string? FindRegistriesFile() + { + var moduleFile = TryModuleRegistriesFile(); + if (moduleFile is not null) { - // Outside a module: show user/built-in registries. + return moduleFile; } - var moduleFile = moduleRoot is null ? null : Path.Combine(moduleRoot, "tazel_registries.txt"); var userHome = Environment.GetEnvironmentVariable("TAZEL_HOME"); - var userFile = string.IsNullOrWhiteSpace(userHome) - ? null - : Path.Combine(userHome, "User", "tazel_registries.txt"); + if (string.IsNullOrWhiteSpace(userHome)) + { + return null; + } - var source = moduleFile is not null && File.Exists(moduleFile) ? moduleFile - : userFile is not null && File.Exists(userFile) ? userFile - : "built-in"; + var userFile = Path.Combine(userHome, "User", "tazel_registries.txt"); + return File.Exists(userFile) ? userFile : null; + } - reporter.Plain($"source: {source}"); - if (source != "built-in") + private string? TryModuleRegistriesFile() + { + try { - var lines = File.ReadAllLines(source) - .Select(line => line.Trim()) - .Where(line => line.Length > 0 && !line.StartsWith('#') && !line.Contains("token", StringComparison.OrdinalIgnoreCase)) - .ToList(); - if (lines.Count > 0) - { - foreach (var line in lines) - { - reporter.Plain($" {line}"); - } + var path = Path.Combine(ModuleFiles.FindRoot(workingDirectory), "tazel_registries.txt"); + return File.Exists(path) ? path : null; + } + catch (ProjectException) + { + return null; + } + } - return 0; - } + private bool PrintRedactedRegistries(string path) + { + var lines = File.ReadAllLines(path) + .Select(line => line.Trim()) + .Where(line => line.Length > 0 && !line.StartsWith('#') && !line.Contains("token", StringComparison.OrdinalIgnoreCase)) + .ToList(); + foreach (var line in lines) + { + reporter.Plain($" {line}"); } - reporter.Plain("1. portal-modules (built-in)"); - reporter.Plain("global-credential-providers: (none)"); - return 0; + return lines.Count > 0; } private int WhatRan(bool failedOnly)