4 Commits f949a9acd2 ... 3a9bc8845a

Author SHA1 Message Date
  Piotr Czajkowski 3a9bc8845a Package 3 months ago
  Piotr Czajkowski 6d35ec03e8 Cosmetics 3 months ago
  Piotr Czajkowski 552b10ddf6 Merge pull request #2 from pczajkowski-ptw/master 1 year ago
  Piotr Czajkowski 3172f30f6c User should know which file has caused exception 1 year ago

+ 15 - 20
ProcessFiles/ProcessFiles.cs

@@ -14,7 +14,7 @@ namespace ProcessFiles
 
     public static class ProcessFiles
     {
-        private static List<string> _errors = new();
+        private static List<string> errors = new();
 
         private static Result WhatIsIt(string path)
         {
@@ -28,21 +28,18 @@ namespace ProcessFiles
             }
             catch (Exception e)
             {
-                _errors.Add(e.ToString());
+                errors.Add(e.ToString());
                 return Result.Failure;
             }
         }
 
         private static string? GetExtension(string path)
         {
-            var extension = Path.GetExtension(path)?.TrimStart('.');
-            if (string.IsNullOrWhiteSpace(extension))
-            {
-                _errors.Add($"Can't establish extension of {path}!");
-                return null;
-            }
-
-            return extension;
+            var extension = Path.GetExtension(path).TrimStart('.');
+            if (!string.IsNullOrWhiteSpace(extension)) return extension;
+            
+            errors.Add($"Can't establish extension of {path}!");
+            return null;
         }
 
         private static bool CheckExtension(string extension, string[] validExtensions)
@@ -60,7 +57,7 @@ namespace ProcessFiles
         {
             if (!File.Exists(path))
             {
-                _errors.Add($"{path} doesn't exist!");
+                errors.Add($"{path} doesn't exist!");
                 return false;
             }
 
@@ -70,7 +67,7 @@ namespace ProcessFiles
 
             if (!CheckExtension(extension, fileExtensions))
             {
-                _errors.Add($"Extension of {path} doesn't match any extension ({string.Join(", ", fileExtensions)})!");
+                errors.Add($"Extension of {path} doesn't match any extension ({string.Join(", ", fileExtensions)})!");
                 return false;
             }
 
@@ -85,7 +82,7 @@ namespace ProcessFiles
             }
             catch (Exception e)
             {
-                _errors.Add(e.ToString());
+                errors.Add($"{path}:\n{e}");
             }
         }
 
@@ -101,7 +98,7 @@ namespace ProcessFiles
         {
             if (!Directory.Exists(path))
             {
-                _errors.Add($"{path} doesn't exist!");
+                errors.Add($"{path} doesn't exist!");
                 return;
             }
 
@@ -119,7 +116,7 @@ namespace ProcessFiles
 
             if (!files.Any())
             {
-                _errors.Add($"There are no files in {path} with given extensions ({string.Join(", ", fileExtensions)})!");
+                errors.Add($"There are no files in {path} with given extensions ({string.Join(", ", fileExtensions)})!");
                 return;
             }
 
@@ -129,12 +126,12 @@ namespace ProcessFiles
 
         public static IEnumerable<string> Process(IEnumerable<string> arguments, string fileExtension, Action<string> action, bool recursive = false)
         {
-            return Process(arguments, new string[] {fileExtension}, action, recursive);
+            return Process(arguments, new[] {fileExtension}, action, recursive);
         }
 
         public static IEnumerable<string> Process(IEnumerable<string> arguments, string[] fileExtensions, Action<string> action, bool recursive = false)
         {
-            _errors = new List<string>();
+            errors = new List<string>();
 
             foreach (var argument in arguments)
             {
@@ -148,12 +145,10 @@ namespace ProcessFiles
                         break;
                     case Result.Failure:
                         continue;
-                    default:
-                        break;
                 }
             }
 
-            return _errors;
+            return errors;
         }
     }
 }

+ 18 - 4
ProcessFiles/ProcessFiles.csproj

@@ -1,8 +1,22 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
-  <PropertyGroup>
-    <TargetFrameworks>net6</TargetFrameworks>
-    <Nullable>enable</Nullable>
-  </PropertyGroup>
+	<PropertyGroup>
+		<Nullable>enable</Nullable>
+		<TargetFramework>net6.0</TargetFramework>
+		<Version>0.1.0</Version>
+		<Title>ProcessFiles</Title>
+		<Authors>Piotr Czajkowski</Authors>
+		<Description>Easily process files from command line arguments</Description>
+		<PackageProjectUrl>https://git.liox.eu/pczajkowski/ProcessFiles</PackageProjectUrl>
+		<RepositoryUrl>https://github.com/pczajkowski/ProcessFiles</RepositoryUrl>
+		<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
+		<PackageReadmeFile>README.md</PackageReadmeFile>
+		<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
+		<RepositoryType>GitHub</RepositoryType>
+	</PropertyGroup>
 
+	<ItemGroup>
+		<None Include="../README.md" Pack="true" PackagePath=""/>
+		<None Include="../LICENSE.md" Pack="true" PackagePath=""/>
+	</ItemGroup>
 </Project>

+ 1 - 1
ProcessFilesTests/ProcessFilesTests.cs

@@ -135,7 +135,7 @@ namespace ProcessFilesTests
                 result.Add(Path.GetFileName(value));
             }
 
-            var errors = ProcessFiles.ProcessFiles.Process(new[] { testFolder }, new string[] { "txt", "json" }, TestAction, true);
+            var errors = ProcessFiles.ProcessFiles.Process(new[] { testFolder }, new[] { "txt", "json" }, TestAction, true);
             Assert.Empty(errors);
             Assert.True(CheckResult(result, expectedInSubFolderMultipleExtensions));
         }

+ 2 - 0
ProcessFilesTests/ProcessFilesTests.csproj

@@ -4,6 +4,8 @@
     <TargetFramework>net6.0</TargetFramework>
 
     <IsPackable>false</IsPackable>
+
+    <OutputType>Library</OutputType>
   </PropertyGroup>
 
   <ItemGroup>