Skip to content

Commit e18693a

Browse files
committed
Rewrite dotnet-getdocument and GetDocumentCommandInsider to retrieve all documents in one go
- #8242 1 of 2 - save a cache file listing all retrieved documents - remove .NET Core App 2.0 support - remove ServiceProjectReferenceMetadata.targets, related `Project` class, and searches for a project - tools will run within a project and get needed information from project on command line - roll framework forward in both tools to expand their applicability nits: - refactor methods in `GetDocumentCommandWorker` - reorder option addition for consistency and to place `--help` at the top of help output - consolidate information about method signatures at top of `GetDocumentCommandWorker` - consolidate `try` / `catch` blocks in `GetDocumentCommandWorker`
1 parent 173cf17 commit e18693a

21 files changed

+664
-970
lines changed

src/Mvc/GetDocumentInsider/src/Commands/CommandBase.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ protected virtual void Validate()
3232
{
3333
}
3434

35-
protected virtual int Execute()
36-
=> 0;
35+
protected virtual int Execute() => 0;
3736
}
3837
}

src/Mvc/GetDocumentInsider/src/Commands/GetDocumentCommand.cs

+13-30
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using System.Reflection;
8-
#if NETCOREAPP2_0
8+
#if NETCOREAPP2_1
99
using System.Runtime.Loader;
1010
#endif
1111
using Microsoft.DotNet.Cli.CommandLine;
@@ -14,44 +14,29 @@ namespace Microsoft.Extensions.ApiDescription.Tool.Commands
1414
{
1515
internal class GetDocumentCommand : ProjectCommandBase
1616
{
17-
internal const string FallbackDocumentName = "v1";
18-
internal const string FallbackMethod = "GenerateAsync";
19-
internal const string FallbackService = "Microsoft.Extensions.ApiDescription.IDocumentProvider";
20-
21-
private CommandOption _documentName;
22-
private CommandOption _method;
17+
private CommandOption _fileListPath;
2318
private CommandOption _output;
24-
private CommandOption _service;
2519

2620
public override void Configure(CommandLineApplication command)
2721
{
2822
base.Configure(command);
2923

30-
_documentName = command.Option(
31-
"--documentName <Name>",
32-
Resources.FormatDocumentDescription(FallbackDocumentName));
33-
_method = command.Option("--method <Name>", Resources.FormatMethodDescription(FallbackMethod));
34-
_output = command.Option("--output <Path>", Resources.OutputDescription);
35-
_service = command.Option("--service <QualifiedName>", Resources.FormatServiceDescription(FallbackService));
24+
_fileListPath = command.Option("--file-list <Path>", Resources.FileListDescription);
25+
_output = command.Option("--output <Directory>", Resources.OutputDescription);
3626
}
3727

3828
protected override void Validate()
3929
{
4030
base.Validate();
4131

42-
if (!_output.HasValue())
43-
{
44-
throw new CommandException(Resources.FormatMissingOption(_output.LongName));
45-
}
46-
47-
if (_method.HasValue() && !_service.HasValue())
32+
if (!_fileListPath.HasValue())
4833
{
49-
throw new CommandException(Resources.FormatMissingOption(_service.LongName));
34+
throw new CommandException(Resources.FormatMissingOption(_fileListPath.LongName));
5035
}
5136

52-
if (_service.HasValue() && !_method.HasValue())
37+
if (!_output.HasValue())
5338
{
54-
throw new CommandException(Resources.FormatMissingOption(_method.LongName));
39+
throw new CommandException(Resources.FormatMissingOption(_output.LongName));
5540
}
5641
}
5742

@@ -79,7 +64,7 @@ protected override int Execute()
7964
}
8065
}
8166

82-
#if NETCOREAPP2_0
67+
#if NETCOREAPP2_1
8368
AssemblyLoadContext.Default.Resolving += (loadContext, assemblyName) =>
8469
{
8570
var name = assemblyName.Name;
@@ -125,7 +110,7 @@ protected override int Execute()
125110
return Assembly.LoadFile(assemblyPath);
126111
};
127112
#else
128-
#error target frameworks need to be updated.
113+
#error Target frameworks need to be updated.
129114
#endif
130115

131116
// Now safe to reference the application's code.
@@ -135,12 +120,10 @@ protected override int Execute()
135120
var context = new GetDocumentCommandContext
136121
{
137122
AssemblyPath = assemblyPath,
138-
AssemblyDirectory = Path.GetDirectoryName(assemblyPath),
139123
AssemblyName = Path.GetFileNameWithoutExtension(assemblyPath),
140-
DocumentName = _documentName.Value(),
141-
Method = _method.Value(),
142-
OutputPath = _output.Value(),
143-
Service = _service.Value(),
124+
FileListPath = _fileListPath.Value(),
125+
OutputDirectory = _output.Value(),
126+
ProjectName = ProjectName.Value(),
144127
};
145128

146129
return GetDocumentCommandWorker.Process(context);

src/Mvc/GetDocumentInsider/src/Commands/GetDocumentCommandContext.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@ namespace Microsoft.Extensions.ApiDescription.Tool.Commands
88
[Serializable]
99
public class GetDocumentCommandContext
1010
{
11-
public string AssemblyDirectory { get; set; }
12-
1311
public string AssemblyName { get; set; }
1412

1513
public string AssemblyPath { get; set; }
1614

17-
public string DocumentName { get; set; }
18-
19-
public string Method { get; set; }
15+
public string FileListPath { get; set; }
2016

21-
public string OutputPath { get; set; }
17+
public string OutputDirectory { get; set; }
2218

23-
public string Service { get; set; }
19+
public string ProjectName { get; set; }
2420
}
2521
}

0 commit comments

Comments
 (0)