-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
I was trying to follow the example in this guide on learn for generating documents at build time. It indicates there that you can use the --document-name flag to only generate the document matching the given name. However, I noticed that no matter what value I passed, all of my documents were being generated.
I dug into the code and found the lines where this flag was being consumed. I even saw a comment indicating "If an explicit document name is provided, then generate only that document.". Notably though, I didn't see any code that actually did this restriction prior to the logic iterating over all documents and generating them.
aspnetcore/src/Tools/GetDocumentInsider/src/Commands/GetDocumentCommandWorker.cs
Lines 257 to 297 in 8d0f798
| // If an explicit document name is provided, then generate only that document. | |
| var documentNames = (IEnumerable<string>)InvokeMethod(getDocumentsMethod, service, _getDocumentsArguments); | |
| if (documentNames == null) | |
| { | |
| return false; | |
| } | |
| if (!string.IsNullOrEmpty(_context.DocumentName) && !documentNames.Contains(_context.DocumentName)) | |
| { | |
| _reporter.WriteError(Resources.FormatDocumentNotFound(_context.DocumentName)); | |
| return false; | |
| } | |
| if (!string.IsNullOrWhiteSpace(_context.FileName) && !Regex.IsMatch(_context.FileName, "^([A-Za-z0-9-_]+)$")) | |
| { | |
| _reporter.WriteError(Resources.FileNameFormatInvalid); | |
| return false; | |
| } | |
| // Write out the documents. | |
| var found = false; | |
| Directory.CreateDirectory(_context.OutputDirectory); | |
| var filePathList = new List<string>(); | |
| foreach (var documentName in documentNames) | |
| { | |
| var filePath = GetDocument( | |
| documentName, | |
| _context.ProjectName, | |
| _context.OutputDirectory, | |
| generateMethod, | |
| service, | |
| generateWithVersionMethod, | |
| _context.FileName); | |
| if (filePath == null) | |
| { | |
| return false; | |
| } | |
| filePathList.Add(filePath); | |
| found = true; | |
| } |