瀏覽代碼

qfu: add ncount to clone operation. updates readme.md

Dalibor Votruba 1 年之前
父節點
當前提交
70cdeead48
共有 5 個文件被更改,包括 59 次插入7 次删除
  1. 1 1
      qfu/Commands/Aspects/FilesAspect.cs
  2. 37 1
      qfu/Commands/CloneCmd.cs
  3. 4 0
      qfu/Properties/launchSettings.json
  4. 1 1
      qfu/qfu.csproj
  5. 16 4
      qfu/readme.md

+ 1 - 1
qfu/Commands/Aspects/FilesAspect.cs

@@ -9,7 +9,7 @@ namespace qdr.app.tools.qfu.Commands.Aspects
     {
         #region *** Constants ***
         private const string ARG_FILES_SEP = "|";
-        private const string ARG_FILES_NAME = "files";
+        public const string ARG_FILES_NAME = "files";
         private const string ARG_FILES_HINT = "files";
         private const string ARG_FILES_DESCR = "One or more files separated by character pipe (" + ARG_FILES_SEP + ")";
         private const int ARG_SRC_ORD = 1;

+ 37 - 1
qfu/Commands/CloneCmd.cs

@@ -13,6 +13,10 @@ namespace qdr.app.tools.qfu.Commands
         #region *** Constants ***
         private const string CMD_NAME = "clone";
         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
 
         #region *** Properties ***
@@ -22,6 +26,8 @@ namespace qdr.app.tools.qfu.Commands
         protected string[] TargetFiles { get; private set; } = Array.Empty<string>();
         protected bool IsEnsurePath { get; private set; } = false;
         protected bool IsForce { get; private set; } = false;
+        protected int? CloneCount{ get; private set; }
+      
         #endregion
 
         #region *** Constructors ***
@@ -73,9 +79,21 @@ namespace qdr.app.tools.qfu.Commands
         #region **** Arguments ****
         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();
             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);
             IsForce = GetArgumentValueOrDefault<bool>(ForceAspect.ARG_FORCE_NAME, false);
         }
@@ -83,12 +101,30 @@ namespace qdr.app.tools.qfu.Commands
         protected override IEnumerable<AbstractArgument> OnSetupArguments()
         {
             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(FilesAspect.SetupArguments());
             list.AddRange(ForceAspect.SetupArguments());
             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
     }

+ 4 - 0
qfu/Properties/launchSettings.json

@@ -10,6 +10,10 @@
     "qfu clone": {
       "commandName": "Project",
       "commandLineArgs": "clone test.dat \"test01.dat\"|\"test02.dat\"|\"test03.dat\""
+    },
+    "qfu clon n": {
+      "commandName": "Project",
+      "commandLineArgs": "clone test.dat \"test01.dat\"|\"test02.dat\"|\"test03.dat\" -n:10 -force"
     }
   }
 }

+ 1 - 1
qfu/qfu.csproj

@@ -34,6 +34,6 @@
     </None>
   </ItemGroup>
 	<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Debug'">
-		<Exec Command="if not exist $(OutDir)test.dat fsutil file createnew $(OutDir)test.dat 100048576" />
+		<Exec Command="if not exist $(OutDir)test.dat fsutil file createnew $(OutDir)test.dat 148576" />
 	</Target>
 </Project>

+ 16 - 4
qfu/readme.md

@@ -9,7 +9,8 @@ QFU is a powerful filesystem utility that provides efficient file operations thr
 ### Key Features
 
 - **File Cloning**: Clone source files to multiple destinations with various options
-- **Flexible Input Methods**: Support for direct file specification or file list input
+- **Auto-Generation**: Automatically generate multiple copies with sequential naming using count parameter
+- **Flexible Input Methods**: Support for direct file specification, auto-generation, or file list input
 - **Path Management**: Automatic directory creation when needed
 - **Force Operations**: Override existing files when necessary
 - **Robust Error Handling**: Comprehensive validation and error reporting
@@ -57,13 +58,15 @@ Clone a source file to one or more destination files.
 **Syntax:**
 ```
 qfu clone <source_file> <target_files> [options]
+qfu clone <source_file> -n <count> [options]
 ```
 
 **Arguments:**
 - `source_file`: Path to the source file to clone
-- `target_files`: Pipe-separated list of target file paths (`file1.txt|file2.txt|file3.txt`)
+- `target_files`: Pipe-separated list of target file paths (`file1.txt|file2.txt|file3.txt`) - ignored when using `-n`
 
 **Options:**
+- `-n <count>`: Generate the specified number of files automatically with sequential naming (e.g., `file_1.ext`, `file_2.ext`)
 - `-pe` or `-path_ensure`: Create destination directories if they don't exist
 - `-force`: Overwrite existing destination files
 - `-list`: Treat the first target file as a text file containing a list of destination paths (one per line)
@@ -99,9 +102,18 @@ echo "backup/file3.txt" >> targets.txt
 qfu clone source.txt targets.txt -list -pe
 ```
 
+#### Auto-Generate Multiple Files
+```bash
+# Generate 5 copies with sequential naming (source_1.txt, source_2.txt, etc.)
+qfu clone source.txt -n 5
+
+# Generate 3 copies with force and path creation
+qfu clone template.config -n 3 -force -pe
+```
+
 #### Complex Example
 ```bash
-# Clone with all options
+# Clone with all options (manual file specification)
 qfu clone template.cs "src/Class1.cs|src/Class2.cs|tests/TestClass.cs" -force -pe
 ```
 
@@ -132,7 +144,7 @@ Successfully cloned: 2 of 3 files.
 QFU provides comprehensive error handling:
 
 - **Source Validation**: Verifies source file exists before operation
-- **Destination Validation**: Checks for existing files (unless `--force` used)
+- **Destination Validation**: Checks for existing files (unless `-force` used)
 - **Path Validation**: Ensures destination paths are valid
 - **Permission Checking**: Reports access denied errors
 - **List File Validation**: Validates list files when using `-list` option