Skip to content

Commit 6483a69

Browse files
authored
Revert "Revert "[main] Update dependencies from dotnet/command-line-api (#29131)"" (#33157)
1 parent 874e01f commit 6483a69

File tree

191 files changed

+3371
-3062
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+3371
-3062
lines changed

eng/Version.Details.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,13 @@
321321
<Sha>eae093b037d5a3a80ff12232e7644fc1a8378b77</Sha>
322322
<SourceBuild RepoName="roslyn-analyzers" ManagedOnly="true" />
323323
</Dependency>
324-
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.22564.1">
324+
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.23307.1">
325325
<Uri>https://github.com/dotnet/command-line-api</Uri>
326-
<Sha>8374d5fca634a93458c84414b1604c12f765d1ab</Sha>
326+
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
327327
</Dependency>
328-
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.356401">
328+
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.430701">
329329
<Uri>https://github.com/dotnet/command-line-api</Uri>
330-
<Sha>8374d5fca634a93458c84414b1604c12f765d1ab</Sha>
330+
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
331331
<SourceBuild RepoName="command-line-api" ManagedOnly="true" />
332332
</Dependency>
333333
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-externals" Version="8.0.0-alpha.1.23326.1">

eng/Versions.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<SystemTextJsonVersion>7.0.2</SystemTextJsonVersion>
4040
<SystemReflectionMetadataLoadContextVersion>8.0.0-preview.7.23329.8</SystemReflectionMetadataLoadContextVersion>
4141
<SystemManagementPackageVersion>4.6.0</SystemManagementPackageVersion>
42-
<SystemCommandLineVersion>2.0.0-beta4.22564.1</SystemCommandLineVersion>
42+
<SystemCommandLineVersion>2.0.0-beta4.23307.1</SystemCommandLineVersion>
4343
<MicrosoftDeploymentDotNetReleasesVersion>1.0.0-preview.6.23206.1</MicrosoftDeploymentDotNetReleasesVersion>
4444
<MicrosoftVisualStudioSetupConfigurationInteropVersion>3.2.2146</MicrosoftVisualStudioSetupConfigurationInteropVersion>
4545
</PropertyGroup>

src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidatePackage.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void Run(Func<ISuppressionEngine, ISuppressableLog> logFactory,
2222
bool enableRuleAttributesMustMatch,
2323
string[]? excludeAttributesFiles,
2424
bool enableRuleCannotChangeParameterName,
25-
string packagePath,
25+
string? packagePath,
2626
bool runApiCompat,
2727
bool enableStrictModeForCompatibleTfms,
2828
bool enableStrictModeForCompatibleFrameworksInPackage,

src/ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Program.cs

+196-159
Large diffs are not rendered by default.

src/BlazorWasmSdk/Tool/Program.cs

+16-20
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.CommandLine;
7-
using System.CommandLine.Invocation;
8-
using System.CommandLine.Parsing;
97
using System.IO;
108
using System.IO.Compression;
119
using System.Threading.Tasks;
@@ -16,23 +14,22 @@ internal static class Program
1614
{
1715
public static int Main(string[] args)
1816
{
19-
var rootCommand = new RootCommand();
20-
var brotli = new Command("brotli");
17+
CliRootCommand rootCommand = new();
18+
CliCommand brotli = new("brotli");
2119

22-
var compressionLevelOption = new Option<CompressionLevel>(
23-
"-c",
24-
defaultValueFactory: () => CompressionLevel.SmallestSize,
25-
description: "System.IO.Compression.CompressionLevel for the Brotli compression algorithm.");
26-
var sourcesOption = new Option<List<string>>(
27-
"-s",
28-
description: "A list of files to compress.")
20+
CliOption<CompressionLevel> compressionLevelOption = new("-c")
2921
{
22+
DefaultValueFactory = _ => CompressionLevel.SmallestSize,
23+
Description = "System.IO.Compression.CompressionLevel for the Brotli compression algorithm.",
24+
};
25+
CliOption<List<string>> sourcesOption = new("-s")
26+
{
27+
Description = "A list of files to compress.",
3028
AllowMultipleArgumentsPerToken = false
3129
};
32-
var outputsOption = new Option<List<string>>(
33-
"-o",
34-
"The filenames to output the compressed file to.")
30+
CliOption<List<string>> outputsOption = new("-o")
3531
{
32+
Description = "The filenames to output the compressed file to.",
3633
AllowMultipleArgumentsPerToken = false
3734
};
3835

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

4340
rootCommand.Add(brotli);
4441

45-
brotli.SetHandler((InvocationContext context) =>
42+
brotli.SetAction((ParseResult parseResult) =>
4643
{
47-
var parseResults = context.ParseResult;
48-
var c = parseResults.GetValue(compressionLevelOption);
49-
var s = parseResults.GetValue(sourcesOption);
50-
var o = parseResults.GetValue(outputsOption);
44+
var c = parseResult.GetValue(compressionLevelOption);
45+
var s = parseResult.GetValue(sourcesOption);
46+
var o = parseResult.GetValue(outputsOption);
5147

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

72-
return rootCommand.InvokeAsync(args).Result;
68+
return rootCommand.Parse(args).Invoke();
7369
}
7470
}
7571
}

src/BuiltInTools/dotnet-watch/CommandLineOptions.cs

+80-58
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
using System;
66
using System.Collections.Generic;
77
using System.CommandLine;
8-
using System.CommandLine.Invocation;
8+
using System.IO;
99
using System.Linq;
10-
11-
using Microsoft.AspNetCore.Authentication;
1210
using Microsoft.DotNet.Watcher.Tools;
1311
using Microsoft.Extensions.Tools.Internal;
1412

@@ -76,112 +74,131 @@ dotnet watch test
7674
public required IReadOnlyList<string> RemainingArguments { get; init; }
7775
public RunCommandLineOptions? RunOptions { get; init; }
7876

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

84-
verboseOption.AddValidator(v =>
84+
var verboseOption = new CliOption<bool>("--verbose", "-v")
8585
{
86-
if (v.FindResultFor(quietOption) is not null && v.FindResultFor(verboseOption) is not null)
86+
Description = "Show verbose output"
87+
};
88+
89+
verboseOption.Validators.Add(v =>
90+
{
91+
if (v.GetResult(quietOption) is not null && v.GetResult(verboseOption) is not null)
8792
{
88-
v.ErrorMessage = Resources.Error_QuietAndVerboseSpecified;
93+
v.AddError(Resources.Error_QuietAndVerboseSpecified);
8994
}
9095
});
9196

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

96101
// launch profile used by dotnet-watch
97-
var launchProfileWatchOption = new Option<string>(new[] { "-lp", LaunchProfileOptionName }, "The launch profile to start the project with (case-sensitive).");
98-
var noLaunchProfileWatchOption = new Option<bool>(new[] { NoLaunchProfileOptionName }, "Do not attempt to use launchSettings.json to configure the application.");
102+
var launchProfileWatchOption = new CliOption<string>(LaunchProfileOptionName, "-lp")
103+
{
104+
Description = "The launch profile to start the project with (case-sensitive)."
105+
};
106+
var noLaunchProfileWatchOption = new CliOption<bool>(NoLaunchProfileOptionName)
107+
{
108+
Description = "Do not attempt to use launchSettings.json to configure the application."
109+
};
99110

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

104-
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.");
105-
var propertyOption = new Option<string[]>(new[] { "--property" }, "Properties to be passed to MSBuild.");
115+
var targetFrameworkOption = new CliOption<string>("--framework", "-f")
116+
{
117+
Description = "The target framework to run for. The target framework must also be specified in the project file."
118+
};
119+
var propertyOption = new CliOption<string[]>("--property")
120+
{
121+
Description = "Properties to be passed to MSBuild."
122+
};
106123

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

112129
if (invalidProperty != null)
113130
{
114-
v.ErrorMessage = $"Invalid property format: '{invalidProperty}'. Expected 'name=value'.";
131+
v.AddError($"Invalid property format: '{invalidProperty}'. Expected 'name=value'.");
115132
}
116133
});
117134

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

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

127-
var runCommand = new Command("run") { IsHidden = true };
128-
var rootCommand = new RootCommand(Description);
129-
addOptions(runCommand);
130-
addOptions(rootCommand);
145+
var runCommand = new CliCommand("run") { Hidden = true };
146+
var rootCommand = new CliRootCommand(Description);
147+
AddSymbols(runCommand);
148+
AddSymbols(rootCommand);
131149

132-
void addOptions(Command command)
150+
void AddSymbols(CliCommand command)
133151
{
134-
command.Add(quietOption);
135-
command.Add(verboseOption);
136-
command.Add(noHotReloadOption);
137-
command.Add(nonInteractiveOption);
138-
command.Add(longProjectOption);
139-
command.Add(shortProjectOption);
152+
command.Options.Add(quietOption);
153+
command.Options.Add(verboseOption);
154+
command.Options.Add(noHotReloadOption);
155+
command.Options.Add(nonInteractiveOption);
156+
command.Options.Add(longProjectOption);
157+
command.Options.Add(shortProjectOption);
140158

141159
if (command == runCommand)
142160
{
143-
command.Add(launchProfileRunOption);
144-
command.Add(noLaunchProfileRunOption);
161+
command.Options.Add(launchProfileRunOption);
162+
command.Options.Add(noLaunchProfileRunOption);
145163
}
146164
else
147165
{
148-
command.Add(launchProfileWatchOption);
149-
command.Add(noLaunchProfileWatchOption);
166+
command.Options.Add(launchProfileWatchOption);
167+
command.Options.Add(noLaunchProfileWatchOption);
150168
}
151169

152-
command.Add(targetFrameworkOption);
153-
command.Add(propertyOption);
170+
command.Options.Add(targetFrameworkOption);
171+
command.Options.Add(propertyOption);
154172

155-
command.Add(listOption);
173+
command.Options.Add(listOption);
156174

157175
if (command == runCommand)
158176
{
159-
command.Add(remainingRunArgs);
177+
command.Arguments.Add(remainingRunArgs);
160178
}
161179
else
162180
{
163-
command.Add(runCommand);
164-
command.Add(remainingWatchArgs);
181+
command.Subcommands.Add(runCommand);
182+
command.Arguments.Add(remainingWatchArgs);
165183
}
166184
};
167185

168186
CommandLineOptions? options = null;
169187

170-
runCommand.SetHandler(context =>
188+
runCommand.SetAction(parseResult =>
171189
{
172-
RootHandler(context, new()
190+
RootHandler(parseResult, new()
173191
{
174-
LaunchProfileName = context.ParseResult.GetValue(launchProfileRunOption),
175-
NoLaunchProfile = context.ParseResult.GetValue(noLaunchProfileRunOption),
176-
RemainingArguments = context.ParseResult.GetValue(remainingRunArgs),
192+
LaunchProfileName = parseResult.GetValue(launchProfileRunOption),
193+
NoLaunchProfile = parseResult.GetValue(noLaunchProfileRunOption),
194+
RemainingArguments = parseResult.GetValue(remainingRunArgs) ?? Array.Empty<string>(),
177195
});
178196
});
179197

180-
rootCommand.SetHandler(context => RootHandler(context, runOptions: null));
198+
rootCommand.SetAction(parseResult => RootHandler(parseResult, runOptions: null));
181199

182-
void RootHandler(InvocationContext context, RunCommandLineOptions? runOptions)
200+
void RootHandler(ParseResult parseResults, RunCommandLineOptions? runOptions)
183201
{
184-
var parseResults = context.ParseResult;
185202
var projectValue = parseResults.GetValue(longProjectOption);
186203
if (string.IsNullOrEmpty(projectValue))
187204
{
@@ -206,12 +223,17 @@ void RootHandler(InvocationContext context, RunCommandLineOptions? runOptions)
206223
TargetFramework = parseResults.GetValue(targetFrameworkOption),
207224
BuildProperties = parseResults.GetValue(propertyOption)?
208225
.Select(p => (p[..p.IndexOf('=')].Trim(), p[(p.IndexOf('=') + 1)..])).ToArray(),
209-
RemainingArguments = parseResults.GetValue(remainingWatchArgs),
226+
RemainingArguments = parseResults.GetValue(remainingWatchArgs) ?? Array.Empty<string>(),
210227
RunOptions = runOptions,
211228
};
212229
}
213230

214-
errorCode = rootCommand.Invoke(args, console);
231+
errorCode = new CliConfiguration(rootCommand)
232+
{
233+
Output = output ?? Console.Out,
234+
Error = error ?? Console.Error
235+
}.Invoke(args);
236+
215237
return options;
216238
}
217239

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.DotNet.Cli.Utils.Extensions
5+
{
6+
public static class StringExtensions
7+
{
8+
public static string RemovePrefix(this string name)
9+
{
10+
int prefixLength = GetPrefixLength(name);
11+
12+
return prefixLength > 0
13+
? name.Substring(prefixLength)
14+
: name;
15+
16+
static int GetPrefixLength(string name)
17+
{
18+
if (name[0] == '-')
19+
{
20+
return name.Length > 1 && name[1] == '-'
21+
? 2
22+
: 1;
23+
}
24+
25+
if (name[0] == '/')
26+
{
27+
return 1;
28+
}
29+
30+
return 0;
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)