Skip to content

Rewrite dotnet-getdocument and GetDocument.Insider to retrieve all documents in one go #10667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Mvc/GetDocumentInsider/src/Commands/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ protected virtual void Validate()
{
}

protected virtual int Execute()
=> 0;
protected virtual int Execute() => 0;
}
}
45 changes: 14 additions & 31 deletions src/Mvc/GetDocumentInsider/src/Commands/GetDocumentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
#if NETCOREAPP2_0
#if NETCOREAPP2_1
using System.Runtime.Loader;
#endif
using Microsoft.DotNet.Cli.CommandLine;
Expand All @@ -14,44 +14,29 @@ namespace Microsoft.Extensions.ApiDescription.Tool.Commands
{
internal class GetDocumentCommand : ProjectCommandBase
{
internal const string FallbackDocumentName = "v1";
internal const string FallbackMethod = "GenerateAsync";
internal const string FallbackService = "Microsoft.Extensions.ApiDescription.IDocumentProvider";

private CommandOption _documentName;
private CommandOption _method;
private CommandOption _fileListPath;
private CommandOption _output;
private CommandOption _service;

public override void Configure(CommandLineApplication command)
{
base.Configure(command);

_documentName = command.Option(
"--documentName <Name>",
Resources.FormatDocumentDescription(FallbackDocumentName));
_method = command.Option("--method <Name>", Resources.FormatMethodDescription(FallbackMethod));
_output = command.Option("--output <Path>", Resources.OutputDescription);
_service = command.Option("--service <QualifiedName>", Resources.FormatServiceDescription(FallbackService));
_fileListPath = command.Option("--file-list <Path>", Resources.FileListDescription);
_output = command.Option("--output <Directory>", Resources.OutputDescription);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example usage of this for the unfamiliar?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is this something that needs to be reviewed in detail? or is this an implementation detail of the MSBuild functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an implementation detail of the MSBuild functionality seen in #10669 and that PR shows how the tool should be used

}

protected override void Validate()
{
base.Validate();

if (!_output.HasValue())
{
throw new CommandException(Resources.FormatMissingOption(_output.LongName));
}

if (_method.HasValue() && !_service.HasValue())
if (!_fileListPath.HasValue())
{
throw new CommandException(Resources.FormatMissingOption(_service.LongName));
throw new CommandException(Resources.FormatMissingOption(_fileListPath.LongName));
}

if (_service.HasValue() && !_method.HasValue())
if (!_output.HasValue())
{
throw new CommandException(Resources.FormatMissingOption(_method.LongName));
throw new CommandException(Resources.FormatMissingOption(_output.LongName));
}
}

Expand Down Expand Up @@ -79,7 +64,7 @@ protected override int Execute()
}
}

#if NETCOREAPP2_0
#if NETCOREAPP2_1
AssemblyLoadContext.Default.Resolving += (loadContext, assemblyName) =>
{
var name = assemblyName.Name;
Expand Down Expand Up @@ -125,7 +110,7 @@ protected override int Execute()
return Assembly.LoadFile(assemblyPath);
};
#else
#error target frameworks need to be updated.
#error Target frameworks need to be updated.
#endif

// Now safe to reference the application's code.
Expand All @@ -135,20 +120,18 @@ protected override int Execute()
var context = new GetDocumentCommandContext
{
AssemblyPath = assemblyPath,
AssemblyDirectory = Path.GetDirectoryName(assemblyPath),
AssemblyName = Path.GetFileNameWithoutExtension(assemblyPath),
DocumentName = _documentName.Value(),
Method = _method.Value(),
OutputPath = _output.Value(),
Service = _service.Value(),
FileListPath = _fileListPath.Value(),
OutputDirectory = _output.Value(),
ProjectName = ProjectName.Value(),
};

return GetDocumentCommandWorker.Process(context);
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.ToString());
return 1;
return 2;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ namespace Microsoft.Extensions.ApiDescription.Tool.Commands
[Serializable]
public class GetDocumentCommandContext
{
public string AssemblyDirectory { get; set; }

public string AssemblyName { get; set; }

public string AssemblyPath { get; set; }

public string DocumentName { get; set; }

public string Method { get; set; }
public string FileListPath { get; set; }

public string OutputPath { get; set; }
public string OutputDirectory { get; set; }

public string Service { get; set; }
public string ProjectName { get; set; }
}
}
Loading