diff --git a/Main.cs b/Program.cs similarity index 58% rename from Main.cs rename to Program.cs index 972a0fc..27d0ec6 100644 --- a/Main.cs +++ b/Program.cs @@ -8,15 +8,7 @@ void ProcessDirectory(string baseDir) { var fs = Path.Combine(baseDir, subDir); if (File.Exists(fs)) { - if (Path.GetFileName(fs) == "BUILD") - { - Console.WriteLine(); - Console.WriteLine(fs); - Console.WriteLine("======== ======== ======== ======== ======== ======== ======== ========"); - FormatBuildFile(fs); - Console.WriteLine("======== ======== ======== ======== ======== ======== ======== ========"); - Console.WriteLine(); - } + if (Path.GetFileName(fs) == "BUILD") FormatBuildFile(fs); } else if (Directory.Exists(fs)) { @@ -30,11 +22,10 @@ void FormatBuildFile(string filename) var oldcontent = File.ReadAllText(filename); var newcontent = FormatFile(filename, oldcontent); - if (oldcontent != newcontent) - { - //File.WriteAllText(filename, newcontent); - Console.WriteLine("Auto-Formatted file :: " + filename); - } + if (oldcontent == newcontent) return; + + File.WriteAllText(filename, newcontent); + Console.WriteLine("Auto-Formatted file :: " + filename); } string FormatFile(string filename, string content) @@ -52,15 +43,7 @@ string FormatFile(string filename, string content) var newDeps = FormatDeps(filename, linenum, oldDeps); - if (oldDeps != newDeps) - { - Console.WriteLine("+++++++++++++ OLD +++++++++++++++++"); - Console.WriteLine(oldDeps); - Console.WriteLine("++++++++++++++ NEW ++++++++++++++++"); - Console.WriteLine(newDeps); - Console.WriteLine("++++++++++++++++++++++++++++++"); - Console.WriteLine(); - } + if (oldDeps != newDeps) content = content.Replace(oldDeps, newDeps); } return content; @@ -90,7 +73,7 @@ string FormatDeps(string filename, int linenum, string deps) return result; } -(int group, string clean, string raw) GetDepGroup(string filename, int linenum, string value) +(int group, string sgroup, string clean, string raw) GetDepGroup(string filename, int linenum, string value) { var v = value.Trim(); @@ -101,16 +84,38 @@ string FormatDeps(string filename, int linenum, string deps) if (rowA) { - v = v.Substring(1, v.Length - 4); + v = v.Substring(1, v.Length - 3); } else if (rowB) { - v = v.Substring(1, v.Length - 3); + v = v.Substring(1, v.Length - 2); } v = v.Trim(); + + if (v.StartsWith(":")) return (100, "local", v, value); + + if (v.StartsWith("//common")) return (200, "common", v, value); + if (v.StartsWith("//apcommon")) return (201, "common", v, value); + + if (v.StartsWith("//accessor")) return (220, "accessor", v, value); + if (v.StartsWith("//models")) return (221, "models", v, value); + if (v.StartsWith("//routing")) return (222, "routing", v, value); + if (v.StartsWith("//service")) return (223, "service", v, value); + if (v.StartsWith("//artifacts")) return (224, "artifacts", v, value); - //TODO group - - return (0, v, value); + if (v.StartsWith("//services")) return (251, "services", v, value); + if (v.StartsWith("//gateways")) return (252, "gateways", v, value); + if (v.StartsWith("//jobs")) return (253, "jobs", v, value); + + if (v.StartsWith("//proto/common:")) return (401, "commonproto", v, value); + if (v.StartsWith("//proto")) return (402, "proto", v, value); + + if (v.StartsWith("//library/go/private")) return (500, "privatelib", v, value); + + if (v.StartsWith("//library/go:")) return (501, "golib", v, value); + + if (v.StartsWith("//library/go/")) return (502, "sublib", v, value); + + throw new Exception($"unknown dep group in file {filename}:{linenum} => '{v}'"); } \ No newline at end of file diff --git a/please_build-formatter.csproj b/pbf.csproj similarity index 80% rename from please_build-formatter.csproj rename to pbf.csproj index 211c653..b9de063 100644 --- a/please_build-formatter.csproj +++ b/pbf.csproj @@ -3,7 +3,6 @@ Exe net6.0 - please_build_formatter enable enable diff --git a/pbf.sln b/pbf.sln new file mode 100644 index 0000000..0193a08 --- /dev/null +++ b/pbf.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pbf", "pbf.csproj", "{1B977662-654F-4FB6-AB8D-56DA3D1BB93D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1B977662-654F-4FB6-AB8D-56DA3D1BB93D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1B977662-654F-4FB6-AB8D-56DA3D1BB93D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1B977662-654F-4FB6-AB8D-56DA3D1BB93D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1B977662-654F-4FB6-AB8D-56DA3D1BB93D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/please_build-formatter.sln b/please_build-formatter.sln deleted file mode 100644 index dbac611..0000000 --- a/please_build-formatter.sln +++ /dev/null @@ -1,16 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "please_build-formatter", "please_build-formatter.csproj", "{CFC72DCC-8B8F-4E36-8679-478DB84CE9F0}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CFC72DCC-8B8F-4E36-8679-478DB84CE9F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CFC72DCC-8B8F-4E36-8679-478DB84CE9F0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CFC72DCC-8B8F-4E36-8679-478DB84CE9F0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CFC72DCC-8B8F-4E36-8679-478DB84CE9F0}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal