using Quadarax.Foundation.Core.QConsole.Argument; using Quadarax.Foundation.Core.QConsole.Command.Base; namespace qdr.app.tools.qfu.Commands.Aspects { internal class ExcludeAspect { #region *** Constants *** private const string ARG_EXCLUDE_SEP = "|"; public const string ARG_EXCLUDE_NAME = "exclude"; private const string ARG_EXCLUDE_HINT = "exclude"; private const string ARG_EXCLUDE_DESCR = "One or more files or search patterns to exclude separated by character pipe (" + ARG_EXCLUDE_SEP + "). Example: *.tmp|temp*|backup.jpg"; #endregion #region *** Public Operations *** public static IEnumerable SetupArguments() { return [ new NamedArgument(ARG_EXCLUDE_NAME, ARG_EXCLUDE_DESCR, ARG_EXCLUDE_HINT, Quadarax.Foundation.Core.QConsole.Value.TypeValuesEnum.String, string.Empty, false) ]; } public static string[] GetExcludePatterns(AbstractCommand context) { if (context == null) throw new ArgumentNullException(nameof(context), "Command context cannot be null."); var excludeArgument = context.Arguments.FirstOrDefault(x => string.Equals(x.Code, ARG_EXCLUDE_NAME)); if (excludeArgument?.Value.Get() == null) return Array.Empty(); // No exclude patterns var excludeValue = excludeArgument.Value.Get()?.ToString(); if (string.IsNullOrWhiteSpace(excludeValue)) return Array.Empty(); // No exclude patterns return ParseExcludePatterns(excludeValue); } public static string[] ParseExcludePatterns(string excludeArgument) { if (string.IsNullOrWhiteSpace(excludeArgument)) return Array.Empty(); return excludeArgument.Split(new[] { ARG_EXCLUDE_SEP }, StringSplitOptions.RemoveEmptyEntries) .Select(f => f.Trim()) .Where(f => !string.IsNullOrEmpty(f)) .ToArray(); } #endregion } }