From c5b27d63a80212abae73df85deae80a458b6e7f2 Mon Sep 17 00:00:00 2001
From: Adeel Mujahid <3840695+am11@users.noreply.github.com>
Date: Fri, 30 Jun 2023 15:06:43 +0300
Subject: [PATCH] Update System.CommandLine version (#84229)
---
eng/Version.Details.xml | 8 +-
eng/Versions.props | 2 +-
src/coreclr/tools/Common/CommandLineHelpers.cs | 60 ++-
src/coreclr/tools/ILVerify/ILVerifyRootCommand.cs | 90 ++--
src/coreclr/tools/ILVerify/Program.cs | 16 +-
src/coreclr/tools/InjectResource/Program.cs | 36 +-
.../tools/aot/ILCompiler/ILCompilerRootCommand.cs | 475 +++++++++----------
src/coreclr/tools/aot/ILCompiler/Program.cs | 16 +-
.../tools/aot/crossgen2/Crossgen2RootCommand.cs | 518 +++++++++++----------
src/coreclr/tools/aot/crossgen2/Program.cs | 16 +-
src/coreclr/tools/dotnet-pgo/PgoRootCommand.cs | 197 ++++----
src/coreclr/tools/dotnet-pgo/Program.cs | 20 +-
src/coreclr/tools/r2rdump/Program.cs | 14 +-
src/coreclr/tools/r2rdump/R2RDumpRootCommand.cs | 222 ++++-----
src/coreclr/tools/r2rtest/CommandLineOptions.cs | 195 ++++----
src/coreclr/tools/r2rtest/R2RTest.csproj | 23 +-
16 files changed, 970 insertions(+), 938 deletions(-)
diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml
index 9097e7e..e0d0e30 100644
--- a/eng/Version.Details.xml
+++ b/eng/Version.Details.xml
@@ -76,13 +76,13 @@
https://github.com/dotnet/llvm-project
76f334f354eb653a7b409a5319b591ea09df5a43
-
+
https://github.com/dotnet/command-line-api
- 8374d5fca634a93458c84414b1604c12f765d1ab
+ 02fe27cd6a9b001c8feb7938e6ef4b3799745759
-
+
https://github.com/dotnet/command-line-api
- 8374d5fca634a93458c84414b1604c12f765d1ab
+ 02fe27cd6a9b001c8feb7938e6ef4b3799745759b
diff --git a/eng/Versions.props b/eng/Versions.props
index 13372c1..5f81f25 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -161,7 +161,7 @@
1.0.0-prerelease.23326.3
16.11.27-beta1.23180.1
- 2.0.0-beta4.22564.1
+ 2.0.0-beta4.23307.1
3.0.3
2.1.0
2.0.3
diff --git a/src/coreclr/tools/Common/CommandLineHelpers.cs b/src/coreclr/tools/Common/CommandLineHelpers.cs
index 2475d2a..205592c 100644
--- a/src/coreclr/tools/Common/CommandLineHelpers.cs
+++ b/src/coreclr/tools/Common/CommandLineHelpers.cs
@@ -1,8 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.CommandLine.Help;
using System.Collections.Generic;
-using System.CommandLine.Binding;
using System.CommandLine.Parsing;
using System.IO;
using System.IO.Compression;
@@ -24,11 +24,11 @@ namespace System.CommandLine
{
public const string DefaultSystemModule = "System.Private.CoreLib";
- public static Dictionary BuildPathDictionary(IReadOnlyList tokens, bool strict)
+ public static Dictionary BuildPathDictionary(IReadOnlyList tokens, bool strict)
{
Dictionary dictionary = new(StringComparer.OrdinalIgnoreCase);
- foreach (Token token in tokens)
+ foreach (CliToken token in tokens)
{
AppendExpandedPaths(dictionary, token.Value, strict);
}
@@ -36,11 +36,11 @@ namespace System.CommandLine
return dictionary;
}
- public static List BuildPathList(IReadOnlyList tokens)
+ public static List BuildPathList(IReadOnlyList tokens)
{
List paths = new();
Dictionary dictionary = new(StringComparer.OrdinalIgnoreCase);
- foreach (Token token in tokens)
+ foreach (CliToken token in tokens)
{
AppendExpandedPaths(dictionary, token.Value, false);
foreach (string file in dictionary.Values)
@@ -113,6 +113,36 @@ namespace System.CommandLine
}
}
+ public static CliRootCommand UseVersion(this CliRootCommand command)
+ {
+ for (int i = 0; i < command.Options.Count; i++)
+ {
+ if (command.Options[i] is VersionOption)
+ {
+ command.Options[i] = new VersionOption("--version", "-v");
+ break;
+ }
+ }
+
+ return command;
+ }
+
+ public static CliRootCommand UseExtendedHelp(this CliRootCommand command, Func>> customizer)
+ {
+ foreach (CliOption option in command.Options)
+ {
+ if (option is HelpOption helpOption)
+ {
+ HelpBuilder builder = new();
+ builder.CustomizeLayout(customizer);
+ helpOption.Action = new HelpAction { Builder = builder };
+ break;
+ }
+ }
+
+ return command;
+ }
+
public static void MakeReproPackage(string makeReproPath, string outputFilePath, string[] args, ParseResult res, IEnumerable inputOptions, IEnumerable outputOptions = null)
{
Directory.CreateDirectory(makeReproPath);
@@ -177,16 +207,16 @@ namespace System.CommandLine
Dictionary outputToReproPackageFileName = new();
List rspFile = new List();
- foreach (var option in res.CommandResult.Command.Options)
+ foreach (CliOption option in res.CommandResult.Command.Options)
{
- if (!res.HasOption(option) || option.Name == "make-repro-path")
+ OptionResult optionResult = res.GetResult(option);
+ if (optionResult is null || option.Name == "make-repro-path")
{
continue;
}
- IValueDescriptor descriptor = option;
- object val = res.CommandResult.GetValue(option);
- if (val is not null && !(descriptor.HasDefaultValue && descriptor.GetDefaultValue().Equals(val)))
+ object val = optionResult.GetValueOrDefault