From 6bfb58fbefab918b3fe5ada8b212bc9ab7228aff Mon Sep 17 00:00:00 2001 From: Daniel-iel Date: Fri, 17 May 2024 08:09:34 -0300 Subject: [PATCH] =?UTF-8?q?Corrigindo=20os=20testes=20que=20n=C3=A3o=20est?= =?UTF-8?q?avam=20rodando=20no=20linux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 83 +++++++++++++++++-- .../Analyzers/AnalyzerRunnerTest.cs | 25 +++--- .../Models/BrConfigurationTest.cs | 6 +- src/ByReplace/Analyzers/AnalyzerRunner.cs | 6 +- src/ByReplace/ByReplace.csproj | 4 +- src/ByReplace/Common/PathFixer.cs | 49 +++++++++++ src/ByReplace/Models/BrConfiguration.cs | 8 +- src/Dockerfile | 11 +-- 8 files changed, 161 insertions(+), 31 deletions(-) create mode 100644 src/ByReplace/Common/PathFixer.cs diff --git a/README.md b/README.md index ff17ae4..3f1b17c 100644 --- a/README.md +++ b/README.md @@ -14,20 +14,91 @@ # About -Coming soon! +ByReplace is a powerful command-line interface (CLI) tool designed for efficiently executing find-and-replace operations within source files. This versatile utility enables users to seamlessly modify text within their codebase, enhancing productivity and streamlining development processes. Whether you're updating variable names, correcting typos, or implementing sweeping changes across multiple files. # Get Started -Coming soon! +[Dotnet 8](https://dotnet.microsoft.com/en-us/download) is required to run ByReplace. +After installing the NuGet package, navigate to your terminal and execute the command `br -v`. If the installation was successful, the following text will be displayed in your terminal. + +```shell +br + +Commands: + apply apply commands + rule rule commands + +Options: + -h, --help Show help message + --version Show version +``` ## Install -Coming soon! +ByReplace tool is delivery by [nuget](https://www.nuget.org/packages/ByReplace). + +```shell +dotnet install -g ByReplace +``` + +## How Create the Configuration File -## How create brconfig file +```shell +{ + "Path": "", + "SkipDirectories": [ "" ], + "Rules": [ + { + "Name": "", + "Description": "", + "Skip": [ "", "" ], + "Extensions": [ "", "" ], + "Replacement": { + "Old": [ "", "" ], + "New": "" + } + } + ] +} +``` -Coming soon! +### Path + +### SkipDirectories + +### Rules ## Commands -Coming soon! +### Apply + +`br apply rule`: Is used to execute only one rule from brConfiguration file. + +- `-r`: rule's name. +- `-p`: path of files to execute the apply. +- `-f`: folder's path that constains the brConfiguration file. + +```shell +br apply rule -r "Rule" -p "C:/{three files" -f "C:" +``` + +`br apply rules`: Is used to execute all rules rule from brConfiguration file. + +- `-p`: path of files to execute the apply. +- `-f`: folder's path that constains the brConfiguration file. + +```shell +br apply rules -p "C:/{three files" -f "C:" +``` + +### Rule + +`br rule list-rules` + +```shell +``` + +`br rule open-rule` + +```shell +``` diff --git a/src/ByReplace.Test/Analyzers/AnalyzerRunnerTest.cs b/src/ByReplace.Test/Analyzers/AnalyzerRunnerTest.cs index 55c70f3..010cf46 100644 --- a/src/ByReplace.Test/Analyzers/AnalyzerRunnerTest.cs +++ b/src/ByReplace.Test/Analyzers/AnalyzerRunnerTest.cs @@ -84,6 +84,19 @@ public void RunAnalysis_MapAllRulesThatMatchToFileInSourceTree_ShouldReturnRules Assert.Equal(4, analyzersAndFixers.Count); Assert.Collection(analyzersAndFixers, + entry => + { + Assert.Equal("bin2.txt", entry.Key.Name); + Assert.Equal(".txt", entry.Key.Extension); + Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name)); + }, + entry => + { + Assert.Equal("obj1.txt", entry.Key.Name); + Assert.Equal(".txt", entry.Key.Extension); + Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name)); + }, + entry => { Assert.Equal("RootFile1.cs", entry.Key.Name); @@ -95,18 +108,6 @@ public void RunAnalysis_MapAllRulesThatMatchToFileInSourceTree_ShouldReturnRules Assert.Equal("RootFile2.cs", entry.Key.Name); Assert.Equal(".cs", entry.Key.Extension); Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name)); - }, - entry => - { - Assert.Equal("bin2.txt", entry.Key.Name); - Assert.Equal(".txt", entry.Key.Extension); - Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name)); - }, - entry => - { - Assert.Equal("obj1.txt", entry.Key.Name); - Assert.Equal(".txt", entry.Key.Extension); - Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name)); }); } diff --git a/src/ByReplace.Test/Models/BrConfigurationTest.cs b/src/ByReplace.Test/Models/BrConfigurationTest.cs index e24b2c8..5f3451e 100644 --- a/src/ByReplace.Test/Models/BrConfigurationTest.cs +++ b/src/ByReplace.Test/Models/BrConfigurationTest.cs @@ -76,13 +76,13 @@ public void SetOnlyOneRule_WhenSetNewRule_ShouldReplaceOldRulesWithTheNewOne() public void ChangeDefaultPath_WhenChangePathToAPathThatExists_ShouldReplaceTheValueOfPath() { // Arrange - var config = new BrConfiguration("C://ByReplace", ["**//Controllers/*"], []); + var config = new BrConfiguration("./ByReplace", ["**//Controllers/*"], []); // Act - config.ChangeDefaultPath("C:"); + config.ChangeDefaultPath("./"); // Assert - Assert.Equal("C:", config.Path); + Assert.Equal("./", config.Path); } [Fact] diff --git a/src/ByReplace/Analyzers/AnalyzerRunner.cs b/src/ByReplace/Analyzers/AnalyzerRunner.cs index 1fda79b..55433b5 100644 --- a/src/ByReplace/Analyzers/AnalyzerRunner.cs +++ b/src/ByReplace/Analyzers/AnalyzerRunner.cs @@ -24,6 +24,10 @@ internal AnalyzerAndFixer RunAnalysis(ImmutableList directoryThre analyzersAndFixers.TryMatchRule(dir, brConfiguration.Rules); } - return analyzersAndFixers; + return new AnalyzerAndFixer( + analyzersAndFixers + .OrderBy(x => x.Key.FullName) + .ToDictionary(x => x.Key, x => x.Value), print); + } } diff --git a/src/ByReplace/ByReplace.csproj b/src/ByReplace/ByReplace.csproj index e79fdc3..bf9e274 100644 --- a/src/ByReplace/ByReplace.csproj +++ b/src/ByReplace/ByReplace.csproj @@ -15,8 +15,8 @@ LICENSE $(MSBuildProjectName) CLI to help developer to do bulk replace using shared configuration. - Daniel-iel - Daniel-iel + Daniel Oliveira + Daniel Oliveira br ./nupkg true diff --git a/src/ByReplace/Common/PathFixer.cs b/src/ByReplace/Common/PathFixer.cs new file mode 100644 index 0000000..14c44d7 --- /dev/null +++ b/src/ByReplace/Common/PathFixer.cs @@ -0,0 +1,49 @@ +using System.Runtime.InteropServices; + +namespace ByReplace.Common; + +internal class PathFixer +{ + public string OS + { + get + { + return Environment.OSVersion.ToString(); + } + } + + public string GetFixedPath(params string[] parts) + { + IPathFixer linux = new PathFixerLinux(); + IPathFixer windows = new PathFixerLinux(); + + return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) + ? linux.PathFixed(parts) + : windows.PathFixed(parts); + } +} + +internal interface IPathFixer +{ + string PathFixed(params string[] parts); +} + +internal class PathFixerWindowns : IPathFixer +{ + public string PathFixed(params string[] parts) + { + return string + .Join('\\', parts) + .Trim(); + } +} + +internal class PathFixerLinux : IPathFixer +{ + public string PathFixed(params string[] parts) + { + return string + .Join('/', parts) + .Trim(); + } +} \ No newline at end of file diff --git a/src/ByReplace/Models/BrConfiguration.cs b/src/ByReplace/Models/BrConfiguration.cs index e567dc0..0dbcdaa 100644 --- a/src/ByReplace/Models/BrConfiguration.cs +++ b/src/ByReplace/Models/BrConfiguration.cs @@ -1,4 +1,6 @@ -[assembly: InternalsVisibleTo("ByReplace.Test")] +using ByReplace.Common; + +[assembly: InternalsVisibleTo("ByReplace.Test")] namespace ByReplace.Models; @@ -34,7 +36,9 @@ public void ChangeDefaultPath(string path) public static BrConfiguration GetConfiguration(string pathConfig) { - string configurationFilePath = Sanitizer(string.Join(@"\", pathConfig, "brconfig.json")); + PathFixer path = new PathFixer(); + + string configurationFilePath = path.GetFixedPath(pathConfig, "brconfig.json"); if (!File.Exists(configurationFilePath)) { diff --git a/src/Dockerfile b/src/Dockerfile index 1db747f..dcf792e 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -5,8 +5,9 @@ RUN dotnet restore ByReplace.sln RUN dotnet build ByReplace.sln -c Release -o /app RUN dotnet test ByReplace.sln -# # Build runtime image -# FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime -# WORKDIR /app -# COPY --from=build /app . -# ENTRYPOINT ["dotnet", "ByReplace.dll"] +# Build runtime image +#FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime +#WORKDIR /app +#COPY --from=build /app . +#ENTRYPOINT ["dotnet", "ByReplace.dll"] +# \ No newline at end of file