Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a93456e
Update dependencies from https://github.com/dotnet/command-line-api b…
dotnet-maestro[bot] Jun 8, 2023
27f25dc
Merge branch 'main' of https://github.com/dotnet/sdk into darc-main-a…
Jun 12, 2023
35c9c70
Update dependencies from https://github.com/dotnet/command-line-api b…
dotnet-maestro[bot] Jun 12, 2023
7aa4ec2
Update dependencies from https://github.com/dotnet/command-line-api b…
dotnet-maestro[bot] Jun 12, 2023
0c7a1dd
Update dependencies from https://github.com/dotnet/command-line-api b…
dotnet-maestro[bot] Jun 15, 2023
8167084
Update dependencies from https://github.com/dotnet/command-line-api b…
dotnet-maestro[bot] Jun 19, 2023
b55ba25
Update dependencies from https://github.com/dotnet/command-line-api b…
dotnet-maestro[bot] Jun 26, 2023
90754b0
Merge branch 'main' of https://github.com/dotnet/sdk into darc-main-a…
Jul 3, 2023
6d16402
Add missing using statement
marcpopMSFT Jul 3, 2023
d1822d8
Changed CommandAction to derive of AsynchronousCliAction, since the s…
MiYanni Jul 17, 2023
898ce04
Merge branch 'main' of https://github.com/dotnet/sdk into darc-main-a…
Jul 18, 2023
1965507
Update dependencies from https://github.com/dotnet/command-line-api b…
dotnet-maestro[bot] Jul 31, 2023
d2818e1
Merge branch 'main' into darc-main-a7233ddc-4b19-4004-b583-4a3b720def80
marcpopMSFT Aug 4, 2023
82f4ac3
Update dependencies from https://github.com/dotnet/command-line-api b…
dotnet-maestro[bot] Aug 7, 2023
3a9f452
Merge branch 'main' into darc-main-a7233ddc-4b19-4004-b583-4a3b720def80
dsplaisted Aug 21, 2023
062b7dd
Merge branch 'main' into darc-main-a7233ddc-4b19-4004-b583-4a3b720def80
marek-safar Sep 14, 2023
2783865
Merge branch 'main' into darc-main-a7233ddc-4b19-4004-b583-4a3b720def80
marek-safar Sep 27, 2023
707a22d
Merge branch 'main' into darc-main-a7233ddc-4b19-4004-b583-4a3b720def80
MiYanni Oct 17, 2023
ef551fa
Fixed build error by adding required namespace for AsynchronousCliAct…
MiYanni Oct 17, 2023
c43d997
Merge branch 'darc-main-a7233ddc-4b19-4004-b583-4a3b720def80' of http…
MiYanni Oct 17, 2023
6e207d2
Aligned System.CommandLine versions between Versions.props and Versio…
MiYanni Oct 17, 2023
55cf39a
Added missing newline based on help option output changes in S.CL.
MiYanni Oct 19, 2023
f144469
It seems that ExactlyOne with a default value would be coerced into Z…
MiYanni Oct 26, 2023
016cb20
Added HACKY WORKAROUND for accessing ArgumentResult values when token…
MiYanni Nov 4, 2023
f0d3b50
remove old hack
baronfel Nov 6, 2023
c146b96
fix name comparison
baronfel Nov 6, 2023
41f78d5
Remove old System.CommandLine code that has a more natural expression…
MiYanni Nov 7, 2023
d2ff86e
Cleanup from Chet's simplification.
MiYanni Nov 7, 2023
7e707b3
Fix build by switching on the symbolResult instead of the tokens them…
MiYanni Nov 7, 2023
bdb4668
Disable the check in OptionDuplicates_NotAllowed since the fix relies…
MiYanni Nov 7, 2023
dac42ad
This is functioning (passes tests) of the ParseResultExtensions chang…
MiYanni Nov 8, 2023
8755e93
Figured out what was causing the test failures with the previous chan…
MiYanni Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@
<Sha>b87a6345475b20f4f27e3915752b5866f8bec72a</Sha>
<SourceBuild RepoName="roslyn-analyzers" ManagedOnly="true" />
</Dependency>
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.23307.1">
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.23407.1">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
<Sha>a045dd54a4c44723c215d992288160eb1401bb7f</Sha>
</Dependency>
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.430701">
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.440701">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
<Sha>a045dd54a4c44723c215d992288160eb1401bb7f</Sha>
<SourceBuild RepoName="command-line-api" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-externals" Version="9.0.0-alpha.1.23509.2">
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<SystemTextJsonVersion>7.0.3</SystemTextJsonVersion>
<SystemReflectionMetadataLoadContextVersion>9.0.0-alpha.1.23516.25</SystemReflectionMetadataLoadContextVersion>
<SystemManagementPackageVersion>4.6.0</SystemManagementPackageVersion>
<SystemCommandLineVersion>2.0.0-beta4.23307.1</SystemCommandLineVersion>
<SystemCommandLineVersion>2.0.0-beta4.23407.1</SystemCommandLineVersion>
<MicrosoftDeploymentDotNetReleasesVersion>2.0.0-preview.1.23509.2</MicrosoftDeploymentDotNetReleasesVersion>
<MicrosoftVisualStudioSetupConfigurationInteropVersion>3.2.2146</MicrosoftVisualStudioSetupConfigurationInteropVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -219,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<TArgs> _command;

