ExcludeAspect.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Quadarax.Foundation.Core.QConsole.Argument;
  2. using Quadarax.Foundation.Core.QConsole.Command.Base;
  3. namespace qdr.app.tools.qfu.Commands.Aspects
  4. {
  5. internal class ExcludeAspect
  6. {
  7. #region *** Constants ***
  8. private const string ARG_EXCLUDE_SEP = "|";
  9. public const string ARG_EXCLUDE_NAME = "exclude";
  10. private const string ARG_EXCLUDE_HINT = "exclude";
  11. 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";
  12. #endregion
  13. #region *** Public Operations ***
  14. public static IEnumerable<AbstractArgument> SetupArguments()
  15. {
  16. return
  17. [
  18. new NamedArgument(ARG_EXCLUDE_NAME, ARG_EXCLUDE_DESCR, ARG_EXCLUDE_HINT, Quadarax.Foundation.Core.QConsole.Value.TypeValuesEnum.String, string.Empty, false)
  19. ];
  20. }
  21. public static string[] GetExcludePatterns(AbstractCommand context)
  22. {
  23. if (context == null)
  24. throw new ArgumentNullException(nameof(context), "Command context cannot be null.");
  25. var excludeArgument = context.Arguments.FirstOrDefault(x => string.Equals(x.Code, ARG_EXCLUDE_NAME));
  26. if (excludeArgument?.Value.Get() == null)
  27. return Array.Empty<string>(); // No exclude patterns
  28. var excludeValue = excludeArgument.Value.Get()?.ToString();
  29. if (string.IsNullOrWhiteSpace(excludeValue))
  30. return Array.Empty<string>(); // No exclude patterns
  31. return ParseExcludePatterns(excludeValue);
  32. }
  33. public static string[] ParseExcludePatterns(string excludeArgument)
  34. {
  35. if (string.IsNullOrWhiteSpace(excludeArgument))
  36. return Array.Empty<string>();
  37. return excludeArgument.Split(new[] { ARG_EXCLUDE_SEP }, StringSplitOptions.RemoveEmptyEntries)
  38. .Select(f => f.Trim())
  39. .Where(f => !string.IsNullOrEmpty(f))
  40. .ToArray();
  41. }
  42. #endregion
  43. }
  44. }