Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[main] Update dependencies from dotnet/command-line-api (#29131)" #33146

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -321,13 +321,13 @@
<Sha>2f0301ef59624a72fb00f7fd92caa50be03f277d</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.22564.1">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
<Sha>8374d5fca634a93458c84414b1604c12f765d1ab</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.356401">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
<Sha>8374d5fca634a93458c84414b1604c12f765d1ab</Sha>
<SourceBuild RepoName="command-line-api" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-externals" Version="8.0.0-alpha.1.23305.2">
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<SystemTextJsonVersion>7.0.2</SystemTextJsonVersion>
<SystemReflectionMetadataLoadContextVersion>8.0.0-preview.6.23308.17</SystemReflectionMetadataLoadContextVersion>
<SystemManagementPackageVersion>4.6.0</SystemManagementPackageVersion>
<SystemCommandLineVersion>2.0.0-beta4.23307.1</SystemCommandLineVersion>
<SystemCommandLineVersion>2.0.0-beta4.22564.1</SystemCommandLineVersion>
<MicrosoftDeploymentDotNetReleasesVersion>1.0.0-preview.6.23206.1</MicrosoftDeploymentDotNetReleasesVersion>
<MicrosoftVisualStudioSetupConfigurationInteropVersion>3.2.2146</MicrosoftVisualStudioSetupConfigurationInteropVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void Run(Func<ISuppressionEngine, ISuppressableLog> logFactory,
bool enableRuleAttributesMustMatch,
string[]? excludeAttributesFiles,
bool enableRuleCannotChangeParameterName,
string? packagePath,
string packagePath,
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look right.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is a strict revert of the prior change.

Copy link
Member

@ViktorHofer ViktorHofer Jun 9, 2023

Choose a reason for hiding this comment

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

Then the state before the command line api change was made, was incorrect. Please revert this change as we accept a nullable package path string in PackageValidation (and later throw).

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, this is currently blocking codeflow to installer and we don't want to delay further. It'll come back with the revert of the revert.

bool runApiCompat,
bool enableStrictModeForCompatibleTfms,
bool enableStrictModeForCompatibleFrameworksInPackage,
Expand Down
355 changes: 159 additions & 196 deletions src/ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Program.cs

Large diffs are not rendered by default.

36 changes: 20 additions & 16 deletions src/BlazorWasmSdk/Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.Parsing;
using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;
Expand All @@ -14,22 +16,23 @@ internal static class Program
{
public static int Main(string[] args)
{
CliRootCommand rootCommand = new();
CliCommand brotli = new("brotli");
var rootCommand = new RootCommand();
var brotli = new Command("brotli");

CliOption<CompressionLevel> compressionLevelOption = new("-c")
var compressionLevelOption = new Option<CompressionLevel>(
"-c",
defaultValueFactory: () => CompressionLevel.SmallestSize,
description: "System.IO.Compression.CompressionLevel for the Brotli compression algorithm.");
var sourcesOption = new Option<List<string>>(
"-s",
description: "A list of files to compress.")
{
DefaultValueFactory = _ => CompressionLevel.SmallestSize,
Description = "System.IO.Compression.CompressionLevel for the Brotli compression algorithm.",
};
CliOption<List<string>> sourcesOption = new("-s")
{
Description = "A list of files to compress.",
AllowMultipleArgumentsPerToken = false
};
CliOption<List<string>> outputsOption = new("-o")
var outputsOption = new Option<List<string>>(
"-o",
"The filenames to output the compressed file to.")
{
Description = "The filenames to output the compressed file to.",
AllowMultipleArgumentsPerToken = false
};

Expand All @@ -39,11 +42,12 @@ public static int Main(string[] args)

rootCommand.Add(brotli);

brotli.SetAction((ParseResult parseResult) =>
brotli.SetHandler((InvocationContext context) =>
{
var c = parseResult.GetValue(compressionLevelOption);
var s = parseResult.GetValue(sourcesOption);
var o = parseResult.GetValue(outputsOption);
var parseResults = context.ParseResult;
var c = parseResults.GetValue(compressionLevelOption);
var s = parseResults.GetValue(sourcesOption);
var o = parseResults.GetValue(outputsOption);

Parallel.For(0, s.Count, i =>
{
Expand All @@ -65,7 +69,7 @@ public static int Main(string[] args)
});
});

return rootCommand.Parse(args).Invoke();
return rootCommand.InvokeAsync(args).Result;
}
}
}
138 changes: 58 additions & 80 deletions src/BuiltInTools/dotnet-watch/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.IO;
using System.CommandLine.Invocation;
using System.Linq;

using Microsoft.AspNetCore.Authentication;
using Microsoft.DotNet.Watcher.Tools;
using Microsoft.Extensions.Tools.Internal;

Expand Down Expand Up @@ -75,131 +77,112 @@ dotnet watch test
public required IReadOnlyList<string> RemainingArguments { get; init; }
public RunCommandLineOptions? RunOptions { get; init; }

public static CommandLineOptions? Parse(string[] args, IReporter reporter, out int errorCode, TextWriter? output = null, TextWriter? error = null)
public static CommandLineOptions? Parse(string[] args, IReporter reporter, out int errorCode, System.CommandLine.IConsole? console = null)
{
var quietOption = new CliOption<bool>("--quiet", "-q")
{
Description = "Suppresses all output except warnings and errors"
};
var quietOption = new Option<bool>(new[] { "--quiet", "-q" }, "Suppresses all output except warnings and errors");
var verboseOption = new Option<bool>(new[] { "--verbose", "-v" }, "Show verbose output");

var verboseOption = new CliOption<bool>("--verbose", "-v")
verboseOption.AddValidator(v =>
{
Description = "Show verbose output"
};

verboseOption.Validators.Add(v =>
{
if (v.GetResult(quietOption) is not null && v.GetResult(verboseOption) is not null)
if (v.FindResultFor(quietOption) is not null && v.FindResultFor(verboseOption) is not null)
{
v.AddError(Resources.Error_QuietAndVerboseSpecified);
v.ErrorMessage = Resources.Error_QuietAndVerboseSpecified;
}
});

var listOption = new CliOption<bool>("--list") { Description = "Lists all discovered files without starting the watcher." };
var shortProjectOption = new CliOption<string>("-p") { Description = "The project to watch.", Hidden = true };
var longProjectOption = new CliOption<string>("--project") { Description = "The project to watch" };
var listOption = new Option<bool>("--list", "Lists all discovered files without starting the watcher.");
var shortProjectOption = new Option<string>("-p", "The project to watch.") { IsHidden = true };
var longProjectOption = new Option<string>("--project", "The project to watch");

// launch profile used by dotnet-watch
var launchProfileWatchOption = new CliOption<string>(LaunchProfileOptionName, "-lp")
{
Description = "The launch profile to start the project with (case-sensitive)."
};
var noLaunchProfileWatchOption = new CliOption<bool>(NoLaunchProfileOptionName)
{
Description = "Do not attempt to use launchSettings.json to configure the application."
};
var launchProfileWatchOption = new Option<string>(new[] { "-lp", LaunchProfileOptionName }, "The launch profile to start the project with (case-sensitive).");
var noLaunchProfileWatchOption = new Option<bool>(new[] { NoLaunchProfileOptionName }, "Do not attempt to use launchSettings.json to configure the application.");

// launch profile used by dotnet-run
var launchProfileRunOption = new CliOption<string>(LaunchProfileOptionName, "-lp") { Hidden = true };
var noLaunchProfileRunOption = new CliOption<bool>(NoLaunchProfileOptionName) { Hidden = true };
var launchProfileRunOption = new Option<string>(new[] { "-lp", LaunchProfileOptionName }) { IsHidden = true };
var noLaunchProfileRunOption = new Option<bool>(new[] { NoLaunchProfileOptionName }) { IsHidden = true };

var targetFrameworkOption = new CliOption<string>("--framework", "-f")
{
Description = "The target framework to run for. The target framework must also be specified in the project file."
};
var propertyOption = new CliOption<string[]>("--property")
{
Description = "Properties to be passed to MSBuild."
};
var targetFrameworkOption = new Option<string>(new[] { "-f", "--framework" }, "The target framework to run for. The target framework must also be specified in the project file.");
var propertyOption = new Option<string[]>(new[] { "--property" }, "Properties to be passed to MSBuild.");

propertyOption.Validators.Add(v =>
propertyOption.AddValidator(v =>
{
var invalidProperty = v.GetValue(propertyOption)?.FirstOrDefault(
property => !(property.IndexOf('=') is > 0 and var index && index < property.Length - 1 && property[..index].Trim().Length > 0));

if (invalidProperty != null)
{
v.AddError($"Invalid property format: '{invalidProperty}'. Expected 'name=value'.");
v.ErrorMessage = $"Invalid property format: '{invalidProperty}'. Expected 'name=value'.";
}
});

var noHotReloadOption = new CliOption<bool>("--no-hot-reload") { Description = "Suppress hot reload for supported apps." };
var nonInteractiveOption = new CliOption<bool>("--non-interactive")
{
Description = "Runs dotnet-watch in non-interactive mode. This option is only supported when running with Hot Reload enabled. " +
"Use this option to prevent console input from being captured."
};
var noHotReloadOption = new Option<bool>("--no-hot-reload", "Suppress hot reload for supported apps.");
var nonInteractiveOption = new Option<bool>(
"--non-interactive",
"Runs dotnet-watch in non-interactive mode. This option is only supported when running with Hot Reload enabled. " +
"Use this option to prevent console input from being captured.");

var remainingWatchArgs = new CliArgument<string[]>("forwardedArgs") { Description = "Arguments to pass to the child dotnet process." };
var remainingRunArgs = new CliArgument<string[]>("remainingRunArgs");
var remainingWatchArgs = new Argument<string[]>("forwardedArgs", "Arguments to pass to the child dotnet process.");
var remainingRunArgs = new Argument<string[]>(name: null);

var runCommand = new CliCommand("run") { Hidden = true };
var rootCommand = new CliRootCommand(Description);
AddSymbols(runCommand);
AddSymbols(rootCommand);
var runCommand = new Command("run") { IsHidden = true };
var rootCommand = new RootCommand(Description);
addOptions(runCommand);
addOptions(rootCommand);

void AddSymbols(CliCommand command)
void addOptions(Command command)
{
command.Options.Add(quietOption);
command.Options.Add(verboseOption);
command.Options.Add(noHotReloadOption);
command.Options.Add(nonInteractiveOption);
command.Options.Add(longProjectOption);
command.Options.Add(shortProjectOption);
command.Add(quietOption);
command.Add(verboseOption);
command.Add(noHotReloadOption);
command.Add(nonInteractiveOption);
command.Add(longProjectOption);
command.Add(shortProjectOption);

if (command == runCommand)
{
command.Options.Add(launchProfileRunOption);
command.Options.Add(noLaunchProfileRunOption);
command.Add(launchProfileRunOption);
command.Add(noLaunchProfileRunOption);
}
else
{
command.Options.Add(launchProfileWatchOption);
command.Options.Add(noLaunchProfileWatchOption);
command.Add(launchProfileWatchOption);
command.Add(noLaunchProfileWatchOption);
}

command.Options.Add(targetFrameworkOption);
command.Options.Add(propertyOption);
command.Add(targetFrameworkOption);
command.Add(propertyOption);

command.Options.Add(listOption);
command.Add(listOption);

if (command == runCommand)
{
command.Arguments.Add(remainingRunArgs);
command.Add(remainingRunArgs);
}
else
{
command.Subcommands.Add(runCommand);
command.Arguments.Add(remainingWatchArgs);
command.Add(runCommand);
command.Add(remainingWatchArgs);
}
};

CommandLineOptions? options = null;

runCommand.SetAction(parseResult =>
runCommand.SetHandler(context =>
{
RootHandler(parseResult, new()
RootHandler(context, new()
{
LaunchProfileName = parseResult.GetValue(launchProfileRunOption),
NoLaunchProfile = parseResult.GetValue(noLaunchProfileRunOption),
RemainingArguments = parseResult.GetValue(remainingRunArgs) ?? Array.Empty<string>(),
LaunchProfileName = context.ParseResult.GetValue(launchProfileRunOption),
NoLaunchProfile = context.ParseResult.GetValue(noLaunchProfileRunOption),
RemainingArguments = context.ParseResult.GetValue(remainingRunArgs),
});
});

rootCommand.SetAction(parseResult => RootHandler(parseResult, runOptions: null));
rootCommand.SetHandler(context => RootHandler(context, runOptions: null));

void RootHandler(ParseResult parseResults, RunCommandLineOptions? runOptions)
void RootHandler(InvocationContext context, RunCommandLineOptions? runOptions)
{
var parseResults = context.ParseResult;
var projectValue = parseResults.GetValue(longProjectOption);
if (string.IsNullOrEmpty(projectValue))
{
Expand All @@ -224,17 +207,12 @@ void RootHandler(ParseResult parseResults, RunCommandLineOptions? runOptions)
TargetFramework = parseResults.GetValue(targetFrameworkOption),
BuildProperties = parseResults.GetValue(propertyOption)?
.Select(p => (p[..p.IndexOf('=')].Trim(), p[(p.IndexOf('=') + 1)..])).ToArray(),
RemainingArguments = parseResults.GetValue(remainingWatchArgs) ?? Array.Empty<string>(),
RemainingArguments = parseResults.GetValue(remainingWatchArgs),
RunOptions = runOptions,
};
}

errorCode = new CliConfiguration(rootCommand)
{
Output = output ?? Console.Out,
Error = error ?? Console.Error
}.Invoke(args);

errorCode = rootCommand.Invoke(args, console);
return options;
}

Expand Down
34 changes: 0 additions & 34 deletions src/Cli/Microsoft.DotNet.Cli.Utils/Extensions/StringExtensions.cs

This file was deleted.

Loading