22// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33// See the LICENSE file in the project root for more information
44
5- using System . Diagnostics . CodeAnalysis ;
65using System . IO . Abstractions ;
76using System . IO . Abstractions . TestingHelpers ;
87using Actions . Core . Services ;
1312using Elastic . Documentation . Configuration . Versions ;
1413using Elastic . Documentation . Refactor ;
1514using Elastic . Documentation . Tooling . Diagnostics . Console ;
16- using Elastic . Documentation . Tooling . Filters ;
1715using Elastic . Markdown ;
1816using Elastic . Markdown . Exporters ;
1917using Elastic . Markdown . IO ;
2220
2321namespace Documentation . Builder . Cli ;
2422
25- internal sealed class Commands ( ILoggerFactory logger , ICoreService githubActionsService , IOptions < VersionsConfiguration > versionsConfigOption )
23+ internal sealed class Commands ( ILoggerFactory logFactory , ICoreService githubActionsService , IOptions < VersionsConfiguration > versionsConfigOption )
2624{
27- private readonly ILogger < Program > _log = logger . CreateLogger < Program > ( ) ;
28-
29- [ SuppressMessage ( "Usage" , "CA2254:Template should be a static expression" ) ]
30- private void AssignOutputLogger ( )
31- {
32- ConsoleApp . Log = msg => _log . LogInformation ( msg ) ;
33- ConsoleApp . LogError = msg => _log . LogError ( msg ) ;
34- }
25+ private readonly ILogger < Program > _log = logFactory . CreateLogger < Program > ( ) ;
3526
3627 /// <summary>
3728 /// Continuously serve a documentation folder at http://localhost:3000.
@@ -43,11 +34,9 @@ private void AssignOutputLogger()
4334 /// <param name="port">Port to serve the documentation.</param>
4435 /// <param name="ctx"></param>
4536 [ Command ( "serve" ) ]
46- [ ConsoleAppFilter < CheckForUpdatesFilter > ]
4737 public async Task Serve ( string ? path = null , int port = 3000 , Cancel ctx = default )
4838 {
49- AssignOutputLogger ( ) ;
50- var host = new DocumentationWebHost ( path , port , logger , new FileSystem ( ) , new MockFileSystem ( ) , versionsConfigOption . Value ) ;
39+ var host = new DocumentationWebHost ( path , port , logFactory , new FileSystem ( ) , new MockFileSystem ( ) , versionsConfigOption . Value ) ;
5140 _log . LogInformation ( "Find your documentation at http://localhost:{Port}/{Path}" , port ,
5241 host . GeneratorState . Generator . DocumentationSet . FirstInterestingUrl . TrimStart ( '/' )
5342 ) ;
@@ -56,22 +45,20 @@ public async Task Serve(string? path = null, int port = 3000, Cancel ctx = defau
5645 }
5746
5847 /// <summary>
59- /// Serve html files directly
48+ /// Serve HTML files directly
6049 /// </summary>
6150 /// <param name="port">Port to serve the documentation.</param>
6251 /// <param name="ctx"></param>
6352 [ Command ( "serve-static" ) ]
64- [ ConsoleAppFilter < CheckForUpdatesFilter > ]
6553 public async Task ServeStatic ( int port = 4000 , Cancel ctx = default )
6654 {
67- AssignOutputLogger ( ) ;
6855 var host = new StaticWebHost ( port ) ;
6956 await host . RunAsync ( ctx ) ;
7057 await host . StopAsync ( ctx ) ;
7158 }
7259
7360 /// <summary>
74- /// Converts a source markdown folder or file to an output folder
61+ /// Converts a source Markdown folder or file to an output folder
7562 /// <para>global options:</para>
7663 /// --log-level level
7764 /// </summary>
@@ -80,14 +67,11 @@ public async Task ServeStatic(int port = 4000, Cancel ctx = default)
8067 /// <param name="pathPrefix"> Specifies the path prefix for urls </param>
8168 /// <param name="force"> Force a full rebuild of the destination folder</param>
8269 /// <param name="strict"> Treat warnings as errors and fail the build on warnings</param>
83- /// <param name="allowIndexing"> Allow indexing and following of html files</param>
70+ /// <param name="allowIndexing"> Allow indexing and following of HTML files</param>
8471 /// <param name="metadataOnly"> Only emit documentation metadata to output</param>
8572 /// <param name="canonicalBaseUrl"> The base URL for the canonical url tag</param>
8673 /// <param name="ctx"></param>
8774 [ Command ( "generate" ) ]
88- [ ConsoleAppFilter < StopwatchFilter > ]
89- [ ConsoleAppFilter < CatchExceptionFilter > ]
90- [ ConsoleAppFilter < CheckForUpdatesFilter > ]
9175 public async Task < int > Generate (
9276 string ? path = null ,
9377 string ? output = null ,
@@ -100,10 +84,9 @@ public async Task<int> Generate(
10084 Cancel ctx = default
10185 )
10286 {
103- AssignOutputLogger ( ) ;
10487 pathPrefix ??= githubActionsService . GetInput ( "prefix" ) ;
10588 var fileSystem = new FileSystem ( ) ;
106- await using var collector = new ConsoleDiagnosticsCollector ( logger , githubActionsService ) . StartAsync ( ctx ) ;
89+ await using var collector = new ConsoleDiagnosticsCollector ( logFactory , githubActionsService ) . StartAsync ( ctx ) ;
10790
10891 var runningOnCi = ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( "GITHUB_ACTIONS" ) ) ;
10992 BuildContext context ;
@@ -139,7 +122,7 @@ public async Task<int> Generate(
139122 var outputDirectory = ! string . IsNullOrWhiteSpace ( output )
140123 ? fileSystem . DirectoryInfo . New ( output )
141124 : fileSystem . DirectoryInfo . New ( Path . Combine ( Paths . WorkingDirectoryRoot . FullName , ".artifacts/docs/html" ) ) ;
142- // we temporarily do not error when pointed to a non documentation folder.
125+ // we temporarily do not error when pointed to a non- documentation folder.
143126 _ = fileSystem . Directory . CreateDirectory ( outputDirectory . FullName ) ;
144127
145128 ConsoleApp . Log ( $ "Skipping build as we are running on a merge commit and the docs folder is out of date and has no docset.yml. { e . Message } ") ;
@@ -152,7 +135,7 @@ public async Task<int> Generate(
152135 await githubActionsService . SetOutputAsync ( "skip" , "false" ) ;
153136
154137 // always delete output folder on CI
155- var set = new DocumentationSet ( context , logger ) ;
138+ var set = new DocumentationSet ( context , logFactory ) ;
156139 if ( runningOnCi )
157140 set . ClearOutputDirectory ( ) ;
158141
@@ -161,11 +144,11 @@ public async Task<int> Generate(
161144 metadataOnly ??= metaValue ;
162145 var exporter = metadataOnly . HasValue && metadataOnly . Value ? new NoopDocumentationFileExporter ( ) : null ;
163146
164- var generator = new DocumentationGenerator ( set , logger , null , null , null , exporter ) ;
147+ var generator = new DocumentationGenerator ( set , logFactory , null , null , null , exporter ) ;
165148 _ = await generator . GenerateAll ( ctx ) ;
166149
167150
168- var openApiGenerator = new OpenApiGenerator ( context , generator . MarkdownStringRenderer , logger ) ;
151+ var openApiGenerator = new OpenApiGenerator ( context , generator . MarkdownStringRenderer , logFactory ) ;
169152 await openApiGenerator . Generate ( ctx ) ;
170153
171154 if ( runningOnCi )
@@ -180,21 +163,18 @@ public async Task<int> Generate(
180163 }
181164
182165 /// <summary>
183- /// Converts a source markdown folder or file to an output folder
166+ /// Converts a source Markdown folder or file to an output folder
184167 /// </summary>
185168 /// <param name="path"> -p, Defaults to the`{pwd}/docs` folder</param>
186169 /// <param name="output"> -o, Defaults to `.artifacts/html` </param>
187170 /// <param name="pathPrefix"> Specifies the path prefix for urls </param>
188171 /// <param name="force"> Force a full rebuild of the destination folder</param>
189172 /// <param name="strict"> Treat warnings as errors and fail the build on warnings</param>
190- /// <param name="allowIndexing"> Allow indexing and following of html files</param>
173+ /// <param name="allowIndexing"> Allow indexing and following of HTML files</param>
191174 /// <param name="metadataOnly"> Only emit documentation metadata to output</param>
192175 /// <param name="canonicalBaseUrl"> The base URL for the canonical url tag</param>
193176 /// <param name="ctx"></param>
194177 [ Command ( "" ) ]
195- [ ConsoleAppFilter < StopwatchFilter > ]
196- [ ConsoleAppFilter < CatchExceptionFilter > ]
197- [ ConsoleAppFilter < CheckForUpdatesFilter > ]
198178 public async Task < int > GenerateDefault (
199179 string ? path = null ,
200180 string ? output = null ,
@@ -218,9 +198,6 @@ public async Task<int> GenerateDefault(
218198 /// <param name="dryRun">Dry run the move operation</param>
219199 /// <param name="ctx"></param>
220200 [ Command ( "mv" ) ]
221- [ ConsoleAppFilter < StopwatchFilter > ]
222- [ ConsoleAppFilter < CatchExceptionFilter > ]
223- [ ConsoleAppFilter < CheckForUpdatesFilter > ]
224201 public async Task < int > Move (
225202 [ Argument ] string source ,
226203 [ Argument ] string target ,
@@ -229,13 +206,12 @@ public async Task<int> Move(
229206 Cancel ctx = default
230207 )
231208 {
232- AssignOutputLogger ( ) ;
233209 var fileSystem = new FileSystem ( ) ;
234- await using var collector = new ConsoleDiagnosticsCollector ( logger , null ) . StartAsync ( ctx ) ;
210+ await using var collector = new ConsoleDiagnosticsCollector ( logFactory , null ) . StartAsync ( ctx ) ;
235211 var context = new BuildContext ( collector , fileSystem , fileSystem , versionsConfigOption . Value , path , null ) ;
236- var set = new DocumentationSet ( context , logger ) ;
212+ var set = new DocumentationSet ( context , logFactory ) ;
237213
238- var moveCommand = new Move ( fileSystem , fileSystem , set , logger ) ;
214+ var moveCommand = new Move ( fileSystem , fileSystem , set , logFactory ) ;
239215 var result = await moveCommand . Execute ( source , target , dryRun ?? false , ctx ) ;
240216 await collector . StopAsync ( ctx ) ;
241217 return result ;
0 commit comments