From e5861a73ad3f08c820319b56b302387a8832ed59 Mon Sep 17 00:00:00 2001 From: Logan Bussell Date: Tue, 30 Aug 2022 10:45:47 -0700 Subject: [PATCH 01/10] Update projects to net7.0 TargetFramework with shared property (#1803) * Update projects to net7.0 TFM with shared property * Only enable trimming for .NET Core * Update ApiCompatibilityApprovalTests baseline (ordering change) Co-authored-by: MichaelSimons --- Directory.Build.props | 1 + global.json | 7 +++-- ...tionBinder_api_is_not_changed.approved.txt | 28 +++++++++---------- ....CommandLine.ApiCompatibility.Tests.csproj | 2 +- .../System.CommandLine.Benchmarks.csproj | 4 +-- ...ystem.CommandLine.DragonFruit.Tests.csproj | 2 +- .../System.CommandLine.Generator.Tests.csproj | 2 +- .../System.CommandLine.Hosting.Tests.csproj | 2 +- ...ndLine.NamingConventionBinder.Tests.csproj | 2 +- .../System.CommandLine.Rendering.Tests.csproj | 2 +- .../EndToEndTestApp/EndToEndTestApp.csproj | 2 +- .../dotnet-suggest.Tests.csproj | 2 +- .../dotnet-suggest.csproj | 2 +- .../System.CommandLine.Tests.csproj | 2 +- .../TestApps/NativeAOT/NativeAOT.csproj | 4 +-- .../TestApps/Trimming/Trimming.csproj | 4 +-- .../System.CommandLine.csproj | 7 +++-- 17 files changed, 40 insertions(+), 35 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index c0c5f79ab5..901c57c7d7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,6 +9,7 @@ $(NoWarn);CS8714;CS8765;CS8600;CS8601;CS8602;CS8603;CS8604 MIT 10.0 + net7.0 diff --git a/global.json b/global.json index 1c6fd2686c..f5bec6115a 100644 --- a/global.json +++ b/global.json @@ -1,12 +1,13 @@ { "tools": { - "dotnet": "6.0.100", + "dotnet": "7.0.100-preview.6.22352.1", "runtimes": { "dotnet": [ - "5.0.10" + "5.0.17", + "6.0.7" ] }, - "xcopy-msbuild": "16.10.0-preview2" + "xcopy-msbuild": "17.1.0" }, "msbuild-sdks": { "Microsoft.DotNet.Arcade.Sdk": "7.0.0-beta.22168.2" diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_NamingConventionBinder_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_NamingConventionBinder_api_is_not_changed.approved.txt index b509ade0c0..e8a6a52be0 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_NamingConventionBinder_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_NamingConventionBinder_api_is_not_changed.approved.txt @@ -3,20 +3,6 @@ public static System.Void AddModelBinder(this System.CommandLine.Binding.BindingContext bindingContext, ModelBinder binder) public static ModelBinder GetOrCreateModelBinder(this System.CommandLine.Binding.BindingContext bindingContext, System.CommandLine.Binding.IValueDescriptor valueDescriptor) public static class CommandHandler - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) - public static System.CommandLine.ICommandHandler Create(Func> action) public static System.CommandLine.ICommandHandler Create(System.Delegate delegate) public static System.CommandLine.ICommandHandler Create(Action action) public static System.CommandLine.ICommandHandler Create(Action action) @@ -68,6 +54,20 @@ public static System.CommandLine.ICommandHandler Create(Func action) public static System.CommandLine.ICommandHandler Create(Func> action) public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) + public static System.CommandLine.ICommandHandler Create(Func> action) public static System.CommandLine.ICommandHandler Create(System.Reflection.MethodInfo method, System.Object target = null) public class ConstructorDescriptor, IMethodDescriptor public System.Collections.Generic.IReadOnlyList ParameterDescriptors { get; } diff --git a/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj b/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj index 30bcd13942..4cc48fde3d 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj +++ b/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + $(TargetFrameworkForNETSDK) false diff --git a/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj b/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj index e54aabc422..185ba62a78 100644 --- a/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj +++ b/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj @@ -9,8 +9,8 @@ false - net461;net5.0;net6.0; - net5.0;net6.0; + net461;net5.0;net6.0;net7.0 + net5.0;net6.0;net7.0 False diff --git a/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj b/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj index 7eee0b3856..e504f7e86f 100644 --- a/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj +++ b/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj @@ -1,6 +1,6 @@  - net6.0 + $(TargetFrameworkForNETSDK) AutoGeneratedProgram true diff --git a/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj b/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj index a423eb1e7a..20f0f410d9 100644 --- a/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj +++ b/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj @@ -1,6 +1,6 @@  - net6.0 + $(TargetFrameworkForNETSDK) $(TargetFrameworks);net462 true true diff --git a/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj b/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj index 328b4e1245..8e2cd6ea40 100644 --- a/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj +++ b/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + $(TargetFrameworkForNETSDK) $(TargetFrameworks);net462 false diff --git a/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj b/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj index 43eb7c29e6..7bff17964a 100644 --- a/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj +++ b/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj @@ -1,6 +1,6 @@  - net6.0 + $(TargetFrameworkForNETSDK) $(TargetFrameworks);net462 10 diff --git a/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj b/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj index 1c116508e3..afd6dc6a46 100644 --- a/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj +++ b/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + $(TargetFrameworkForNETSDK) false diff --git a/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj b/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj index 9a3eb54d35..76add0d5a9 100644 --- a/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj +++ b/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj @@ -6,7 +6,7 @@ Exe - net6.0 + $(TargetFrameworkForNETSDK) diff --git a/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj b/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj index da6abedf0b..f1711a10e1 100644 --- a/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj +++ b/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + $(TargetFrameworkForNETSDK) diff --git a/src/System.CommandLine.Suggest/dotnet-suggest.csproj b/src/System.CommandLine.Suggest/dotnet-suggest.csproj index fd82500868..ce4bda1d6b 100644 --- a/src/System.CommandLine.Suggest/dotnet-suggest.csproj +++ b/src/System.CommandLine.Suggest/dotnet-suggest.csproj @@ -1,7 +1,7 @@  Exe - net6.0 + $(TargetFrameworkForNETSDK) true true dotnet-suggest diff --git a/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj b/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj index c1988ec497..44b5c9fc96 100644 --- a/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj +++ b/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj @@ -1,6 +1,6 @@  - net6.0 + $(TargetFrameworkForNETSDK) $(TargetFrameworks);net462 false diff --git a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj index b0036ed029..cc306fea0d 100644 --- a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj +++ b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj @@ -2,13 +2,13 @@ Exe - net6.0 + $(TargetFrameworkForNETSDK) false - ..\..\..\System.CommandLine\bin\Release\net6.0\System.CommandLine.dll + ..\..\..\System.CommandLine\bin\Release\$(TargetFrameworkForNETSDK)\System.CommandLine.dll diff --git a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj index 6dcf889293..615b0764cf 100644 --- a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj +++ b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + $(TargetFrameworkForNETSDK) enable enable true @@ -10,7 +10,7 @@ - ..\..\..\System.CommandLine\bin\Release\net6.0\System.CommandLine.dll + ..\..\..\System.CommandLine\bin\Release\$(TargetFrameworkForNETSDK)\System.CommandLine.dll diff --git a/src/System.CommandLine/System.CommandLine.csproj b/src/System.CommandLine/System.CommandLine.csproj index 424053a6e8..37115d707f 100644 --- a/src/System.CommandLine/System.CommandLine.csproj +++ b/src/System.CommandLine/System.CommandLine.csproj @@ -3,7 +3,7 @@ true System.CommandLine - net6.0;netstandard2.0 + $(TargetFrameworkForNETSDK);netstandard2.0 enable true 10 @@ -15,9 +15,12 @@ * Test and debug support true + true + + + true true - true From 63106f266e72c92d5c29b17f7dc2a671dc11cfc6 Mon Sep 17 00:00:00 2001 From: Alex Perovich Date: Wed, 31 Aug 2022 19:31:21 -0700 Subject: [PATCH 02/10] Update public pool names --- .vsts-ci.yml | 4 ++-- eng/common/templates/job/source-build.yml | 2 +- eng/common/templates/job/source-index-stage1.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.vsts-ci.yml b/.vsts-ci.yml index 2ca94b5e96..0b39ec13a2 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -38,7 +38,7 @@ stages: # For public or PR jobs, use the hosted pool. For internal jobs use the internal pool. # Will eventually change this to two BYOC pools. ${{ if ne(variables['System.TeamProject'], 'internal') }}: - name: NetCore1ESPool-Public + name: NetCore-Public demands: ImageOverride -equals windows.vs2022.amd64.open ${{ if eq(variables['System.TeamProject'], 'internal') }}: name: NetCore1ESPool-Internal @@ -115,7 +115,7 @@ stages: displayName: Ubuntu pool: ${{ if eq(variables['System.TeamProject'], 'public') }}: - name: NetCore1ESPool-Svc-Public + name: NetCore-Svc-Public demands: ImageOverride -equals 1es-ubuntu-2004-open ${{ if eq(variables['System.TeamProject'], 'internal') }}: name: NetCore1ESPool-Svc-Internal diff --git a/eng/common/templates/job/source-build.yml b/eng/common/templates/job/source-build.yml index 5cd5325d7b..88f6f75a62 100644 --- a/eng/common/templates/job/source-build.yml +++ b/eng/common/templates/job/source-build.yml @@ -46,7 +46,7 @@ jobs: # source-build builds run in Docker, including the default managed platform. pool: ${{ if eq(variables['System.TeamProject'], 'public') }}: - name: NetCore1ESPool-Public + name: NetCore-Public demands: ImageOverride -equals Build.Ubuntu.1804.Amd64.Open ${{ if eq(variables['System.TeamProject'], 'internal') }}: name: NetCore1ESPool-Internal diff --git a/eng/common/templates/job/source-index-stage1.yml b/eng/common/templates/job/source-index-stage1.yml index 4af724eb1a..f6b80407ee 100644 --- a/eng/common/templates/job/source-index-stage1.yml +++ b/eng/common/templates/job/source-index-stage1.yml @@ -24,7 +24,7 @@ jobs: pool: ${{ if eq(variables['System.TeamProject'], 'public') }}: - name: NetCore1ESPool-Public + name: NetCore-Public demands: ImageOverride -equals Build.Server.Amd64.VS2019.Open ${{ if eq(variables['System.TeamProject'], 'internal') }}: name: NetCore1ESPool-Internal From b8cce4856909291ff2e0da993cda0c8866305ef5 Mon Sep 17 00:00:00 2001 From: "Brett V. Forsgren" Date: Thu, 1 Sep 2022 15:29:59 -0600 Subject: [PATCH 03/10] update build urls (#1833) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b96f12e593..5d02012988 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -[![Build Status](https://dev.azure.com/dnceng/public/_apis/build/status/dotnet/command-line-api/command-line-api?branchName=main)](https://dev.azure.com/dnceng/public/_build/latest?definitionId=337&branchName=main) [![Join the chat at https://gitter.im/dotnet/command-line-api](https://badges.gitter.im/dotnet/command-line-api.svg)](https://gitter.im/dotnet/command-line-api?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://dev.azure.com/dnceng-public/public/_apis/build/status/dotnet/command-line-api/command-line-api?branchName=main)](https://dev.azure.com/dnceng-public/public/_build?definitionId=175&branchName=main) [![Join the chat at https://gitter.im/dotnet/command-line-api](https://badges.gitter.im/dotnet/command-line-api.svg)](https://gitter.im/dotnet/command-line-api?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) This repository contains the code for the System.CommandLine libraries and the `dotnet-suggest` global tool. From 4d9cc58be363b1eec05f5ec4457c2a198f79a210 Mon Sep 17 00:00:00 2001 From: Greg Ingram Date: Fri, 2 Sep 2022 18:58:15 -0400 Subject: [PATCH 04/10] Updated indention from an earlier PR cleanup. (#1793) --- src/System.CommandLine.Rendering/TestTerminal.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/System.CommandLine.Rendering/TestTerminal.cs b/src/System.CommandLine.Rendering/TestTerminal.cs index fd85d0737d..e15b9f116f 100644 --- a/src/System.CommandLine.Rendering/TestTerminal.cs +++ b/src/System.CommandLine.Rendering/TestTerminal.cs @@ -78,11 +78,7 @@ public virtual void ResetColor() RecordEvent(new ColorReset()); } - public Region GetRegion() => - new(0, - 0, - Width, - Height); + public Region GetRegion() => new(0, 0, Width, Height); public void Clear() { From eda3d190508a33a84586cf37f4134bbbe19ba446 Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Tue, 6 Sep 2022 00:39:53 -0700 Subject: [PATCH 05/10] Adding proposed fix for FromAmong The behavior of the method now matches its description. --- src/System.CommandLine.Tests/ArgumentTests.cs | 18 ++++++++++++++++++ src/System.CommandLine.Tests/OptionTests.cs | 16 +++++++++++++++- src/System.CommandLine/ArgumentExtensions.cs | 2 ++ src/System.CommandLine/OptionExtensions.cs | 2 ++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/System.CommandLine.Tests/ArgumentTests.cs b/src/System.CommandLine.Tests/ArgumentTests.cs index 51351ef5e1..19ffb3db3f 100644 --- a/src/System.CommandLine.Tests/ArgumentTests.cs +++ b/src/System.CommandLine.Tests/ArgumentTests.cs @@ -765,6 +765,24 @@ public void OnlyTake_can_pass_on_all_tokens_from_a_single_arity_argument_to_anot } } + [Fact] + public void Argument_of_enum_can_limit_enum_members_as_valid_values() + { + var argument = new Argument() + .FromAmong(ConsoleColor.Red.ToString(), ConsoleColor.Green.ToString()); + Command command = new("set-color") + { + argument + }; + + var result = command.Parse("set-color Fuschia"); + + result.Errors + .Select(e => e.Message) + .Should() + .BeEquivalentTo(new[] { $"Argument 'Fuschia' not recognized. Must be one of:\n\t'Red'\n\t'Green'" }); + } + protected override Symbol CreateSymbol(string name) { return new Argument(name); diff --git a/src/System.CommandLine.Tests/OptionTests.cs b/src/System.CommandLine.Tests/OptionTests.cs index f4a7f8a23f..dc3ac47b23 100644 --- a/src/System.CommandLine.Tests/OptionTests.cs +++ b/src/System.CommandLine.Tests/OptionTests.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using FluentAssertions; using System.CommandLine.Parsing; using System.Linq; -using FluentAssertions; using Xunit; namespace System.CommandLine.Tests @@ -370,6 +370,20 @@ public void Option_of_boolean_defaults_to_false_when_not_specified() .Should() .BeFalse(); } + + [Fact] + public void Option_of_enum_can_limit_enum_members_as_valid_values() + { + var option = new Option("--color") + .FromAmong(ConsoleColor.Red.ToString(), ConsoleColor.Green.ToString()); + + var result = option.Parse("--color Fuschia"); + + result.Errors + .Select(e => e.Message) + .Should() + .BeEquivalentTo(new[] { $"Argument 'Fuschia' not recognized. Must be one of:\n\t'Red'\n\t'Green'" }); + } protected override Symbol CreateSymbol(string name) => new Option(name); } diff --git a/src/System.CommandLine/ArgumentExtensions.cs b/src/System.CommandLine/ArgumentExtensions.cs index 3d153dd346..e43d286cd1 100644 --- a/src/System.CommandLine/ArgumentExtensions.cs +++ b/src/System.CommandLine/ArgumentExtensions.cs @@ -76,7 +76,9 @@ public static TArgument FromAmong( params string[] values) where TArgument : Argument { + argument.AllowedValues?.Clear(); argument.AddAllowedValues(values); + argument.Completions.Clear(); argument.Completions.Add(values); return argument; diff --git a/src/System.CommandLine/OptionExtensions.cs b/src/System.CommandLine/OptionExtensions.cs index 79558cf043..d27166f2f4 100644 --- a/src/System.CommandLine/OptionExtensions.cs +++ b/src/System.CommandLine/OptionExtensions.cs @@ -25,7 +25,9 @@ public static TOption FromAmong( params string[] values) where TOption : Option { + option.Argument.AllowedValues?.Clear(); option.Argument.AddAllowedValues(values); + option.Argument.Completions.Clear(); option.Argument.Completions.Add(values); return option; From 1d98a75ce2b109a2d7c18d81fac3f279be095e4e Mon Sep 17 00:00:00 2001 From: Vlada Shubina Date: Mon, 5 Sep 2022 11:50:28 +0200 Subject: [PATCH 06/10] fixed null reference exception in Token operator overload --- src/System.CommandLine/Parsing/Token.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/System.CommandLine/Parsing/Token.cs b/src/System.CommandLine/Parsing/Token.cs index 7b656c9886..9fae4842ac 100644 --- a/src/System.CommandLine/Parsing/Token.cs +++ b/src/System.CommandLine/Parsing/Token.cs @@ -66,7 +66,7 @@ internal Token(string? value, TokenType type, Symbol? symbol, int position) /// The first . /// The second . /// if the objects are equal. - public static bool operator ==(Token left, Token right) => left.Equals(right); + public static bool operator ==(Token? left, Token? right) => left is null ? right is null : left.Equals(right); /// /// Checks if two specified instances have different values. @@ -74,6 +74,7 @@ internal Token(string? value, TokenType type, Symbol? symbol, int position) /// The first . /// The second . /// if the objects are not equal. - public static bool operator !=(Token left, Token right) => !left.Equals(right); + public static bool operator !=(Token? left, Token? right) => left is null ? right is not null : !left.Equals(right); + } } From c0efeb46a4a0ecd40ac72d35cae08020e8f30677 Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Sun, 18 Sep 2022 00:41:28 -0700 Subject: [PATCH 07/10] Localizing required option not provided message There is a slight behavior change for options that have multiple aliases as it will select the longest alias. This is to make it more consistent with how the Name property on the option works. --- ...ommandLine_api_is_not_changed.approved.txt | 1 + .../GlobalOptionTests.cs | 20 +++++++++++++++- .../ParsingValidationTests.cs | 24 +++++++++++++++++++ .../LocalizationResources.cs | 6 +++++ .../Parsing/ParseResultVisitor.cs | 5 ++-- .../Properties/Resources.Designer.cs | 9 +++++++ .../Properties/Resources.resx | 3 +++ .../Properties/xlf/Resources.cs.xlf | 5 ++++ .../Properties/xlf/Resources.de.xlf | 5 ++++ .../Properties/xlf/Resources.es.xlf | 5 ++++ .../Properties/xlf/Resources.fr.xlf | 5 ++++ .../Properties/xlf/Resources.it.xlf | 5 ++++ .../Properties/xlf/Resources.ja.xlf | 5 ++++ .../Properties/xlf/Resources.ko.xlf | 5 ++++ .../Properties/xlf/Resources.pl.xlf | 5 ++++ .../Properties/xlf/Resources.pt-BR.xlf | 5 ++++ .../Properties/xlf/Resources.ru.xlf | 5 ++++ .../Properties/xlf/Resources.tr.xlf | 5 ++++ .../Properties/xlf/Resources.zh-Hans.xlf | 5 ++++ .../Properties/xlf/Resources.zh-Hant.xlf | 5 ++++ 20 files changed, 130 insertions(+), 3 deletions(-) diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt index 4317a19b64..bd25b25078 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt @@ -188,6 +188,7 @@ System.CommandLine public System.String NoArgumentProvided(System.CommandLine.Parsing.SymbolResult symbolResult) public System.String RequiredArgumentMissing(System.CommandLine.Parsing.SymbolResult symbolResult) public System.String RequiredCommandWasNotProvided() + public System.String RequiredOptionWasNotProvided(Option option) public System.String ResponseFileNotFound(System.String filePath) public System.String SuggestionsTokenNotMatched(System.String token) public System.String UnrecognizedArgument(System.String unrecognizedArg, System.Collections.Generic.IReadOnlyCollection allowedValues) diff --git a/src/System.CommandLine.Tests/GlobalOptionTests.cs b/src/System.CommandLine.Tests/GlobalOptionTests.cs index f6884378fb..8a44bf30c7 100644 --- a/src/System.CommandLine.Tests/GlobalOptionTests.cs +++ b/src/System.CommandLine.Tests/GlobalOptionTests.cs @@ -43,7 +43,25 @@ public void When_a_required_global_option_is_omitted_it_results_in_an_error() .ContainSingle() .Which.Message.Should().Be("Option '--i-must-be-set' is required."); } - + + [Fact] + public void When_a_required_global_option_has_multiple_aliases_the_error_message_uses_longest() + { + var rootCommand = new RootCommand(); + var requiredOption = new Option(new[] { "-i", "--i-must-be-set" }) + { + IsRequired = true + }; + rootCommand.AddGlobalOption(requiredOption); + + var result = rootCommand.Parse(""); + + result.Errors + .Should() + .ContainSingle() + .Which.Message.Should().Be("Option '--i-must-be-set' is required."); + } + [Fact] public void When_a_required_global_option_is_present_on_child_of_command_it_was_added_to_it_does_not_result_in_an_error() { diff --git a/src/System.CommandLine.Tests/ParsingValidationTests.cs b/src/System.CommandLine.Tests/ParsingValidationTests.cs index d4645a62a4..e252bb5b3b 100644 --- a/src/System.CommandLine.Tests/ParsingValidationTests.cs +++ b/src/System.CommandLine.Tests/ParsingValidationTests.cs @@ -177,6 +177,30 @@ public void When_a_required_option_is_not_supplied_then_an_error_is_returned() .Be("Option '-x' is required."); } + [Fact] + public void When_a_required_option_has_multiple_aliases_the_error_message_uses_longest() + { + var command = new Command("command") + { + new Option(new[] {"-x", "--xray" }) + { + IsRequired = true + } + }; + + var result = command.Parse(""); + + result.Errors + .Should() + .HaveCount(1) + .And + .Contain(e => e.SymbolResult.Symbol == command) + .Which + .Message + .Should() + .Be("Option '--xray' is required."); + } + [Theory] [InlineData("subcommand -x arg")] [InlineData("-x arg subcommand")] diff --git a/src/System.CommandLine/LocalizationResources.cs b/src/System.CommandLine/LocalizationResources.cs index ee565ef513..0107ce06fe 100644 --- a/src/System.CommandLine/LocalizationResources.cs +++ b/src/System.CommandLine/LocalizationResources.cs @@ -98,6 +98,12 @@ symbolResult is CommandResult public virtual string RequiredCommandWasNotProvided() => GetResourceString(Properties.Resources.RequiredCommandWasNotProvided); + /// + /// Interpolates values into a localized string similar to Option '{0}' is required. + /// + public virtual string RequiredOptionWasNotProvided(Option option) => + GetResourceString(Properties.Resources.RequiredOptionWasNotProvided, option.Aliases.OrderByDescending(x => x.Length).First()); + /// /// Interpolates values into a localized string similar to Argument '{0}' not recognized. Must be one of:{1}. /// diff --git a/src/System.CommandLine/Parsing/ParseResultVisitor.cs b/src/System.CommandLine/Parsing/ParseResultVisitor.cs index ce4502f740..2ed41340ed 100644 --- a/src/System.CommandLine/Parsing/ParseResultVisitor.cs +++ b/src/System.CommandLine/Parsing/ParseResultVisitor.cs @@ -360,8 +360,9 @@ private void ValidateCommandResult() { AddErrorToResult( _innermostCommandResult, - new ParseError($"Option '{option.Aliases.First()}' is required.", - _innermostCommandResult)); + new ParseError( + _rootCommandResult.LocalizationResources.RequiredOptionWasNotProvided(option), + _innermostCommandResult)); } } } diff --git a/src/System.CommandLine/Properties/Resources.Designer.cs b/src/System.CommandLine/Properties/Resources.Designer.cs index 7d3ef75bf9..ddb11c322f 100644 --- a/src/System.CommandLine/Properties/Resources.Designer.cs +++ b/src/System.CommandLine/Properties/Resources.Designer.cs @@ -348,6 +348,15 @@ internal static string RequiredCommandWasNotProvided { } } + /// + /// Looks up a localized string similar to Option '{0}' is required.. + /// + internal static string RequiredOptionWasNotProvided { + get { + return ResourceManager.GetString("RequiredOptionWasNotProvided", resourceCulture); + } + } + /// /// Looks up a localized string similar to Response file not found '{0}'.. /// diff --git a/src/System.CommandLine/Properties/Resources.resx b/src/System.CommandLine/Properties/Resources.resx index f084edc5b0..f0b101ebba 100644 --- a/src/System.CommandLine/Properties/Resources.resx +++ b/src/System.CommandLine/Properties/Resources.resx @@ -231,4 +231,7 @@ Cannot parse argument '{0}' for option '{1}' as expected type '{2}'. + + Option '{0}' is required. + \ No newline at end of file diff --git a/src/System.CommandLine/Properties/xlf/Resources.cs.xlf b/src/System.CommandLine/Properties/xlf/Resources.cs.xlf index 5600551bac..86c81955a1 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.cs.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.cs.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.de.xlf b/src/System.CommandLine/Properties/xlf/Resources.de.xlf index 6095ba13c5..e47d4bc1ee 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.de.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.de.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.es.xlf b/src/System.CommandLine/Properties/xlf/Resources.es.xlf index 9c8605bcfe..2e85b00d2f 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.es.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.es.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.fr.xlf b/src/System.CommandLine/Properties/xlf/Resources.fr.xlf index 26f41492c4..e8afe2a034 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.fr.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.fr.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.it.xlf b/src/System.CommandLine/Properties/xlf/Resources.it.xlf index b69c678224..040135ce41 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.it.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.it.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.ja.xlf b/src/System.CommandLine/Properties/xlf/Resources.ja.xlf index 7396e36bcd..aa9c63dce5 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.ja.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.ja.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.ko.xlf b/src/System.CommandLine/Properties/xlf/Resources.ko.xlf index 3fc016a55a..f5a4950dca 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.ko.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.ko.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.pl.xlf b/src/System.CommandLine/Properties/xlf/Resources.pl.xlf index 3821ee2f6f..b5cf7fd3f0 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.pl.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.pl.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.pt-BR.xlf b/src/System.CommandLine/Properties/xlf/Resources.pt-BR.xlf index 74cc26d0e0..8f7e7af0d2 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.pt-BR.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.pt-BR.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.ru.xlf b/src/System.CommandLine/Properties/xlf/Resources.ru.xlf index f9f6a823e5..6a8b8128f5 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.ru.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.ru.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.tr.xlf b/src/System.CommandLine/Properties/xlf/Resources.tr.xlf index 661bb28dfb..c43d076b4d 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.tr.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.tr.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.zh-Hans.xlf b/src/System.CommandLine/Properties/xlf/Resources.zh-Hans.xlf index e766fb4bb9..ca955abebc 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.zh-Hans.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.zh-Hans.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. diff --git a/src/System.CommandLine/Properties/xlf/Resources.zh-Hant.xlf b/src/System.CommandLine/Properties/xlf/Resources.zh-Hant.xlf index c5f24eac38..3ceabfdb3d 100644 --- a/src/System.CommandLine/Properties/xlf/Resources.zh-Hant.xlf +++ b/src/System.CommandLine/Properties/xlf/Resources.zh-Hant.xlf @@ -162,6 +162,11 @@ Required command was not provided. + + Option '{0}' is required. + Option '{0}' is required. + + Response file not found '{0}'. Response file not found '{0}'. From 759e1bff2a5d6ee889b37657542930803db45657 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 3 Oct 2022 11:29:44 -0700 Subject: [PATCH 08/10] restore Arcade off switch --- Directory.Build.props | 7 +++++++ .../System.CommandLine.ApiCompatibility.Tests.csproj | 2 +- .../System.CommandLine.Benchmarks.csproj | 4 ++-- .../System.CommandLine.DragonFruit.Tests.csproj | 2 +- .../System.CommandLine.Generator.Tests.csproj | 2 +- .../System.CommandLine.Hosting.Tests.csproj | 2 +- .../System.CommandLine.NamingConventionBinder.Tests.csproj | 2 +- .../System.CommandLine.Rendering.Tests.csproj | 2 +- .../EndToEndTestApp/EndToEndTestApp.csproj | 2 +- .../dotnet-suggest.Tests.csproj | 2 +- src/System.CommandLine.Suggest/dotnet-suggest.csproj | 2 +- .../System.CommandLine.Tests.csproj | 2 +- .../TestApps/NativeAOT/NativeAOT.csproj | 4 ++-- .../TestApps/Trimming/Trimming.csproj | 4 ++-- src/System.CommandLine/System.CommandLine.csproj | 4 ++-- 15 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 901c57c7d7..4c1f04a2fb 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,6 +9,13 @@ $(NoWarn);CS8714;CS8765;CS8600;CS8601;CS8602;CS8603;CS8604 MIT 10.0 + + + + net7.0 + + + net7.0 diff --git a/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj b/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj index 4cc48fde3d..a793cc4d64 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj +++ b/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj @@ -1,7 +1,7 @@ - $(TargetFrameworkForNETSDK) + net7.0 false diff --git a/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj b/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj index 185ba62a78..b63e109c2d 100644 --- a/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj +++ b/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj @@ -9,8 +9,8 @@ false - net461;net5.0;net6.0;net7.0 - net5.0;net6.0;net7.0 + net7.0 + net7.0 False diff --git a/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj b/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj index e504f7e86f..81e3895370 100644 --- a/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj +++ b/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj @@ -1,6 +1,6 @@  - $(TargetFrameworkForNETSDK) + net7.0 AutoGeneratedProgram true diff --git a/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj b/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj index 20f0f410d9..402ca8d79a 100644 --- a/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj +++ b/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj @@ -1,6 +1,6 @@  - $(TargetFrameworkForNETSDK) + net7.0 $(TargetFrameworks);net462 true true diff --git a/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj b/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj index 8e2cd6ea40..9e9e3c23f3 100644 --- a/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj +++ b/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj @@ -1,7 +1,7 @@  - $(TargetFrameworkForNETSDK) + net7.0 $(TargetFrameworks);net462 false diff --git a/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj b/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj index 7bff17964a..f6e65164f9 100644 --- a/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj +++ b/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj @@ -1,6 +1,6 @@  - $(TargetFrameworkForNETSDK) + net7.0 $(TargetFrameworks);net462 10 diff --git a/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj b/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj index afd6dc6a46..b07314646e 100644 --- a/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj +++ b/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj @@ -1,7 +1,7 @@ - $(TargetFrameworkForNETSDK) + net7.0 false diff --git a/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj b/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj index 76add0d5a9..186b884e98 100644 --- a/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj +++ b/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj @@ -6,7 +6,7 @@ Exe - $(TargetFrameworkForNETSDK) + net7.0 diff --git a/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj b/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj index f1711a10e1..e22ead7273 100644 --- a/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj +++ b/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj @@ -1,7 +1,7 @@ - $(TargetFrameworkForNETSDK) + net7.0 diff --git a/src/System.CommandLine.Suggest/dotnet-suggest.csproj b/src/System.CommandLine.Suggest/dotnet-suggest.csproj index ce4bda1d6b..8ce30080ed 100644 --- a/src/System.CommandLine.Suggest/dotnet-suggest.csproj +++ b/src/System.CommandLine.Suggest/dotnet-suggest.csproj @@ -1,7 +1,7 @@  Exe - $(TargetFrameworkForNETSDK) + net7.0 true true dotnet-suggest diff --git a/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj b/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj index 44b5c9fc96..63cdef8518 100644 --- a/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj +++ b/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj @@ -1,6 +1,6 @@  - $(TargetFrameworkForNETSDK) + net7.0 $(TargetFrameworks);net462 false diff --git a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj index cc306fea0d..e37a0569f1 100644 --- a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj +++ b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj @@ -2,13 +2,13 @@ Exe - $(TargetFrameworkForNETSDK) + net7.0 false - ..\..\..\System.CommandLine\bin\Release\$(TargetFrameworkForNETSDK)\System.CommandLine.dll + ..\..\..\System.CommandLine\bin\Release\net7.0\System.CommandLine.dll diff --git a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj index 615b0764cf..b0b2fcd130 100644 --- a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj +++ b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj @@ -2,7 +2,7 @@ Exe - $(TargetFrameworkForNETSDK) + net7.0 enable enable true @@ -10,7 +10,7 @@ - ..\..\..\System.CommandLine\bin\Release\$(TargetFrameworkForNETSDK)\System.CommandLine.dll + ..\..\..\System.CommandLine\bin\Release\net7.0\System.CommandLine.dll diff --git a/src/System.CommandLine/System.CommandLine.csproj b/src/System.CommandLine/System.CommandLine.csproj index 37115d707f..05d2847639 100644 --- a/src/System.CommandLine/System.CommandLine.csproj +++ b/src/System.CommandLine/System.CommandLine.csproj @@ -3,7 +3,7 @@ true System.CommandLine - $(TargetFrameworkForNETSDK);netstandard2.0 + net7.0;netstandard2.0 enable true 10 @@ -18,7 +18,7 @@ true - + true true From cf7a86139766696dcbf5f6b542169d580eb9ef3a Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Sun, 2 Oct 2022 17:36:22 -0700 Subject: [PATCH 09/10] When an explicit max width is specified don't override with the terminal's width --- src/System.CommandLine/CommandLineConfiguration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.CommandLine/CommandLineConfiguration.cs b/src/System.CommandLine/CommandLineConfiguration.cs index 4da27d7dad..44672ea41b 100644 --- a/src/System.CommandLine/CommandLineConfiguration.cs +++ b/src/System.CommandLine/CommandLineConfiguration.cs @@ -55,7 +55,7 @@ public CommandLineConfiguration( internal static HelpBuilder DefaultHelpBuilderFactory(BindingContext context, int? requestedMaxWidth = null) { int maxWidth = requestedMaxWidth ?? int.MaxValue; - if (context.Console is SystemConsole systemConsole) + if (requestedMaxWidth is null && context.Console is SystemConsole systemConsole) { maxWidth = systemConsole.GetWindowWidth(); } From c776cd4e906b669b9cce1017fee7d0ba9845d163 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Tue, 4 Oct 2022 12:46:16 -0400 Subject: [PATCH 10/10] Fix IsOptional method for arguments (#1862) * Fix IsOptional method for arguments * Add test * Add shared arg test * Revert "Add test" This reverts commit 5959570332e156b180bfad547bb4fb12ec69356d. * Update src/System.CommandLine.Tests/Help/HelpBuilderTests.cs Co-authored-by: Jon Sequeira --- .../Help/HelpBuilderTests.cs | 31 +++++++++++++++++++ src/System.CommandLine/Help/HelpBuilder.cs | 6 +--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/System.CommandLine.Tests/Help/HelpBuilderTests.cs b/src/System.CommandLine.Tests/Help/HelpBuilderTests.cs index 0ec484549f..dd8914f09a 100644 --- a/src/System.CommandLine.Tests/Help/HelpBuilderTests.cs +++ b/src/System.CommandLine.Tests/Help/HelpBuilderTests.cs @@ -932,7 +932,38 @@ public void Command_arguments_with_default_values_that_are_enumerable_display_pi _console.ToString().Should().Contain(expected); } + [Fact] + public void Command_shared_arguments_with_one_or_more_arity_are_displayed_as_being_required() + { + var arg = new Argument + { + Name = "shared-args", + Arity = ArgumentArity.OneOrMore + }; + + var inner = new Command("inner", "command help") + { + arg + }; + _ = new Command("outer", "command help") + { + inner, + arg + }; + _ = new Command("unused", "command help") + { + arg + }; + _helpBuilder.Write(inner, _console); + + var expected = + $"Usage:{NewLine}" + + $"{_indentation}outer ... inner ..."; + + _console.ToString().Should().Contain(expected); + } + #endregion Arguments #region Options diff --git a/src/System.CommandLine/Help/HelpBuilder.cs b/src/System.CommandLine/Help/HelpBuilder.cs index 4eb16a21ca..6b83e5019a 100644 --- a/src/System.CommandLine/Help/HelpBuilder.cs +++ b/src/System.CommandLine/Help/HelpBuilder.cs @@ -325,12 +325,8 @@ private string FormatArgumentUsage(IReadOnlyList arguments) { StringBuilderPool.Default.ReturnToPool(sb); } - - bool IsMultiParented(Argument a) => - a.FirstParent is not null && a.FirstParent.Next is not null; - + bool IsOptional(Argument argument) => - IsMultiParented(argument) || argument.Arity.MinimumNumberOfValues == 0; }