Expand Down Expand Up @@ -282,8 +283,6 @@ public override async Task<int> InvokeAsync(ParseResult parseResult, Cancellatio

return (int)returnCode;
}

public override int Invoke(ParseResult parseResult) => InvokeAsync(parseResult, CancellationToken.None).GetAwaiter().GetResult();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ internal static CliConfiguration CreateParser(CliCommand command, bool disableHe
//.UseParseDirective()
//.UseSuggestDirective()
{
EnableParseErrorReporting = true,
EnablePosixBundling = false
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity why was this newline needed? Did formatting change upstream or something?

Copy link
Member

@MiYanni MiYanni Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did. The help output logic was changed and normalized. As you can see, previously, every other section here had an added WriteLine added to it except this one. It was likely being added (by accident) in the previous versions of S.CL.

I had to add it here so that the tests for checking help output passed and remained the same as expected.

HelpBuilder.Default.SubcommandsSection()(context);
context.Output.WriteLine();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<long>)
{
var intValue = (long)optionValue;
return $"0x{intValue.ToString("X")}";
Expand Down
17 changes: 13 additions & 4 deletions src/Cli/dotnet-new3/ParserFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -53,15 +52,25 @@ static HelpOption CreateCustomHelp()
}
}

private static IEnumerable<Action<HelpContext>> CustomHelpLayout(HelpContext context)
private static IEnumerable<Func<HelpContext, bool>> 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;
}
}
}
}
Expand Down

This file was deleted.

5 changes: 3 additions & 2 deletions src/Cli/dotnet/DotNetCommandFactory.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,9 +38,9 @@ public ICommand Create(
private bool TryGetBuiltInCommand(string commandName, out Func<string[], int> 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;
Expand Down
38 changes: 18 additions & 20 deletions src/Cli/dotnet/ParseResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
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;
using CommandResult = System.CommandLine.Parsing.CommandResult;

namespace Microsoft.DotNet.Cli
{
Expand Down Expand Up @@ -135,25 +137,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
{
if (symbolResult.Token() == default)
{
return parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault<string>();
}
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;
}
}
CommandResult commandResult => commandResult.Command.Name,
ArgumentResult argResult => argResult.Tokens.FirstOrDefault()?.Value ?? string.Empty,
_ => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault<string>()
};

public static bool BothArchAndOsOptionsSpecified(this ParseResult parseResult) =>
(parseResult.HasOption(CommonOptions.ArchitectureOption) ||
Expand Down Expand Up @@ -207,10 +196,19 @@ public static IEnumerable<string> GetRunCommandPropertyValues(this ParseResult p
private static IEnumerable<string> 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;

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")]
Expand Down
7 changes: 4 additions & 3 deletions src/Cli/dotnet/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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<CliOption, Dictionary<CliCommand, string>> HelpDescriptionCustomizations = new();

Expand Down Expand Up @@ -162,9 +165,7 @@ public static bool TokenPerLine(string tokenToReplace, out IReadOnlyList<string>
public static CliConfiguration Instance { get; } = new(ConfigureCommandLine(RootCommand))
{
EnableDefaultExceptionHandler = false,
EnableParseErrorReporting = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we remove the error reporting here and in the other place? S.CL uses this for reporting parse errors in a nice way - I'm actually pretty confused why our tests pass with such a large change!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature was changed and this property no longer exists on this class. There is a discussion here that you responded to. This concept is bound to the ParseErrorAction now. From my understanding, it isn't a thing you turn on/off, but the type of action returned when a parsing error occurs. It is actually one of the things I've made a PR for, as there was a problem with a stray newline in its output: dotnet/command-line-api#2289

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow I completely forgot about both of those things 😅

Thank you for the reminder, and the explanation! All good from my end now.

EnablePosixBundling = false,
Directives = { new DiagramDirective(), new SuggestDirective() },
ResponseFileTokenReplacer = TokenPerLine
};

Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 1 addition & 6 deletions src/Tests/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,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();
Expand Down
4 changes: 3 additions & 1 deletion src/Tests/dotnet-watch.Tests/CommandLineOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down