Skip to content

Commit 7962096

Browse files
authored
Revert "Revert "[main] Update dependencies from dotnet/command-line-api (#29131)""
1 parent 3eec09e commit 7962096

File tree

191 files changed

+3366
-3065
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

+3366
-3065
lines changed

eng/Version.Details.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,13 @@
321321
<Sha>2f0301ef59624a72fb00f7fd92caa50be03f277d</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.23305.2">

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<SystemTextJsonVersion>7.0.2</SystemTextJsonVersion>
4040
<SystemReflectionMetadataLoadContextVersion>8.0.0-preview.6.23309.1</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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 196 additions & 159 deletions
Large diffs are not rendered by default.

src/BlazorWasmSdk/Tool/Program.cs

Lines changed: 16 additions & 20 deletions
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

Lines changed: 80 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
using System;
77
using System.Collections.Generic;
88
using System.CommandLine;
9-
using System.CommandLine.Invocation;
9+
using System.IO;
1010
using System.Linq;
11-
12-
using Microsoft.AspNetCore.Authentication;
1311
using Microsoft.DotNet.Watcher.Tools;
1412
using Microsoft.Extensions.Tools.Internal;
1513

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

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

85-
verboseOption.AddValidator(v =>
85+
var verboseOption = new CliOption<bool>("--verbose", "-v")
8686
{
87-
if (v.FindResultFor(quietOption) is not null && v.FindResultFor(verboseOption) is not null)
87+
Description = "Show verbose output"
88+
};
89+
90+
verboseOption.Validators.Add(v =>
91+
{
92+
if (v.GetResult(quietOption) is not null && v.GetResult(verboseOption) is not null)
8893
{
89-
v.ErrorMessage = Resources.Error_QuietAndVerboseSpecified;
94+
v.AddError(Resources.Error_QuietAndVerboseSpecified);
9095
}
9196
});
9297

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

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

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

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

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

113130
if (invalidProperty != null)
114131
{
115-
v.ErrorMessage = $"Invalid property format: '{invalidProperty}'. Expected 'name=value'.";
132+
v.AddError($"Invalid property format: '{invalidProperty}'. Expected 'name=value'.");
116133
}
117134
});
118135

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

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

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

133-
void addOptions(Command command)
151+
void AddSymbols(CliCommand command)
134152
{
135-
command.Add(quietOption);
136-
command.Add(verboseOption);
137-
command.Add(noHotReloadOption);
138-
command.Add(nonInteractiveOption);
139-
command.Add(longProjectOption);
140-
command.Add(shortProjectOption);
153+
command.Options.Add(quietOption);
154+
command.Options.Add(verboseOption);
155+
command.Options.Add(noHotReloadOption);
156+
command.Options.Add(nonInteractiveOption);
157+
command.Options.Add(longProjectOption);
158+
command.Options.Add(shortProjectOption);
141159

142160
if (command == runCommand)
143161
{
144-
command.Add(launchProfileRunOption);
145-
command.Add(noLaunchProfileRunOption);
162+
command.Options.Add(launchProfileRunOption);
163+
command.Options.Add(noLaunchProfileRunOption);
146164
}
147165
else
148166
{
149-
command.Add(launchProfileWatchOption);
150-
command.Add(noLaunchProfileWatchOption);
167+
command.Options.Add(launchProfileWatchOption);
168+
command.Options.Add(noLaunchProfileWatchOption);
151169
}
152170

153-
command.Add(targetFrameworkOption);
154-
command.Add(propertyOption);
171+
command.Options.Add(targetFrameworkOption);
172+
command.Options.Add(propertyOption);
155173

156-
command.Add(listOption);
174+
command.Options.Add(listOption);
157175

158176
if (command == runCommand)
159177
{
160-
command.Add(remainingRunArgs);
178+
command.Arguments.Add(remainingRunArgs);
161179
}
162180
else
163181
{
164-
command.Add(runCommand);
165-
command.Add(remainingWatchArgs);
182+
command.Subcommands.Add(runCommand);
183+
command.Arguments.Add(remainingWatchArgs);
166184
}
167185
};
168186

169187
CommandLineOptions? options = null;
170188

171-
runCommand.SetHandler(context =>
189+
runCommand.SetAction(parseResult =>
172190
{
173-
RootHandler(context, new()
191+
RootHandler(parseResult, new()
174192
{
175-
LaunchProfileName = context.ParseResult.GetValue(launchProfileRunOption),
176-
NoLaunchProfile = context.ParseResult.GetValue(noLaunchProfileRunOption),
177-
RemainingArguments = context.ParseResult.GetValue(remainingRunArgs),
193+
LaunchProfileName = parseResult.GetValue(launchProfileRunOption),
194+
NoLaunchProfile = parseResult.GetValue(noLaunchProfileRunOption),
195+
RemainingArguments = parseResult.GetValue(remainingRunArgs) ?? Array.Empty<string>(),
178196
});
179197
});
180198

181-
rootCommand.SetHandler(context => RootHandler(context, runOptions: null));
199+
rootCommand.SetAction(parseResult => RootHandler(parseResult, runOptions: null));
182200

183-
void RootHandler(InvocationContext context, RunCommandLineOptions? runOptions)
201+
void RootHandler(ParseResult parseResults, RunCommandLineOptions? runOptions)
184202
{
185-
var parseResults = context.ParseResult;
186203
var projectValue = parseResults.GetValue(longProjectOption);
187204
if (string.IsNullOrEmpty(projectValue))
188205
{
@@ -207,12 +224,17 @@ void RootHandler(InvocationContext context, RunCommandLineOptions? runOptions)
207224
TargetFramework = parseResults.GetValue(targetFrameworkOption),
208225
BuildProperties = parseResults.GetValue(propertyOption)?
209226
.Select(p => (p[..p.IndexOf('=')].Trim(), p[(p.IndexOf('=') + 1)..])).ToArray(),
210-
RemainingArguments = parseResults.GetValue(remainingWatchArgs),
227+
RemainingArguments = parseResults.GetValue(remainingWatchArgs) ?? Array.Empty<string>(),
211228
RunOptions = runOptions,
212229
};
213230
}
214231

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

Lines changed: 34 additions & 0 deletions
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)