| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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<QfuCommandContext>().FileSystem;
- #endregion
- #region *** Constructors ***
- protected BaseCmd(Engine engine) : base(engine)
- {
- }
- #endregion
- #region *** Protected Operations ***
- protected string ArgumentAsFileName(string argumentName)
- {
- var fileName = GetArgumentValueOrDefault<string>(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<AbstractArgument> 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
- }
- }
|