Skip to content

Commit 2338330

Browse files
committed
feat(): pr comments
Signed-off-by: Joe Feser <[email protected]>
1 parent 7abde69 commit 2338330

File tree

4 files changed

+29
-51
lines changed

4 files changed

+29
-51
lines changed

src/ApiGenerator/ApiGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<PreserveCompilationContext>true</PreserveCompilationContext>
1010
</PropertyGroup>
1111
<ItemGroup>
12-
<PackageReference Include="CSharpier.Core" Version="0.28.2" />
1312
<PackageReference Include="Glob" Version="1.1.9" />
1413
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1514
<PackageReference Include="NSwag.Core" Version="14.1.0" />
15+
<PackageReference Include="Proc" Version="0.8.1" />
1616
<PackageReference Include="YamlDotNet" Version="16.0.0" />
1717
<PackageReference Include="SemanticVersioning" Version="2.0.2" />
1818
<PackageReference Include="ShellProgressBar" Version="5.2.0" />

src/ApiGenerator/Configuration/GeneratorLocations.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public static class GeneratorLocations
4747

4848
public static string LowLevel(params string[] paths) => LowLevelGeneratedFolder + string.Join("/", paths);
4949

50+
public static string SolutionFolder { get; } = $"{Root}../../";
51+
5052
public static readonly Assembly Assembly = typeof(Generator.ApiGenerator).Assembly;
5153

5254
private static string _root;

