-
Notifications
You must be signed in to change notification settings - Fork 470
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
[BLOCKED] update System.CommandLine #7559
Draft
adamsitnik
wants to merge
3
commits into
dotnet:main
Choose a base branch
from
adamsitnik:scl_prefix_update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
src/Tools/PerfDiff/Logging/SimpleConsoleLoggerFactoryExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,6 @@ | |
using PerfDiff.Logging; | ||
|
||
using System; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.CommandLine.Parsing; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
@@ -18,48 +15,26 @@ namespace PerfDiff | |
internal sealed class Program | ||
{ | ||
internal const int UnhandledExceptionExitCode = 1; | ||
private static ParseResult? s_parseResult; | ||
|
||
private static async Task<int> Main(string[] args) | ||
{ | ||
var rootCommand = DiffCommand.CreateCommandLineOptions(); | ||
rootCommand.Handler = CommandHandler.Create(new DiffCommand.Handler(RunAsync)); | ||
|
||
// Parse the incoming args so we can give warnings when deprecated options are used. | ||
s_parseResult = rootCommand.Parse(args); | ||
|
||
return await rootCommand.InvokeAsync(args).ConfigureAwait(false); | ||
} | ||
private static Task<int> Main(string[] args) | ||
=> DiffCommand.CreateCommandLineOptions().Parse(args).InvokeAsync(); | ||
|
||
public static async Task<int> RunAsync( | ||
string baseline, | ||
string results, | ||
string? verbosity, | ||
bool failOnRegression, | ||
IConsole console) | ||
CancellationToken token) | ||
{ | ||
if (s_parseResult == null) | ||
{ | ||
return 1; | ||
} | ||
|
||
// Setup logging. | ||
var logLevel = GetLogLevel(verbosity); | ||
var logger = SetupLogging(console, minimalLogLevel: logLevel, minimalErrorLevel: LogLevel.Warning); | ||
|
||
// Hook so we can cancel and exit when ctrl+c is pressed. | ||
var cancellationTokenSource = new CancellationTokenSource(); | ||
Console.CancelKeyPress += (sender, e) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now being performed out of the box by System.CommandLine. All you need it to pass the cancellation token in SetAction to given async method |
||
{ | ||
e.Cancel = true; | ||
cancellationTokenSource.Cancel(); | ||
}; | ||
var logger = SetupLogging(minimalLogLevel: logLevel, minimalErrorLevel: LogLevel.Warning); | ||
|
||
var currentDirectory = string.Empty; | ||
|
||
try | ||
{ | ||
var exitCode = await PerfDiff.CompareAsync(baseline, results, failOnRegression, logger, cancellationTokenSource.Token).ConfigureAwait(false); | ||
var exitCode = await PerfDiff.CompareAsync(baseline, results, failOnRegression, logger, token).ConfigureAwait(false); | ||
return exitCode; | ||
} | ||
catch (FileNotFoundException fex) | ||
|
@@ -83,10 +58,10 @@ public static async Task<int> RunAsync( | |
} | ||
} | ||
|
||
static ILogger<Program> SetupLogging(IConsole console, LogLevel minimalLogLevel, LogLevel minimalErrorLevel) | ||
static ILogger<Program> SetupLogging(LogLevel minimalLogLevel, LogLevel minimalErrorLevel) | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddSingleton(new LoggerFactory().AddSimpleConsole(console, minimalLogLevel, minimalErrorLevel)); | ||
serviceCollection.AddSingleton(new LoggerFactory().AddSimpleConsole(minimalLogLevel, minimalErrorLevel)); | ||
serviceCollection.AddLogging(); | ||
|
||
var serviceProvider = serviceCollection.BuildServiceProvider(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not able to find any other usage of
Program.RunAsync
so I've assumed that it's most likely some leftover and removed it.FWIW if there will be any parsing errors detected, the
Parse(args).InvokeAsync()
call is going to get them printed to output and also return error code.