| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 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<AbstractArgument> 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<string>(); // No exclude patterns
- var excludeValue = excludeArgument.Value.Get()?.ToString();
- if (string.IsNullOrWhiteSpace(excludeValue))
- return Array.Empty<string>(); // No exclude patterns
- return ParseExcludePatterns(excludeValue);
- }
- public static string[] ParseExcludePatterns(string excludeArgument)
- {
- if (string.IsNullOrWhiteSpace(excludeArgument))
- return Array.Empty<string>();
- return excludeArgument.Split(new[] { ARG_EXCLUDE_SEP }, StringSplitOptions.RemoveEmptyEntries)
- .Select(f => f.Trim())
- .Where(f => !string.IsNullOrEmpty(f))
- .ToArray();
- }
- #endregion
- }
- }
|