src/ApiGenerator/Generator/CodeGenerator.cs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,22 @@ public static class CodeGenerator
3939
{
4040
public static string CatFormatPropertyGenerator(string type, string name, string key, string setter) =>
4141
$"public {type} {name} {{ "
42-
+ $" get => Q<{type}>(\"{key}\");"
42+
+ $" get => Q<{type}>(\"{key}\");{Environment.NewLine}"
4343
+ $" set {{ Q(\"{key}\", {setter}); SetAcceptHeader({setter}); }}"
4444
+ $"}}";
4545

4646
public static string PropertyGenerator(string type, string name, string key, string setter) =>
47-
$"public {type} {name} {{ get => Q<{type}>(\"{key}\"); set => Q(\"{key}\", {setter}); }}";
47+
$"public {type} {name} {{ get => Q<{type}>(\"{key}\");{Environment.NewLine} set => Q(\"{key}\", {setter}); }}";
4848

4949
public static string Property(string @namespace, string type, string name, string key, string setter, string obsolete, Version versionAdded, params string[] doc)
5050
{
5151
var components = new List<string>();
52-
foreach (var d in RenderDocumentation(doc)) A(d);
53-
if (versionAdded != null) A($"/// <remarks>Supported by OpenSearch servers of version {versionAdded} or greater.</remarks>");
54-
if (!string.IsNullOrWhiteSpace(obsolete)) A($"[Obsolete(\"{obsolete}\")]");
52+
foreach (var d in RenderDocumentation(doc))
53+
A(d);
54+
if (versionAdded != null)
55+
A($"/// <remarks>Supported by OpenSearch servers of version {versionAdded} or greater.</remarks>");
56+
if (!string.IsNullOrWhiteSpace(obsolete))
57+
A($"[Obsolete(\"{obsolete}\")]");
5558

5659
var generated = @namespace != null && @namespace == "Cat" && name == "Format"
5760
? CatFormatPropertyGenerator(type, name, key, setter)
@@ -69,12 +72,16 @@ void A(string s)
6972
public static string Constructor(Constructor c)
7073
{
7174
var components = new List<string>();
72-
if (!c.Description.IsNullOrEmpty()) A(c.Description);
75+
if (!c.Description.IsNullOrEmpty())
76+
A(c.Description);
7377
var generated = c.Generated;
74-
if (c.Body.IsNullOrEmpty()) generated += "{}";
78+
if (c.Body.IsNullOrEmpty())
79+
generated += "{}";
7580
A(generated);
76-
if (!c.Body.IsNullOrEmpty()) A(c.Body);
77-
if (!c.AdditionalCode.IsNullOrEmpty()) A(c.AdditionalCode);
81+
if (!c.Body.IsNullOrEmpty())
82+
A(c.Body);
83+
if (!c.AdditionalCode.IsNullOrEmpty())
84+
A(c.AdditionalCode);
7885
return string.Join($"{Environment.NewLine}\t\t", components);
7986

8087
void A(string s)
@@ -88,15 +95,17 @@ private static IEnumerable<string> RenderDocumentation(params string[] doc)
8895
doc = (doc?.SelectMany(WrapDocumentation) ?? Enumerable.Empty<string>()).ToArray();
8996
switch (doc.Length)
9097
{
91-
case 0: yield break;
98+
case 0:
99+
yield break;
92100
case 1:
93101
yield return $"/// <summary>{doc[0]}</summary>";
94102

95103
yield break;
96104
default:
97105
yield return "/// <summary>";
98106

99-
foreach (var d in doc) yield return $"/// {d}";
107+
foreach (var d in doc)
108+
yield return $"/// {d}";
100109

101110
yield return "/// </summary>";
102111

@@ -106,7 +115,8 @@ private static IEnumerable<string> RenderDocumentation(params string[] doc)
106115

107116
private static string[] WrapDocumentation(string documentation)
108117
{
109-
if (string.IsNullOrWhiteSpace(documentation)) return Array.Empty<string>();
118+
if (string.IsNullOrWhiteSpace(documentation))
119+
return Array.Empty<string>();
110120
const int max = 140;
111121
var lines = documentation.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
112122
var charCount = 0;

src/ApiGenerator/Program.cs

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
using System.Threading;
3434
using System.Threading.Tasks;
3535
using ApiGenerator.Configuration;
36+
using ProcNet;
3637
using Spectre.Console;
3738

3839
#pragma warning disable 162
@@ -175,45 +176,10 @@ private static void RunDotNetFormat()
175176
AnsiConsole.Write(new Rule("[b white on chartreuse4] Formatting Code using dotnet format [/]").LeftJustified());
176177
Console.WriteLine();
177178

178-
var rootPath = GetRootPath(typeof(Program).Assembly.Location);
179-
180-
var relativeFolderList = new List<string>();
181-
182-
foreach (var item in Generator.ApiGenerator.GeneratedFilePaths)
183-
{
184-
var relativePath = item.Replace(rootPath.FullName, string.Empty);
185-
relativeFolderList.Add($".{relativePath.Replace("\\", "/")}");
186-
}
187-
188-
var si = new System.Diagnostics.ProcessStartInfo
179+
Proc.Exec(new ExecArguments("dotnet", "format", "--verbosity", "normal", "--include", "./src/*/_Generated/")
189180
{
190-
WorkingDirectory = rootPath.FullName,
191-
FileName = "dotnet",
192-
Arguments = "format -v diag --include " + string.Join(' ', relativeFolderList.Select(item => $"{item}")),
193-
RedirectStandardInput = true,
194-
RedirectStandardOutput = true,
195-
RedirectStandardError = true,
196-
UseShellExecute = false,
197-
CreateNoWindow = true,
198-
};
199-
200-
var process = System.Diagnostics.Process.Start(si);
201-
202-
Console.WriteLine();
203-
Console.WriteLine($"Running dotnet format --include {string.Join(' ', relativeFolderList.Select(item => $"{item}"))} -v diag");
204-
205-
// hookup the eventhandlers to capture the data that is received
206-
process.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data);
207-
process.ErrorDataReceived += (sender, args) => Console.WriteLine(args.Data);
208-
209-
process.Start();
210-
211-
// start our event pumps
212-
process.BeginOutputReadLine();
213-
process.BeginErrorReadLine();
214-
215-
process.WaitForExit();
216-
Console.WriteLine();
181+
WorkingDirectory = GeneratorLocations.SolutionFolder
182+
});
217183
}
218184

219185
private static bool Ask(string question, bool defaultAnswer = true)

0 commit comments

Comments
 (0)