|
@@ -13,6 +13,10 @@ namespace qdr.app.tools.qfu.Commands
|
|
|
#region *** Constants ***
|
|
#region *** Constants ***
|
|
|
private const string CMD_NAME = "clone";
|
|
private const string CMD_NAME = "clone";
|
|
|
private const string CMD_DESCR = "Clone source file to files specified.";
|
|
private const string CMD_DESCR = "Clone source file to files specified.";
|
|
|
|
|
+
|
|
|
|
|
+ private const string ARG_N_NAME = "n";
|
|
|
|
|
+ private const string ARG_N_HINT = "ncount";
|
|
|
|
|
+ private const string ARG_N_DESCR = "Numeric value how many <{0}> files will be generated. If used, then files in <{1}> arguments will be ignored.";
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region *** Properties ***
|
|
#region *** Properties ***
|
|
@@ -22,6 +26,8 @@ namespace qdr.app.tools.qfu.Commands
|
|
|
protected string[] TargetFiles { get; private set; } = Array.Empty<string>();
|
|
protected string[] TargetFiles { get; private set; } = Array.Empty<string>();
|
|
|
protected bool IsEnsurePath { get; private set; } = false;
|
|
protected bool IsEnsurePath { get; private set; } = false;
|
|
|
protected bool IsForce { get; private set; } = false;
|
|
protected bool IsForce { get; private set; } = false;
|
|
|
|
|
+ protected int? CloneCount{ get; private set; }
|
|
|
|
|
+
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region *** Constructors ***
|
|
#region *** Constructors ***
|
|
@@ -73,9 +79,21 @@ namespace qdr.app.tools.qfu.Commands
|
|
|
#region **** Arguments ****
|
|
#region **** Arguments ****
|
|
|
protected override void OnValidateArguments()
|
|
protected override void OnValidateArguments()
|
|
|
{
|
|
{
|
|
|
|
|
+ if(WasArgumentSpecified(ARG_N_NAME))
|
|
|
|
|
+ {
|
|
|
|
|
+ // count argument is set -> fake argument to ensure that files are not used
|
|
|
|
|
+ var argTaget = GetArgument(FilesAspect.ARG_FILES_NAME);
|
|
|
|
|
+ argTaget.Value.Set("file");
|
|
|
|
|
+ }
|
|
|
base.OnValidateArguments();
|
|
base.OnValidateArguments();
|
|
|
CheckSourceFileExists();
|
|
CheckSourceFileExists();
|
|
|
- TargetFiles = ListAspect.GetFiles(this, FileSystem, FilesAspect.GetFiles(this, FileSystem, false));
|
|
|
|
|
|
|
+ if(WasArgumentSpecified(ARG_N_NAME))
|
|
|
|
|
+ {
|
|
|
|
|
+ CloneCount = GetArgumentValueOrDefault<int>(ARG_N_NAME, 0);
|
|
|
|
|
+ TargetFiles = GenerateTargetFiles(CloneCount.Value);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ TargetFiles = ListAspect.GetFiles(this, FileSystem, FilesAspect.GetFiles(this, FileSystem, false));
|
|
|
IsEnsurePath = GetArgumentValueOrDefault<bool>(FilesAspect.ARG_PATHENS_NAME, false);
|
|
IsEnsurePath = GetArgumentValueOrDefault<bool>(FilesAspect.ARG_PATHENS_NAME, false);
|
|
|
IsForce = GetArgumentValueOrDefault<bool>(ForceAspect.ARG_FORCE_NAME, false);
|
|
IsForce = GetArgumentValueOrDefault<bool>(ForceAspect.ARG_FORCE_NAME, false);
|
|
|
}
|
|
}
|
|
@@ -83,12 +101,30 @@ namespace qdr.app.tools.qfu.Commands
|
|
|
protected override IEnumerable<AbstractArgument> OnSetupArguments()
|
|
protected override IEnumerable<AbstractArgument> OnSetupArguments()
|
|
|
{
|
|
{
|
|
|
var list = base.OnSetupArguments().ToList();
|
|
var list = base.OnSetupArguments().ToList();
|
|
|
|
|
+ list.Add(new NamedArgument(ARG_N_NAME, ARG_N_DESCR, ARG_N_HINT,Quadarax.Foundation.Core.QConsole.Value.TypeValuesEnum.Integer, "0",false));
|
|
|
list.AddRange(ListAspect.SetupArguments());
|
|
list.AddRange(ListAspect.SetupArguments());
|
|
|
list.AddRange(FilesAspect.SetupArguments());
|
|
list.AddRange(FilesAspect.SetupArguments());
|
|
|
list.AddRange(ForceAspect.SetupArguments());
|
|
list.AddRange(ForceAspect.SetupArguments());
|
|
|
return list;
|
|
return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
|
|
+ #region **** Private Operations ****
|
|
|
|
|
+ private string[] GenerateTargetFiles(int count)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (count <= 0)
|
|
|
|
|
+ throw new ArgumentException("Count must be greater than zero.", nameof(count));
|
|
|
|
|
+ var fileName = Path.GetFileNameWithoutExtension(Source);
|
|
|
|
|
+ var fileExt = Path.GetExtension(Source);
|
|
|
|
|
+ var directory = Path.GetDirectoryName(Source) ?? string.Empty;
|
|
|
|
|
+ var files = new string[count];
|
|
|
|
|
+ for (int i = 0; i < count; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ files[i] = Path.Combine(directory, $"{fileName}_{i + 1}{fileExt}");
|
|
|
|
|
+ }
|
|
|
|
|
+ return files;
|
|
|
|
|
+ }
|
|
|
#endregion
|
|
#endregion
|
|
|
#endregion
|
|
#endregion
|
|
|
}
|
|
}
|