提交 fafc11e3 编写于 作者: J Jason Malinowski

Add command line parsing and handling for output and log files

上级 fc040b27
......@@ -41,7 +41,6 @@
<PropertyGroup>
<BasicUndoVersion>0.9.3</BasicUndoVersion>
<BenchmarkDotNetVersion>0.11.4</BenchmarkDotNetVersion>
<CommandLineParserVersion>2.0.273-beta</CommandLineParserVersion>
<DiffPlexVersion>1.4.4</DiffPlexVersion>
<DropAppVersion>17.144.28413-buildid7983345</DropAppVersion>
<EnvDTEVersion>8.0.2</EnvDTEVersion>
......@@ -179,8 +178,7 @@
<RoslynMicrosoftVisualStudioExtensionManagerVersion>0.0.4</RoslynMicrosoftVisualStudioExtensionManagerVersion>
<SourceBrowserVersion>1.0.21</SourceBrowserVersion>
<SystemBuffersVersion>4.5.0</SystemBuffersVersion>
<SystemCommandLineExperimentalVersion>0.1.0-alpha-63729-01</SystemCommandLineExperimentalVersion>
<SystemCommandLineRenderingVersion>0.1.0-alpha-63729-01</SystemCommandLineRenderingVersion>
<SystemCommandLineExperimentalVersion>0.3.0-alpha.19577.1</SystemCommandLineExperimentalVersion>
<SystemComponentModelCompositionVersion>4.5.0</SystemComponentModelCompositionVersion>
<SystemDrawingCommonVersion>4.5.0</SystemDrawingCommonVersion>
<SystemIOFileSystemVersion>4.3.0</SystemIOFileSystemVersion>
......
# This .editorconfig customizes some diagnostic rules that are specific to this project.
[*.cs]
dotnet_diagnostic.CA2007.severity = none # Disable warnings about ConfigureAwait, since this is a console app
dotnet_diagnostic.VSTHRD111.severity = none # Disable warnings about ConfigureAwait, since this is a console app
\ No newline at end of file
......@@ -12,4 +12,11 @@
<RuntimeIdentifiers>$(RoslynPortableRuntimeIdentifiers)</RuntimeIdentifiers>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.CommandLine.Experimental" Version="$(SystemCommandLineExperimentalVersion)" />
</ItemGroup>
<ItemGroup>
<None Include=".editorconfig" />
<None Include="README.md" />
</ItemGroup>
</Project>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.Invocation;
using System.IO;
using System.Threading.Tasks;
namespace Microsoft.CodeAnalysis.Lsif.Generator
{
internal static class Program
{
public static void Main(string[] args)
public static Task Main(string[] args)
{
var generateCommand = new RootCommand("generates an LSIF file")
{
new Option("--output", "file to write the LSIF output to, instead of the console") { Argument = new Argument<string?>(defaultValue: () => null).LegalFilePathsOnly() },
new Option("--log", "file to write a log to") { Argument = new Argument<string?>(defaultValue: () => null).LegalFilePathsOnly() }
};
generateCommand.Handler = CommandHandler.Create((Func<string?, string?, Task>)GenerateAsync);
return generateCommand.InvokeAsync(args);
}
private static async Task GenerateAsync(string? output, string? log)
{
// If we have an output file, we'll write to that, else we'll use Console.Out
using StreamWriter? outputFile = output != null ? new StreamWriter(output) : null;
TextWriter outputWriter = outputFile ?? Console.Out;
using TextWriter logFile = log != null ? new StreamWriter(log) : TextWriter.Null;
try
{
await GenerateAsync(outputWriter, logFile);
}
catch (Exception e)
{
// If it failed, write out to the logs and error, but propagate the error too
var message = "Unhandled exception: " + e.ToString();
await logFile.WriteLineAsync(message);
Console.Error.WriteLine(message);
throw;
}
await logFile.WriteLineAsync("Generation complete.");
}
private static Task GenerateAsync(TextWriter outputWriter, TextWriter logFile)
{
return Task.CompletedTask;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册