| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using Quadarax.Foundation.Core.QConsole.Argument;
- using Quadarax.Foundation.Core.QConsole.Command.Base;
- namespace qdr.app.tools.qfu.Commands.Aspects
- {
- internal class FilterAspect
- {
- #region *** Constants ***
- private const string ARG_FILTER_SEP = "|";
- public const string ARG_FILTER_NAME = "f";
- private const string ARG_FILTER_HINT = "filter";
- private const string ARG_FILTER_DESCR = "Search pattern for files or directories to delete (separated by pipe " + ARG_FILTER_SEP + "). Example: *.txt|*.log|temp*";
- #endregion
- #region *** Public Operations ***
- public static IEnumerable<AbstractArgument> SetupArguments()
- {
- return
- [
- new NamedArgument(ARG_FILTER_NAME, ARG_FILTER_DESCR, ARG_FILTER_HINT, Quadarax.Foundation.Core.QConsole.Value.TypeValuesEnum.String, string.Empty, false)
- ];
- }
- public static string[] GetSearchPatterns(AbstractCommand context)
- {
- if (context == null)
- throw new ArgumentNullException(nameof(context), "Command context cannot be null.");
- var filterArgument = context.Arguments.FirstOrDefault(x => string.Equals(x.Code, ARG_FILTER_NAME));
- if (filterArgument?.Value.Get() == null)
- return ["*"]; // Default pattern - match all
- var filterValue = filterArgument.Value.Get()?.ToString();
- if (string.IsNullOrWhiteSpace(filterValue))
- return ["*"]; // Default pattern - match all
- return ParseSearchPatterns(filterValue);
- }
- public static string[] ParseSearchPatterns(string filterArgument)
- {
- if (string.IsNullOrWhiteSpace(filterArgument))
- return ["*"];
- return filterArgument.Split(new[] { ARG_FILTER_SEP }, StringSplitOptions.RemoveEmptyEntries)
- .Select(f => f.Trim())
- .Where(f => !string.IsNullOrEmpty(f))
- .ToArray();
- }
- #endregion
- }
- }
|