From a93456e4fdc106e5b7950db4cd8274ed5ab7a6e8 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Thu, 8 Jun 2023 18:51:21 +0000 Subject: [PATCH 01/22] Update dependencies from https://github.com/dotnet/command-line-api build 20230608.1 Microsoft.SourceBuild.Intermediate.command-line-api , System.CommandLine From Version 0.1.430701 -> To Version 0.1.430801 --- eng/Version.Details.xml | 8 ++++---- eng/Versions.props | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index f99edc8aa334..1d4224eea3a6 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -253,13 +253,13 @@ 2f6e15ab519f31462043a87d037cccf7b742da02 - + https://github.com/dotnet/command-line-api - 02fe27cd6a9b001c8feb7938e6ef4b3799745759 + 96a8130a7db5b4f5f8932512da52cbf7ff71bcd4 - + https://github.com/dotnet/command-line-api - 02fe27cd6a9b001c8feb7938e6ef4b3799745759 + 96a8130a7db5b4f5f8932512da52cbf7ff71bcd4 diff --git a/eng/Versions.props b/eng/Versions.props index b007838d2a9a..df5d0907ec07 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -39,7 +39,7 @@ 7.0.2 8.0.0-preview.6.23307.10 4.6.0 - 2.0.0-beta4.23307.1 + 2.0.0-beta4.23308.1 1.0.0-preview.6.23206.1 3.2.2146 From 35c9c702c3a26c7c033bc731bf74b32799cfb7d9 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Mon, 12 Jun 2023 16:39:17 +0000 Subject: [PATCH 02/22] Update dependencies from https://github.com/dotnet/command-line-api build 20230612.1 Microsoft.SourceBuild.Intermediate.command-line-api , System.CommandLine From Version 0.1.356401 -> To Version 0.1.431201 --- eng/Version.Details.xml | 8 ++++---- eng/Versions.props | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 85b0726cbdef..855ea8017d4f 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -321,13 +321,13 @@ 2f0301ef59624a72fb00f7fd92caa50be03f277d - + https://github.com/dotnet/command-line-api - 96a8130a7db5b4f5f8932512da52cbf7ff71bcd4 + 44cba4d0d0acd32a5e029bf3f96e28eec37b93d1 - + https://github.com/dotnet/command-line-api - 96a8130a7db5b4f5f8932512da52cbf7ff71bcd4 + 44cba4d0d0acd32a5e029bf3f96e28eec37b93d1 diff --git a/eng/Versions.props b/eng/Versions.props index df0c2108ed07..dd6b513c7e7b 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -39,7 +39,7 @@ 7.0.2 8.0.0-preview.6.23309.7 4.6.0 - 2.0.0-beta4.23308.1 + 2.0.0-beta4.23312.1 1.0.0-preview.6.23206.1 3.2.2146 From 7aa4ec2a71b92135cb292f5b75eaa987beb8c543 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Mon, 12 Jun 2023 17:43:56 +0000 Subject: [PATCH 03/22] Update dependencies from https://github.com/dotnet/command-line-api build 20230612.2 Microsoft.SourceBuild.Intermediate.command-line-api , System.CommandLine From Version 0.1.356401 -> To Version 0.1.431202 --- eng/Version.Details.xml | 8 ++++---- eng/Versions.props | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 855ea8017d4f..0de76e8e9a5b 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -321,13 +321,13 @@ 2f0301ef59624a72fb00f7fd92caa50be03f277d - + https://github.com/dotnet/command-line-api - 44cba4d0d0acd32a5e029bf3f96e28eec37b93d1 + 8f2ada7fbaab300dc3fcaa9141d1d69340e3b4cb - + https://github.com/dotnet/command-line-api - 44cba4d0d0acd32a5e029bf3f96e28eec37b93d1 + 8f2ada7fbaab300dc3fcaa9141d1d69340e3b4cb diff --git a/eng/Versions.props b/eng/Versions.props index dd6b513c7e7b..756c809637dd 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -39,7 +39,7 @@ 7.0.2 8.0.0-preview.6.23309.7 4.6.0 - 2.0.0-beta4.23312.1 + 2.0.0-beta4.23312.2 1.0.0-preview.6.23206.1 3.2.2146 From 0c7a1dd32b9a1436271357b4342ce335257f1dee Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Thu, 15 Jun 2023 17:39:24 +0000 Subject: [PATCH 04/22] Update dependencies from https://github.com/dotnet/command-line-api build 20230615.1 Microsoft.SourceBuild.Intermediate.command-line-api , System.CommandLine From Version 0.1.356401 -> To Version 0.1.431501 --- eng/Version.Details.xml | 8 ++++---- eng/Versions.props | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 0de76e8e9a5b..45642bf73129 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -321,13 +321,13 @@ 2f0301ef59624a72fb00f7fd92caa50be03f277d - + https://github.com/dotnet/command-line-api - 8f2ada7fbaab300dc3fcaa9141d1d69340e3b4cb + 6b9b8c8498b2cfaae488bc06a4132c2b15248e6d - + https://github.com/dotnet/command-line-api - 8f2ada7fbaab300dc3fcaa9141d1d69340e3b4cb + 6b9b8c8498b2cfaae488bc06a4132c2b15248e6d diff --git a/eng/Versions.props b/eng/Versions.props index 756c809637dd..1132654efae1 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -39,7 +39,7 @@ 7.0.2 8.0.0-preview.6.23309.7 4.6.0 - 2.0.0-beta4.23312.2 + 2.0.0-beta4.23315.1 1.0.0-preview.6.23206.1 3.2.2146 From 81670849c1c78e70b441e88c394364a9036399e3 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Mon, 19 Jun 2023 16:25:06 +0000 Subject: [PATCH 05/22] Update dependencies from https://github.com/dotnet/command-line-api build 20230619.1 Microsoft.SourceBuild.Intermediate.command-line-api , System.CommandLine From Version 0.1.356401 -> To Version 0.1.431901 --- eng/Version.Details.xml | 8 ++++---- eng/Versions.props | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 45642bf73129..902003d4fcdc 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -321,13 +321,13 @@ 2f0301ef59624a72fb00f7fd92caa50be03f277d - + https://github.com/dotnet/command-line-api - 6b9b8c8498b2cfaae488bc06a4132c2b15248e6d + 6daed85086c41a1cd72a97f298f9cfe2beafa3f4 - + https://github.com/dotnet/command-line-api - 6b9b8c8498b2cfaae488bc06a4132c2b15248e6d + 6daed85086c41a1cd72a97f298f9cfe2beafa3f4 diff --git a/eng/Versions.props b/eng/Versions.props index 1132654efae1..6f6ed5f9d6b9 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -39,7 +39,7 @@ 7.0.2 8.0.0-preview.6.23309.7 4.6.0 - 2.0.0-beta4.23315.1 + 2.0.0-beta4.23319.1 1.0.0-preview.6.23206.1 3.2.2146 From b55ba2502bbfd864c5e8955ac2c3b4e691342b75 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Mon, 26 Jun 2023 21:12:36 +0000 Subject: [PATCH 06/22] Update dependencies from https://github.com/dotnet/command-line-api build 20230626.1 Microsoft.SourceBuild.Intermediate.command-line-api , System.CommandLine From Version 0.1.356401 -> To Version 0.1.432601 --- eng/Version.Details.xml | 8 ++++---- eng/Versions.props | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 902003d4fcdc..06fc15ac3bf4 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -321,13 +321,13 @@ 2f0301ef59624a72fb00f7fd92caa50be03f277d - + https://github.com/dotnet/command-line-api - 6daed85086c41a1cd72a97f298f9cfe2beafa3f4 + f6ff2f1a94a58617e744f8fe0d469a2a420a6259 - + https://github.com/dotnet/command-line-api - 6daed85086c41a1cd72a97f298f9cfe2beafa3f4 + f6ff2f1a94a58617e744f8fe0d469a2a420a6259 diff --git a/eng/Versions.props b/eng/Versions.props index 6f6ed5f9d6b9..68618fe32ee9 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -39,7 +39,7 @@ 7.0.2 8.0.0-preview.6.23309.7 4.6.0 - 2.0.0-beta4.23319.1 + 2.0.0-beta4.23326.1 1.0.0-preview.6.23206.1 3.2.2146 From 6d1640209527bf0931a9c9a849d594bd82b3d78a Mon Sep 17 00:00:00 2001 From: Marc Paine Date: Mon, 3 Jul 2023 11:18:44 -0700 Subject: [PATCH 07/22] Add missing using statement --- src/Cli/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs index df7a47958b89..38fb0f4b819f 100644 --- a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs +++ b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs @@ -3,6 +3,7 @@ using System.CommandLine; using System.CommandLine.Completions; +using System.CommandLine.Invocation; using System.Reflection; using Microsoft.DotNet.Cli.Utils; using Microsoft.TemplateEngine.Abstractions; From d1822d8f47a028003b42820e5ca6b1a3fa57d9e2 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Mon, 17 Jul 2023 15:11:59 -0700 Subject: [PATCH 08/22] Changed CommandAction to derive of AsynchronousCliAction, since the synchronous Invoke was not called. Removed uses of EnableParseErrorReporting and EnableTypoCorrecti since these were removed from CliConfiguration. Set the Directives on CliRootCommand since CliConfiguration no longer has a local list for Directives. --- .../Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs | 4 +--- .../Microsoft.TemplateEngine.Cli/Commands/ParserFactory.cs | 1 - src/Cli/dotnet-new3/ParserFactory.cs | 1 - src/Cli/dotnet/DotNetCommandFactory.cs | 4 ++-- src/Cli/dotnet/Parser.cs | 7 ++++--- .../dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs | 7 +------ 6 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs index 38fb0f4b819f..20f0b756f3b8 100644 --- a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs +++ b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs @@ -220,7 +220,7 @@ private static void HandleDebugShowConfig(TArgs args, IEngineEnvironmentSettings Reporter.Output.WriteLine(); } - private sealed class CommandAction : CliAction + private sealed class CommandAction : AsynchronousCliAction { private readonly BaseCommand _command; @@ -283,8 +283,6 @@ public override async Task InvokeAsync(ParseResult parseResult, Cancellatio return (int)returnCode; } - - public override int Invoke(ParseResult parseResult) => InvokeAsync(parseResult, CancellationToken.None).GetAwaiter().GetResult(); } } } diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/ParserFactory.cs b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/ParserFactory.cs index 42fd64f9bf0d..9e1a78b02622 100644 --- a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/ParserFactory.cs +++ b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/ParserFactory.cs @@ -15,7 +15,6 @@ internal static CliConfiguration CreateParser(CliCommand command, bool disableHe //.UseParseDirective() //.UseSuggestDirective() { - EnableParseErrorReporting = true, EnablePosixBundling = false }; diff --git a/src/Cli/dotnet-new3/ParserFactory.cs b/src/Cli/dotnet-new3/ParserFactory.cs index d7268b39d3ce..f4a35e57f059 100644 --- a/src/Cli/dotnet-new3/ParserFactory.cs +++ b/src/Cli/dotnet-new3/ParserFactory.cs @@ -18,7 +18,6 @@ internal static CliConfiguration CreateParser(CliCommand command, bool disableHe //.UseParseDirective() //.UseSuggestDirective() { - EnableParseErrorReporting = true, //TODO: discuss with SDK if it is possible to use it. EnablePosixBundling = false }; diff --git a/src/Cli/dotnet/DotNetCommandFactory.cs b/src/Cli/dotnet/DotNetCommandFactory.cs index e2a05b633e3b..1a381e3097f0 100644 --- a/src/Cli/dotnet/DotNetCommandFactory.cs +++ b/src/Cli/dotnet/DotNetCommandFactory.cs @@ -41,9 +41,9 @@ public ICommand Create( private bool TryGetBuiltInCommand(string commandName, out Func commandFunc) { var command = Parser.GetBuiltInCommand(commandName); - if (command != null && command.Action != null) + if (command?.Action is AsynchronousCliAction action) { - commandFunc = (args) => command.Action.InvokeAsync(Parser.Instance.Parse(args)).Result; + commandFunc = (args) => action.InvokeAsync(Parser.Instance.Parse(args)).Result; return true; } commandFunc = null; diff --git a/src/Cli/dotnet/Parser.cs b/src/Cli/dotnet/Parser.cs index 4177436dad3d..5565fb327ebb 100644 --- a/src/Cli/dotnet/Parser.cs +++ b/src/Cli/dotnet/Parser.cs @@ -21,7 +21,10 @@ namespace Microsoft.DotNet.Cli { public static class Parser { - public static readonly CliRootCommand RootCommand = new(); + public static readonly CliRootCommand RootCommand = new() + { + Directives = { new DiagramDirective(), new SuggestDirective() } + }; internal static Dictionary> HelpDescriptionCustomizations = new(); @@ -162,9 +165,7 @@ public static bool TokenPerLine(string tokenToReplace, out IReadOnlyList public static CliConfiguration Instance { get; } = new(ConfigureCommandLine(RootCommand)) { EnableDefaultExceptionHandler = false, - EnableParseErrorReporting = true, EnablePosixBundling = false, - Directives = { new DiagramDirective(), new SuggestDirective() }, ResponseFileTokenReplacer = TokenPerLine }; diff --git a/src/Tests/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs b/src/Tests/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs index de74fa5cf9c0..735c3fee43e9 100644 --- a/src/Tests/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs +++ b/src/Tests/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs @@ -396,16 +396,11 @@ public void It_uses_correct_runtime_help_description(string command) CliConfiguration localCopy = new(sharedConfig.RootCommand) { EnableDefaultExceptionHandler = sharedConfig.EnableDefaultExceptionHandler, - EnableParseErrorReporting = sharedConfig.EnableParseErrorReporting, - EnableTypoCorrections = sharedConfig.EnableTypoCorrections, ResponseFileTokenReplacer = sharedConfig.ResponseFileTokenReplacer, ProcessTerminationTimeout = sharedConfig.ProcessTerminationTimeout, EnablePosixBundling = sharedConfig.EnablePosixBundling, + Output = new StringWriter() }; - localCopy.Directives.Clear(); - localCopy.Directives.AddRange(sharedConfig.Directives); - - localCopy.Output = new StringWriter(); var parseResult = localCopy.Parse(new string[] { command, "-h" }); parseResult.Invoke(); From 1965507cce25c3b926cd56f24394f39c8000d19c Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Mon, 31 Jul 2023 20:44:26 +0000 Subject: [PATCH 09/22] Update dependencies from https://github.com/dotnet/command-line-api build 20230731.1 Microsoft.SourceBuild.Intermediate.command-line-api , System.CommandLine From Version 0.1.430701 -> To Version 0.1.438101 --- eng/Version.Details.xml | 8 ++++---- eng/Versions.props | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 8eba4ffc6f9c..c2ddf5c629ab 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -321,13 +321,13 @@ 3bdcce1d8eebbb3dcdbd2d5d4ea60d470a20eb3c - + https://github.com/dotnet/command-line-api - f6ff2f1a94a58617e744f8fe0d469a2a420a6259 + 67df30a1ac4152e7f6278847b88b8f1ea1492ba7 - + https://github.com/dotnet/command-line-api - f6ff2f1a94a58617e744f8fe0d469a2a420a6259 + 67df30a1ac4152e7f6278847b88b8f1ea1492ba7 diff --git a/eng/Versions.props b/eng/Versions.props index 00cfd55ae6d0..1710bcc0bee3 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -39,7 +39,7 @@ 7.0.2 8.0.0-preview.7.23367.8 4.6.0 - 2.0.0-beta4.23326.1 + 2.0.0-beta4.23381.1 1.0.0-preview.6.23206.1 3.2.2146 From 82f4ac39f67a07807aa54fed4b28fce838e5ec0e Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Mon, 7 Aug 2023 17:05:01 +0000 Subject: [PATCH 10/22] Update dependencies from https://github.com/dotnet/command-line-api build 20230807.1 Microsoft.SourceBuild.Intermediate.command-line-api , System.CommandLine From Version 0.1.430701 -> To Version 0.1.440701 --- eng/Version.Details.xml | 8 ++++---- eng/Versions.props | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index abc2337b21da..0403e7903f5c 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -321,13 +321,13 @@ 7957ef8b5a284b56c40ccc10cb32f251a98dc800 - + https://github.com/dotnet/command-line-api - 67df30a1ac4152e7f6278847b88b8f1ea1492ba7 + a045dd54a4c44723c215d992288160eb1401bb7f - + https://github.com/dotnet/command-line-api - 67df30a1ac4152e7f6278847b88b8f1ea1492ba7 + a045dd54a4c44723c215d992288160eb1401bb7f diff --git a/eng/Versions.props b/eng/Versions.props index abd8b6a30b3e..4dfdf5d8d251 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -42,7 +42,7 @@ 7.0.3 8.0.0-rc.1.23404.3 4.6.0 - 2.0.0-beta4.23381.1 + 2.0.0-beta4.23407.1 1.0.0-preview.6.23403.1 3.2.2146 From ef551fa4ca06d14a21cb278dd98a5b2fa8af78c2 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Tue, 17 Oct 2023 14:25:38 -0700 Subject: [PATCH 11/22] Fixed build error by adding required namespace for AsynchronousCliAction. --- src/Cli/dotnet/DotNetCommandFactory.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Cli/dotnet/DotNetCommandFactory.cs b/src/Cli/dotnet/DotNetCommandFactory.cs index 645775c5206c..22b04fd9df81 100644 --- a/src/Cli/dotnet/DotNetCommandFactory.cs +++ b/src/Cli/dotnet/DotNetCommandFactory.cs @@ -1,6 +1,7 @@ // 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.Invocation; using System.Diagnostics; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.CommandFactory; From 6e207d2e1d46b1240d85dcda530be6c085bf854d Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Tue, 17 Oct 2023 15:44:24 -0700 Subject: [PATCH 12/22] Aligned System.CommandLine versions between Versions.props and Version.Details.xml. Fixed GetValue in TemplateCommandArgs.cs by checking against the new typed generic of CliOption. Adjusted CustomHelpLayout in ParserFactory.cs to match the new Func instead of the previous Action by always returning true to match the previous logic. --- eng/Versions.props | 2 +- .../Commands/create/TemplateCommandArgs.cs | 2 +- src/Cli/dotnet-new3/ParserFactory.cs | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 5a8f4e1eb9f9..b85aa796d7d5 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -42,7 +42,7 @@ 7.0.3 9.0.0-alpha.1.23516.25 4.6.0 - 2.0.0-beta4.23326.1 + 2.0.0-beta4.23407.1 2.0.0-preview.1.23509.2 3.2.2146 diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommandArgs.cs b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommandArgs.cs index 0bedbbf22629..368bbcf6177c 100644 --- a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommandArgs.cs +++ b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommandArgs.cs @@ -115,7 +115,7 @@ public bool TryGetAliasForCanonicalName(string canonicalName, out string? alias) { throw new InvalidOperationException($"Parameter {parameterName} is not defined for {Template.Identity}."); } - if (parameter.Type == ParameterType.Hex && optionResult.Option.ValueType == typeof(long)) + if (parameter.Type == ParameterType.Hex && optionResult.Option is CliOption) { var intValue = (long)optionValue; return $"0x{intValue.ToString("X")}"; diff --git a/src/Cli/dotnet-new3/ParserFactory.cs b/src/Cli/dotnet-new3/ParserFactory.cs index 60a8cf04504e..6116ed16c203 100644 --- a/src/Cli/dotnet-new3/ParserFactory.cs +++ b/src/Cli/dotnet-new3/ParserFactory.cs @@ -52,15 +52,25 @@ static HelpOption CreateCustomHelp() } } - private static IEnumerable> CustomHelpLayout(HelpContext context) + private static IEnumerable> CustomHelpLayout(HelpContext context) { if (context.ParseResult.CommandResult.Command is ICustomHelp custom) { - return custom.CustomHelpLayout(); + foreach (var layout in custom.CustomHelpLayout()) + { + yield return hc => + { + layout(hc); + return true; + }; + } } else { - return HelpBuilder.Default.GetLayout(); + foreach (var layout in HelpBuilder.Default.GetLayout()) + { + yield return layout; + } } } } From 55cf39ab478048e16790550e5a80af71bd5d60d3 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 18 Oct 2023 18:01:25 -0700 Subject: [PATCH 13/22] Added missing newline based on help option output changes in S.CL. --- .../Commands/create/InstantiateCommand.Help.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.Help.cs b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.Help.cs index 8b5f38be95e9..ef71e9bcb602 100644 --- a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.Help.cs +++ b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.Help.cs @@ -455,6 +455,7 @@ private static void WriteCustomInstantiateHelp(HelpContext context, CliCommand c HelpBuilder.Default.CommandArgumentsSection()(context); context.Output.WriteLine(); HelpBuilder.Default.OptionsSection()(context); + context.Output.WriteLine(); HelpBuilder.Default.SubcommandsSection()(context); context.Output.WriteLine(); } From f1444698d4d4d8db58126ee0aa1d8e955ff8f185 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Wed, 25 Oct 2023 18:20:06 -0700 Subject: [PATCH 14/22] It seems that ExactlyOne with a default value would be coerced into ZeroOrOne. Now, it seems the parsing logic doesn't do that, so we need to explicitly set it to ZeroOrOne. --- src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs index 5466d1aa61cd..927b2d05b940 100644 --- a/src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -14,7 +14,7 @@ internal static class SlnCommandParser { HelpName = LocalizableStrings.SolutionArgumentName, Description = LocalizableStrings.SolutionArgumentDescription, - Arity = ArgumentArity.ExactlyOne + Arity = ArgumentArity.ZeroOrOne }.DefaultToCurrentDirectory(); private static readonly CliCommand Command = ConstructCommand(); From 016cb2053c028a0758ccebaa9f5aecde4a53b1e6 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 3 Nov 2023 18:11:29 -0700 Subject: [PATCH 15/22] Added HACKY WORKAROUND for accessing ArgumentResult values when token parsing. Also added DirectiveResult token access. --- .../CommandLineValidationMessages.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs b/src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs index 56c4091b7984..268311e9cc88 100644 --- a/src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs +++ b/src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine.Parsing; +using System.Reflection; namespace Microsoft.DotNet.Cli { @@ -15,9 +16,19 @@ internal static CliToken Token(this SymbolResult symbolResult) OptionResult optionResult => optionResult.IdentifierToken is null ? new CliToken($"--{optionResult.Option.Name}", CliTokenType.Option, optionResult.Option) : optionResult.IdentifierToken, - ArgumentResult argResult => new CliToken(argResult.GetValueOrDefault(), CliTokenType.Argument, argResult.Argument), + ArgumentResult argResult => new CliToken(GetArgResultValue(argResult), CliTokenType.Argument, argResult.Argument), + DirectiveResult dirResult => dirResult.Token, _ => default }; + + // TODO: WE SHOULD NOT NEED TO DO THIS LONGTERM! There seems to be no mechanism currently to get at the raw value of an ArgumentResult without knowing the type you're expecting. + static string GetArgResultValue(ArgumentResult argResult) + { + var methodInfo = argResult.GetType().GetMethod("GetArgumentConversionResult", BindingFlags.Instance | BindingFlags.NonPublic); + var conversionResult = methodInfo.Invoke(argResult, null); + var value = conversionResult.GetType().GetField("Value", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(conversionResult); + return value.ToString(); + } } } } From f0d3b500a5545a1ae47af470b7ab476a851614ef Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Mon, 6 Nov 2023 17:00:32 -0600 Subject: [PATCH 16/22] remove old hack --- .../CommandLineValidationMessages.cs | 22 ---------------- src/Cli/dotnet/ParseResultExtensions.cs | 26 +++++++------------ 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs b/src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs index 268311e9cc88..d0c5555a30d4 100644 --- a/src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs +++ b/src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs @@ -8,27 +8,5 @@ namespace Microsoft.DotNet.Cli { internal static class SymbolResultExtensions { - internal static CliToken Token(this SymbolResult symbolResult) - { - return symbolResult switch - { - CommandResult commandResult => commandResult.IdentifierToken, - OptionResult optionResult => optionResult.IdentifierToken is null ? - new CliToken($"--{optionResult.Option.Name}", CliTokenType.Option, optionResult.Option) - : optionResult.IdentifierToken, - ArgumentResult argResult => new CliToken(GetArgResultValue(argResult), CliTokenType.Argument, argResult.Argument), - DirectiveResult dirResult => dirResult.Token, - _ => default - }; - - // TODO: WE SHOULD NOT NEED TO DO THIS LONGTERM! There seems to be no mechanism currently to get at the raw value of an ArgumentResult without knowing the type you're expecting. - static string GetArgResultValue(ArgumentResult argResult) - { - var methodInfo = argResult.GetType().GetMethod("GetArgumentConversionResult", BindingFlags.Instance | BindingFlags.NonPublic); - var conversionResult = methodInfo.Invoke(argResult, null); - var value = conversionResult.GetType().GetField("Value", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(conversionResult); - return value.ToString(); - } - } } } diff --git a/src/Cli/dotnet/ParseResultExtensions.cs b/src/Cli/dotnet/ParseResultExtensions.cs index 34194f7ad3d3..fb17db99d72f 100644 --- a/src/Cli/dotnet/ParseResultExtensions.cs +++ b/src/Cli/dotnet/ParseResultExtensions.cs @@ -137,22 +137,13 @@ public static string[] GetSubArguments(this string[] args) private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult symbolResult) { - if (symbolResult.Token() == default) + return symbolResult.Tokens switch { - return parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault(); - } - else if (symbolResult.Token().Type.Equals(CliTokenType.Command)) - { - return ((System.CommandLine.Parsing.CommandResult)symbolResult).Command.Name; - } - else if (symbolResult.Token().Type.Equals(CliTokenType.Argument)) - { - return symbolResult.Token().Value; - } - else - { - return string.Empty; - } + [] => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault(), + [{ Type: CliTokenType.Command }, ..] => (symbolResult as System.CommandLine.Parsing.CommandResult).Command.Name, + [{ Type: CliTokenType.Argument, Value: var token }, ..] => token, + _ => string.Empty + }; } public static bool BothArchAndOsOptionsSpecified(this ParseResult parseResult) => @@ -207,8 +198,9 @@ public static IEnumerable GetRunCommandPropertyValues(this ParseResult p private static IEnumerable GetRunPropertyOptions(ParseResult parseResult, bool shorthand) { var optionString = shorthand ? "-p" : "--property"; - var options = parseResult.CommandResult.Children.Where(c => c.Token().Type.Equals(CliTokenType.Option)); - var propertyOptions = options.Where(o => o.Token().Value.Equals(optionString)); + var options = + parseResult.CommandResult.Children.OfType(); + var propertyOptions = options.Where(o => o.Option.Aliases.Contains(optionString)); var propertyValues = propertyOptions.SelectMany(o => o.Tokens.Select(t => t.Value)).ToArray(); return propertyValues; } From c146b96e909ca047ca5bf1eb50f1b5945d055004 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Mon, 6 Nov 2023 17:19:30 -0600 Subject: [PATCH 17/22] fix name comparison --- src/Cli/dotnet/ParseResultExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/dotnet/ParseResultExtensions.cs b/src/Cli/dotnet/ParseResultExtensions.cs index fb17db99d72f..ca14713af742 100644 --- a/src/Cli/dotnet/ParseResultExtensions.cs +++ b/src/Cli/dotnet/ParseResultExtensions.cs @@ -200,7 +200,7 @@ private static IEnumerable GetRunPropertyOptions(ParseResult parseResult var optionString = shorthand ? "-p" : "--property"; var options = parseResult.CommandResult.Children.OfType(); - var propertyOptions = options.Where(o => o.Option.Aliases.Contains(optionString)); + var propertyOptions = options.Where(o => o.Option.Name.Equals(optionString, StringComparison.OrdinalIgnoreCase) || o.Option.Aliases.Contains(optionString, StringComparer.OrdinalIgnoreCase)); var propertyValues = propertyOptions.SelectMany(o => o.Tokens.Select(t => t.Value)).ToArray(); return propertyValues; } From d2ff86e3d140e4bf1806a1e2639ee2e9706a991f Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Mon, 6 Nov 2023 16:49:18 -0800 Subject: [PATCH 18/22] Cleanup from Chet's simplification. --- .../CommandLineValidationMessages.cs | 12 ------------ src/Cli/dotnet/ParseResultExtensions.cs | 12 +++++++----- 2 files changed, 7 insertions(+), 17 deletions(-) delete mode 100644 src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs diff --git a/src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs b/src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs deleted file mode 100644 index d0c5555a30d4..000000000000 --- a/src/Cli/dotnet/CommandLineValidation/CommandLineValidationMessages.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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.Parsing; -using System.Reflection; - -namespace Microsoft.DotNet.Cli -{ - internal static class SymbolResultExtensions - { - } -} diff --git a/src/Cli/dotnet/ParseResultExtensions.cs b/src/Cli/dotnet/ParseResultExtensions.cs index ca14713af742..664c85468555 100644 --- a/src/Cli/dotnet/ParseResultExtensions.cs +++ b/src/Cli/dotnet/ParseResultExtensions.cs @@ -7,6 +7,7 @@ using System.Text.RegularExpressions; using Microsoft.DotNet.Cli.Utils; using static Microsoft.DotNet.Cli.Parser; +using CommandResult = System.CommandLine.Parsing.CommandResult; namespace Microsoft.DotNet.Cli { @@ -140,9 +141,9 @@ private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult return symbolResult.Tokens switch { [] => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault(), - [{ Type: CliTokenType.Command }, ..] => (symbolResult as System.CommandLine.Parsing.CommandResult).Command.Name, + [{ Type: CliTokenType.Command }, ..] => (symbolResult as CommandResult)?.Command.Name, [{ Type: CliTokenType.Argument, Value: var token }, ..] => token, - _ => string.Empty + _ => string.Empty }; } @@ -198,9 +199,10 @@ public static IEnumerable GetRunCommandPropertyValues(this ParseResult p private static IEnumerable GetRunPropertyOptions(ParseResult parseResult, bool shorthand) { var optionString = shorthand ? "-p" : "--property"; - var options = - parseResult.CommandResult.Children.OfType(); - var propertyOptions = options.Where(o => o.Option.Name.Equals(optionString, StringComparison.OrdinalIgnoreCase) || o.Option.Aliases.Contains(optionString, StringComparer.OrdinalIgnoreCase)); + var options = parseResult.CommandResult.Children.OfType(); + var propertyOptions = options.Where(o => + o.Option.Name.Equals(optionString, StringComparison.OrdinalIgnoreCase) || + o.Option.Aliases.Contains(optionString, StringComparer.OrdinalIgnoreCase)); var propertyValues = propertyOptions.SelectMany(o => o.Tokens.Select(t => t.Value)).ToArray(); return propertyValues; } From 7e707b3d88f4e67a91b6faa2a11e2bf5fd8b4191 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Mon, 6 Nov 2023 18:29:15 -0800 Subject: [PATCH 19/22] Fix build by switching on the symbolResult instead of the tokens themselves. There is potential for this simplification to cause issues, but at least the build works now. --- src/Cli/dotnet/ParseResultExtensions.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Cli/dotnet/ParseResultExtensions.cs b/src/Cli/dotnet/ParseResultExtensions.cs index 664c85468555..6e202c0cdad2 100644 --- a/src/Cli/dotnet/ParseResultExtensions.cs +++ b/src/Cli/dotnet/ParseResultExtensions.cs @@ -136,16 +136,12 @@ public static string[] GetSubArguments(this string[] args) return subargs.Concat(runArgs).ToArray(); } - private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult symbolResult) + private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult symbolResult) => symbolResult switch { - return symbolResult.Tokens switch - { - [] => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault(), - [{ Type: CliTokenType.Command }, ..] => (symbolResult as CommandResult)?.Command.Name, - [{ Type: CliTokenType.Argument, Value: var token }, ..] => token, - _ => string.Empty - }; - } + CommandResult commandResult => commandResult.Command.Name, + ArgumentResult argResult => argResult.Tokens.FirstOrDefault()?.Value ?? string.Empty, + _ => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault() + }; public static bool BothArchAndOsOptionsSpecified(this ParseResult parseResult) => (parseResult.HasOption(CommonOptions.ArchitectureOption) || From bdb4668eca9f4468bc4dfb95efb3b966858fdc61 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Tue, 7 Nov 2023 15:01:59 -0800 Subject: [PATCH 20/22] Disable the check in OptionDuplicates_NotAllowed since the fix relies on a new S.CL package version. --- src/Tests/dotnet-watch.Tests/CommandLineOptionsTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Tests/dotnet-watch.Tests/CommandLineOptionsTests.cs b/src/Tests/dotnet-watch.Tests/CommandLineOptionsTests.cs index 17a94bf0ef70..9249061a818b 100644 --- a/src/Tests/dotnet-watch.Tests/CommandLineOptionsTests.cs +++ b/src/Tests/dotnet-watch.Tests/CommandLineOptionsTests.cs @@ -365,7 +365,9 @@ public void OptionDuplicates_NotAllowed(string[] args) Assert.Null(options); Assert.Equal(1, errorCode); - Assert.Equal("", output.ToString()); + // TODO: Re-enable this check when a new version of S.CL is released with this fix in it: + // https://github.com/dotnet/command-line-api/pull/2289 + //Assert.Equal("", output.ToString()); } [Theory] From dac42ad9f93927d8d2f04c4d83045303479f7392 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Tue, 7 Nov 2023 18:21:37 -0800 Subject: [PATCH 21/22] This is functioning (passes tests) of the ParseResultExtensions changes. But contains commented code of other variants. --- src/Cli/dotnet/ParseResultExtensions.cs | 56 +++++++++++++++++++++---- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/src/Cli/dotnet/ParseResultExtensions.cs b/src/Cli/dotnet/ParseResultExtensions.cs index 6e202c0cdad2..2b293d56b002 100644 --- a/src/Cli/dotnet/ParseResultExtensions.cs +++ b/src/Cli/dotnet/ParseResultExtensions.cs @@ -4,6 +4,7 @@ using System.CommandLine; using System.CommandLine.Parsing; using System.Diagnostics; +using System.Reflection; using System.Text.RegularExpressions; using Microsoft.DotNet.Cli.Utils; using static Microsoft.DotNet.Cli.Parser; @@ -136,13 +137,43 @@ public static string[] GetSubArguments(this string[] args) return subargs.Concat(runArgs).ToArray(); } - private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult symbolResult) => symbolResult switch + private static CliToken Token(this SymbolResult symbolResult) { - CommandResult commandResult => commandResult.Command.Name, - ArgumentResult argResult => argResult.Tokens.FirstOrDefault()?.Value ?? string.Empty, - _ => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault() + return symbolResult switch + { + CommandResult commandResult => commandResult.IdentifierToken, + OptionResult optionResult => optionResult.IdentifierToken is null ? + new CliToken($"--{optionResult.Option.Name}", CliTokenType.Option, optionResult.Option) : + optionResult.IdentifierToken, + ArgumentResult argResult => new CliToken(GetArgResultValue(argResult), CliTokenType.Argument, argResult.Argument), + _ => default + }; + + // TODO: WE SHOULD NOT NEED TO DO THIS LONGTERM! There seems to be no mechanism currently to get at the raw value of an ArgumentResult without knowing the type you're expecting. + static string GetArgResultValue(ArgumentResult argResult) + { + var methodInfo = argResult.GetType().GetMethod("GetArgumentConversionResult", BindingFlags.Instance | BindingFlags.NonPublic); + var conversionResult = methodInfo.Invoke(argResult, null); + var value = conversionResult.GetType().GetField("Value", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(conversionResult); + return value.ToString(); + } + } + + private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult symbolResult) => symbolResult.Token() switch + { + null => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault(), + { Type: CliTokenType.Command } => ((CommandResult)symbolResult).Command.Name, + { Type: CliTokenType.Argument } => symbolResult.Token().Value, + _ => string.Empty }; + //private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult symbolResult) => symbolResult switch + //{ + // CommandResult commandResult => commandResult.Command.Name, + // ArgumentResult argResult => argResult.Tokens.FirstOrDefault()?.Value ?? string.Empty, + // _ => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault() + //}; + public static bool BothArchAndOsOptionsSpecified(this ParseResult parseResult) => (parseResult.HasOption(CommonOptions.ArchitectureOption) || parseResult.HasOption(CommonOptions.LongFormArchitectureOption)) && @@ -195,14 +226,23 @@ public static IEnumerable GetRunCommandPropertyValues(this ParseResult p private static IEnumerable GetRunPropertyOptions(ParseResult parseResult, bool shorthand) { var optionString = shorthand ? "-p" : "--property"; - var options = parseResult.CommandResult.Children.OfType(); - var propertyOptions = options.Where(o => - o.Option.Name.Equals(optionString, StringComparison.OrdinalIgnoreCase) || - o.Option.Aliases.Contains(optionString, StringComparer.OrdinalIgnoreCase)); + var options = parseResult.CommandResult.Children.Where(c => c.Token().Type.Equals(CliTokenType.Option)); + var propertyOptions = options.Where(o => o.Token().Value.Equals(optionString)); var propertyValues = propertyOptions.SelectMany(o => o.Tokens.Select(t => t.Value)).ToArray(); return propertyValues; } + //private static IEnumerable GetRunPropertyOptions(ParseResult parseResult, bool shorthand) + //{ + // var optionString = shorthand ? "-p" : "--property"; + // var options = parseResult.CommandResult.Children.OfType(); + // var propertyOptions = options.Where(o => + // o.Option.Name.Equals(optionString, StringComparison.OrdinalIgnoreCase) || + // o.Option.Aliases.Contains(optionString, StringComparer.OrdinalIgnoreCase)); + // var propertyValues = propertyOptions.SelectMany(o => o.Tokens.Select(t => t.Value)).ToArray(); + // return propertyValues; + //} + [Conditional("DEBUG")] public static void HandleDebugSwitch(this ParseResult parseResult) { From 8755e93a67dc07c1c10843a24b46aebf8ddffe9a Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Tue, 7 Nov 2023 18:53:50 -0800 Subject: [PATCH 22/22] Figured out what was causing the test failures with the previous changes. The logic around OptionResult was required or else it would both show the warning and try to use -p as a property (when it should be a project) for the particular failing tests. --- src/Cli/dotnet/ParseResultExtensions.cs | 62 ++++++------------------- 1 file changed, 15 insertions(+), 47 deletions(-) diff --git a/src/Cli/dotnet/ParseResultExtensions.cs b/src/Cli/dotnet/ParseResultExtensions.cs index 2b293d56b002..6e146364872a 100644 --- a/src/Cli/dotnet/ParseResultExtensions.cs +++ b/src/Cli/dotnet/ParseResultExtensions.cs @@ -137,43 +137,13 @@ public static string[] GetSubArguments(this string[] args) return subargs.Concat(runArgs).ToArray(); } - private static CliToken Token(this SymbolResult symbolResult) + private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult symbolResult) => symbolResult switch { - return symbolResult switch - { - CommandResult commandResult => commandResult.IdentifierToken, - OptionResult optionResult => optionResult.IdentifierToken is null ? - new CliToken($"--{optionResult.Option.Name}", CliTokenType.Option, optionResult.Option) : - optionResult.IdentifierToken, - ArgumentResult argResult => new CliToken(GetArgResultValue(argResult), CliTokenType.Argument, argResult.Argument), - _ => default - }; - - // TODO: WE SHOULD NOT NEED TO DO THIS LONGTERM! There seems to be no mechanism currently to get at the raw value of an ArgumentResult without knowing the type you're expecting. - static string GetArgResultValue(ArgumentResult argResult) - { - var methodInfo = argResult.GetType().GetMethod("GetArgumentConversionResult", BindingFlags.Instance | BindingFlags.NonPublic); - var conversionResult = methodInfo.Invoke(argResult, null); - var value = conversionResult.GetType().GetField("Value", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(conversionResult); - return value.ToString(); - } - } - - private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult symbolResult) => symbolResult.Token() switch - { - null => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault(), - { Type: CliTokenType.Command } => ((CommandResult)symbolResult).Command.Name, - { Type: CliTokenType.Argument } => symbolResult.Token().Value, - _ => string.Empty + CommandResult commandResult => commandResult.Command.Name, + ArgumentResult argResult => argResult.Tokens.FirstOrDefault()?.Value ?? string.Empty, + _ => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault() }; - //private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult symbolResult) => symbolResult switch - //{ - // CommandResult commandResult => commandResult.Command.Name, - // ArgumentResult argResult => argResult.Tokens.FirstOrDefault()?.Value ?? string.Empty, - // _ => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault() - //}; - public static bool BothArchAndOsOptionsSpecified(this ParseResult parseResult) => (parseResult.HasOption(CommonOptions.ArchitectureOption) || parseResult.HasOption(CommonOptions.LongFormArchitectureOption)) && @@ -226,22 +196,20 @@ public static IEnumerable GetRunCommandPropertyValues(this ParseResult p private static IEnumerable GetRunPropertyOptions(ParseResult parseResult, bool shorthand) { var optionString = shorthand ? "-p" : "--property"; - var options = parseResult.CommandResult.Children.Where(c => c.Token().Type.Equals(CliTokenType.Option)); - var propertyOptions = options.Where(o => o.Token().Value.Equals(optionString)); + var propertyOptions = parseResult.CommandResult.Children.Where(c => GetOptionTokenOrDefault(c)?.Value.Equals(optionString) ?? false); var propertyValues = propertyOptions.SelectMany(o => o.Tokens.Select(t => t.Value)).ToArray(); return propertyValues; - } - //private static IEnumerable GetRunPropertyOptions(ParseResult parseResult, bool shorthand) - //{ - // var optionString = shorthand ? "-p" : "--property"; - // var options = parseResult.CommandResult.Children.OfType(); - // var propertyOptions = options.Where(o => - // o.Option.Name.Equals(optionString, StringComparison.OrdinalIgnoreCase) || - // o.Option.Aliases.Contains(optionString, StringComparer.OrdinalIgnoreCase)); - // var propertyValues = propertyOptions.SelectMany(o => o.Tokens.Select(t => t.Value)).ToArray(); - // return propertyValues; - //} + static CliToken GetOptionTokenOrDefault(SymbolResult symbolResult) + { + if (symbolResult is not OptionResult optionResult) + { + return null; + } + + return optionResult.IdentifierToken ?? new CliToken($"--{optionResult.Option.Name}", CliTokenType.Option, optionResult.Option); + } + } [Conditional("DEBUG")] public static void HandleDebugSwitch(this ParseResult parseResult)