using qdr.app.tools.qfu.Commands.Aspects; using Quadarax.Foundation.Core.QConsole; using Quadarax.Foundation.Core.QConsole.Argument; using Quadarax.Foundation.Core.QConsole.Command.Base; using System.IO.Abstractions; namespace qdr.app.tools.qfu.Commands { abstract class BaseCmd : AbstractCommand { #region *** Properties *** protected string Source { get; private set; } = string.Empty; protected IFileSystem FileSystem => GetContext().FileSystem; #endregion #region *** Constructors *** protected BaseCmd(Engine engine) : base(engine) { } #endregion #region *** Protected Operations *** protected string ArgumentAsFileName(string argumentName) { var fileName = GetArgumentValueOrDefault(argumentName); if (string.IsNullOrEmpty(fileName)) throw new ArgumentException($"Argument '{argumentName}' is not defined or empty.", argumentName); return fileName; } protected void CheckSourceFileExists() { if (!FileSystem.File.Exists(Source)) throw new ArgumentException($"Source file '{Source}' does not exist.", SourceAspect.ARG_SRC_NAME); } #endregion #region *** Overrides *** protected override IEnumerable OnSetupArguments() { var list = base.OnSetupArguments().ToList(); list.AddRange(SourceAspect.SetupArguments()); return list; } protected override void OnValidateArguments() { base.OnValidateArguments(); Source = ArgumentAsFileName(SourceAspect.ARG_SRC_NAME); } #endregion } }