using MaksIT.Core.Comb; namespace MaksIT.Core.Cli; /// /// Parses interactive menu input for the Core CLI. /// public static class InputParsers { /// /// Parses a positive integer, using when input is blank. /// public static bool TryParsePositiveInt( string? input, int defaultValue, out int value, out string? errorMessage ) { if (string.IsNullOrWhiteSpace(input)) { value = defaultValue; errorMessage = null; return true; } if (!int.TryParse(input.Trim(), out value) || value <= 0) { value = 0; errorMessage = "Value must be a positive integer."; return false; } errorMessage = null; return true; } /// /// Parses a COMB GUID type, defaulting to when input is blank. /// public static bool TryParseCombGuidType( string? input, out CombGuidType type, out string? errorMessage ) { if (string.IsNullOrWhiteSpace(input)) { type = CombGuidType.PostgreSql; errorMessage = null; return true; } if (Enum.TryParse(input.Trim(), ignoreCase: true, out type) && Enum.IsDefined(type)) { errorMessage = null; return true; } type = default; errorMessage = "Type must be PostgreSql or SqlServer."; return false; } /// /// Splits a comma-separated list; returns null when input is blank. /// public static List? ParseOptionalList(string? input) { if (string.IsNullOrWhiteSpace(input)) return null; var items = input .Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) .ToList(); if (items.Count == 0) return null; return items; } }