Skip to content

Commit 6bca3a3

Browse files
adamsitnikdotnet-maestro[bot]ViktorHoferakoeplinger
authored
System.CommandLine update (#48477)
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com> Co-authored-by: Viktor Hofer <[email protected]> Co-authored-by: Alexander Köplinger <[email protected]>
1 parent cc47659 commit 6bca3a3

File tree

177 files changed

+1417
-1425
lines changed

Some content is hidden

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

177 files changed

+1417
-1425
lines changed

Diff for: eng/Version.Details.xml

+168-172
Large diffs are not rendered by default.

Diff for: eng/Versions.props

+74-74
Large diffs are not rendered by default.

Diff for: src/BlazorWasmSdk/Tool/Program.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ internal static class Program
1212
{
1313
public static int Main(string[] args)
1414
{
15-
CliRootCommand rootCommand = new();
16-
CliCommand brotli = new("brotli");
15+
RootCommand rootCommand = new();
16+
Command brotli = new("brotli");
1717

18-
CliOption<CompressionLevel> compressionLevelOption = new("-c")
18+
Option<CompressionLevel> compressionLevelOption = new("-c")
1919
{
2020
DefaultValueFactory = _ => CompressionLevel.SmallestSize,
2121
Description = "System.IO.Compression.CompressionLevel for the Brotli compression algorithm.",
2222
};
23-
CliOption<List<string>> sourcesOption = new("-s")
23+
Option<List<string>> sourcesOption = new("-s")
2424
{
2525
Description = "A list of files to compress.",
2626
AllowMultipleArgumentsPerToken = false
2727
};
28-
CliOption<List<string>> outputsOption = new("-o")
28+
Option<List<string>> outputsOption = new("-o")
2929
{
3030
Description = "The filenames to output the compressed file to.",
3131
AllowMultipleArgumentsPerToken = false

Diff for: src/BuiltInTools/dotnet-format/Commands/FormatAnalyzersCommand.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ internal static class FormatAnalyzersCommand
1212
{
1313
private static readonly FormatAnalyzersHandler s_analyzerHandler = new();
1414

15-
internal static CliCommand GetCommand()
15+
internal static Command GetCommand()
1616
{
17-
var command = new CliCommand("analyzers", Resources.Run_3rd_party_analyzers__and_apply_fixes)
17+
var command = new Command("analyzers", Resources.Run_3rd_party_analyzers__and_apply_fixes)
1818
{
1919
DiagnosticsOption,
2020
ExcludeDiagnosticsOption,
@@ -25,7 +25,7 @@ internal static CliCommand GetCommand()
2525
return command;
2626
}
2727

28-
private class FormatAnalyzersHandler : AsynchronousCliAction
28+
private class FormatAnalyzersHandler : AsynchronousCommandLineAction
2929
{
3030
public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
3131
{

Diff for: src/BuiltInTools/dotnet-format/Commands/FormatCommandCommon.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -19,67 +19,67 @@ internal static class FormatCommandCommon
1919
private static string[] VerbosityLevels => new[] { "q", "quiet", "m", "minimal", "n", "normal", "d", "detailed", "diag", "diagnostic" };
2020
private static string[] SeverityLevels => new[] { "info", "warn", "error" };
2121

22-
public static readonly CliArgument<string> SlnOrProjectArgument = new CliArgument<string>(Resources.SolutionOrProjectArgumentName)
22+
public static readonly Argument<string> SlnOrProjectArgument = new Argument<string>(Resources.SolutionOrProjectArgumentName)
2323
{
2424
Description = Resources.SolutionOrProjectArgumentDescription,
2525
Arity = ArgumentArity.ZeroOrOne
2626
}.DefaultToCurrentDirectory();
2727

28-
internal static readonly CliOption<bool> FolderOption = new("--folder")
28+
internal static readonly Option<bool> FolderOption = new("--folder")
2929
{
3030
Description = Resources.Whether_to_treat_the_workspace_argument_as_a_simple_folder_of_files,
3131
};
32-
internal static readonly CliOption<bool> NoRestoreOption = new("--no-restore")
32+
internal static readonly Option<bool> NoRestoreOption = new("--no-restore")
3333
{
3434
Description = Resources.Doesnt_execute_an_implicit_restore_before_formatting,
3535
};
36-
internal static readonly CliOption<bool> VerifyNoChanges = new("--verify-no-changes")
36+
internal static readonly Option<bool> VerifyNoChanges = new("--verify-no-changes")
3737
{
3838
Description = Resources.Verify_no_formatting_changes_would_be_performed_Terminates_with_a_non_zero_exit_code_if_any_files_would_have_been_formatted,
3939
};
40-
internal static readonly CliOption<string[]> DiagnosticsOption = new("--diagnostics")
40+
internal static readonly Option<string[]> DiagnosticsOption = new("--diagnostics")
4141
{
4242
AllowMultipleArgumentsPerToken = true,
4343
DefaultValueFactory = _ => Array.Empty<string>(),
4444
Description = Resources.A_space_separated_list_of_diagnostic_ids_to_use_as_a_filter_when_fixing_code_style_or_3rd_party_issues,
4545
};
46-
internal static readonly CliOption<string[]> ExcludeDiagnosticsOption = new("--exclude-diagnostics")
46+
internal static readonly Option<string[]> ExcludeDiagnosticsOption = new("--exclude-diagnostics")
4747
{
4848
AllowMultipleArgumentsPerToken = true,
4949
DefaultValueFactory = _ => Array.Empty<string>(),
5050
Description = Resources.A_space_separated_list_of_diagnostic_ids_to_ignore_when_fixing_code_style_or_3rd_party_issues,
5151
};
52-
internal static readonly CliOption<string> SeverityOption = new CliOption<string>("--severity")
52+
internal static readonly Option<string> SeverityOption = new Option<string>("--severity")
5353
{
5454
Description = Resources.The_severity_of_diagnostics_to_fix_Allowed_values_are_info_warn_and_error,
5555
};
56-
internal static readonly CliOption<string[]> IncludeOption = new("--include")
56+
internal static readonly Option<string[]> IncludeOption = new("--include")
5757
{
5858
AllowMultipleArgumentsPerToken = true,
5959
DefaultValueFactory = _ => Array.Empty<string>(),
6060
Description = Resources.A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty,
6161
};
62-
internal static readonly CliOption<string[]> ExcludeOption = new("--exclude")
62+
internal static readonly Option<string[]> ExcludeOption = new("--exclude")
6363
{
6464
AllowMultipleArgumentsPerToken = true,
6565
DefaultValueFactory = _ => Array.Empty<string>(),
6666
Description = Resources.A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting,
6767
};
68-
internal static readonly CliOption<bool> IncludeGeneratedOption = new("--include-generated")
68+
internal static readonly Option<bool> IncludeGeneratedOption = new("--include-generated")
6969
{
7070
Description = Resources.Format_files_generated_by_the_SDK,
7171
};
72-
internal static readonly CliOption<string> VerbosityOption = new CliOption<string>("--verbosity", "-v")
72+
internal static readonly Option<string> VerbosityOption = new Option<string>("--verbosity", "-v")
7373
{
7474
Description = Resources.Set_the_verbosity_level_Allowed_values_are_quiet_minimal_normal_detailed_and_diagnostic,
7575
};
76-
internal static readonly CliOption<string> BinarylogOption = new CliOption<string>("--binarylog")
76+
internal static readonly Option<string> BinarylogOption = new Option<string>("--binarylog")
7777
{
7878
HelpName = "binary-log-path",
7979
Arity = ArgumentArity.ZeroOrOne,
8080
Description = Resources.Log_all_project_or_solution_load_information_to_a_binary_log_file,
8181
};
82-
internal static readonly CliOption<string> ReportOption = new CliOption<string>("--report")
82+
internal static readonly Option<string> ReportOption = new Option<string>("--report")
8383
{
8484
HelpName = "report-path",
8585
Arity = ArgumentArity.ZeroOrOne,
@@ -118,7 +118,7 @@ internal static async Task<int> FormatAsync(FormatOptions formatOptions, ILogger
118118
return formatResult.GetExitCode(formatOptions.ChangesAreErrors);
119119
}
120120

121-
public static void AddCommonOptions(this CliCommand command)
121+
public static void AddCommonOptions(this Command command)
122122
{
123123
command.Arguments.Add(SlnOrProjectArgument);
124124
command.Options.Add(NoRestoreOption);
@@ -131,7 +131,7 @@ public static void AddCommonOptions(this CliCommand command)
131131
command.Options.Add(ReportOption);
132132
}
133133

134-
public static CliArgument<string> DefaultToCurrentDirectory(this CliArgument<string> arg)
134+
public static Argument<string> DefaultToCurrentDirectory(this Argument<string> arg)
135135
{
136136
arg.DefaultValueFactory = _ => EnsureTrailingSlash(Directory.GetCurrentDirectory());
137137
return arg;

Diff for: src/BuiltInTools/dotnet-format/Commands/FormatStyleCommand.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ internal static class FormatStyleCommand
1212
{
1313
private static readonly FormatStyleHandler s_styleHandler = new();
1414

15-
internal static CliCommand GetCommand()
15+
internal static Command GetCommand()
1616
{
17-
var command = new CliCommand("style", Resources.Run_code_style_analyzers_and_apply_fixes)
17+
var command = new Command("style", Resources.Run_code_style_analyzers_and_apply_fixes)
1818
{
1919
DiagnosticsOption,
2020
ExcludeDiagnosticsOption,
@@ -25,7 +25,7 @@ internal static CliCommand GetCommand()
2525
return command;
2626
}
2727

28-
private class FormatStyleHandler : AsynchronousCliAction
28+
private class FormatStyleHandler : AsynchronousCommandLineAction
2929
{
3030
public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
3131
{

Diff for: src/BuiltInTools/dotnet-format/Commands/FormatWhitespaceCommand.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ internal static class FormatWhitespaceCommand
1212
{
1313
private static readonly FormatWhitespaceHandler s_formattingHandler = new();
1414

15-
internal static CliCommand GetCommand()
15+
internal static Command GetCommand()
1616
{
17-
var command = new CliCommand("whitespace", Resources.Run_whitespace_formatting)
17+
var command = new Command("whitespace", Resources.Run_whitespace_formatting)
1818
{
1919
FolderOption
2020
};
@@ -45,7 +45,7 @@ internal static void EnsureFolderNotSpecifiedWhenLoggingBinlog(CommandResult sym
4545
}
4646
}
4747

48-
private class FormatWhitespaceHandler : AsynchronousCliAction
48+
private class FormatWhitespaceHandler : AsynchronousCommandLineAction
4949
{
5050
public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
5151
{

Diff for: src/BuiltInTools/dotnet-format/Commands/RootFormatCommand.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ internal static class RootFormatCommand
1212
{
1313
private static readonly FormatCommandDefaultHandler s_formatCommandHandler = new();
1414

15-
public static CliRootCommand GetCommand()
15+
public static RootCommand GetCommand()
1616
{
17-
var formatCommand = new CliRootCommand(Resources.Formats_code_to_match_editorconfig_settings)
17+
var formatCommand = new RootCommand(Resources.Formats_code_to_match_editorconfig_settings)
1818
{
1919
FormatWhitespaceCommand.GetCommand(),
2020
FormatStyleCommand.GetCommand(),
@@ -28,7 +28,7 @@ public static CliRootCommand GetCommand()
2828
return formatCommand;
2929
}
3030

31-
private class FormatCommandDefaultHandler : AsynchronousCliAction
31+
private class FormatCommandDefaultHandler : AsynchronousCommandLineAction
3232
{
3333
public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
3434
{

Diff for: src/BuiltInTools/dotnet-watch/CommandLineOptions.cs

+16-16
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ internal sealed class CommandLineOptions
3131
public string Command => ExplicitCommand ?? DefaultCommand;
3232

3333
// this option is referenced from inner logic and so needs to be reference-able
34-
public static CliOption<bool> NonInteractiveOption = new CliOption<bool>("--non-interactive") { Description = Resources.Help_NonInteractive, Arity = ArgumentArity.Zero };
34+
public static Option<bool> NonInteractiveOption = new Option<bool>("--non-interactive") { Description = Resources.Help_NonInteractive, Arity = ArgumentArity.Zero };
3535

3636
public static CommandLineOptions? Parse(IReadOnlyList<string> args, IReporter reporter, TextWriter output, out int errorCode)
3737
{
3838
// dotnet watch specific options:
39-
var quietOption = new CliOption<bool>("--quiet", "-q") { Description = Resources.Help_Quiet, Arity = ArgumentArity.Zero };
40-
var verboseOption = new CliOption<bool>("--verbose") { Description = Resources.Help_Verbose, Arity = ArgumentArity.Zero };
41-
var listOption = new CliOption<bool>("--list") { Description = Resources.Help_List, Arity = ArgumentArity.Zero };
42-
var noHotReloadOption = new CliOption<bool>("--no-hot-reload") { Description = Resources.Help_NoHotReload, Arity = ArgumentArity.Zero };
39+
var quietOption = new Option<bool>("--quiet", "-q") { Description = Resources.Help_Quiet, Arity = ArgumentArity.Zero };
40+
var verboseOption = new Option<bool>("--verbose") { Description = Resources.Help_Verbose, Arity = ArgumentArity.Zero };
41+
var listOption = new Option<bool>("--list") { Description = Resources.Help_List, Arity = ArgumentArity.Zero };
42+
var noHotReloadOption = new Option<bool>("--no-hot-reload") { Description = Resources.Help_NoHotReload, Arity = ArgumentArity.Zero };
4343

4444
verboseOption.Validators.Add(v =>
4545
{
@@ -49,7 +49,7 @@ internal sealed class CommandLineOptions
4949
}
5050
});
5151

52-
CliOption[] watchOptions =
52+
Option[] watchOptions =
5353
[
5454
quietOption,
5555
verboseOption,
@@ -59,12 +59,12 @@ internal sealed class CommandLineOptions
5959
];
6060

6161
// Options we need to know about that are passed through to the subcommand:
62-
var shortProjectOption = new CliOption<string>("-p") { Hidden = true, Arity = ArgumentArity.ZeroOrOne, AllowMultipleArgumentsPerToken = false };
63-
var longProjectOption = new CliOption<string>("--project") { Hidden = true, Arity = ArgumentArity.ZeroOrOne, AllowMultipleArgumentsPerToken = false };
64-
var launchProfileOption = new CliOption<string>("--launch-profile", "-lp") { Hidden = true, Arity = ArgumentArity.ZeroOrOne, AllowMultipleArgumentsPerToken = false };
65-
var noLaunchProfileOption = new CliOption<bool>("--no-launch-profile") { Hidden = true, Arity = ArgumentArity.Zero };
62+
var shortProjectOption = new Option<string>("-p") { Hidden = true, Arity = ArgumentArity.ZeroOrOne, AllowMultipleArgumentsPerToken = false };
63+
var longProjectOption = new Option<string>("--project") { Hidden = true, Arity = ArgumentArity.ZeroOrOne, AllowMultipleArgumentsPerToken = false };
64+
var launchProfileOption = new Option<string>("--launch-profile", "-lp") { Hidden = true, Arity = ArgumentArity.ZeroOrOne, AllowMultipleArgumentsPerToken = false };
65+
var noLaunchProfileOption = new Option<bool>("--no-launch-profile") { Hidden = true, Arity = ArgumentArity.Zero };
6666

67-
var rootCommand = new CliRootCommand(Resources.Help)
67+
var rootCommand = new RootCommand(Resources.Help)
6868
{
6969
Directives = { new EnvironmentVariablesDirective() },
7070
};
@@ -90,7 +90,7 @@ internal sealed class CommandLineOptions
9090
var rootCommandInvoked = false;
9191
rootCommand.SetAction(parseResult => rootCommandInvoked = true);
9292

93-
var cliConfig = new CliConfiguration(rootCommand)
93+
var cliConfig = new CommandLineConfiguration(rootCommand)
9494
{
9595
Output = output,
9696
Error = output,
@@ -148,7 +148,7 @@ internal sealed class CommandLineOptions
148148

149149
// We assume that forwarded options, if any, are intended for dotnet build.
150150
var buildArguments = buildOptions.Select(option => ((IForwardedOption)option).GetForwardingFunction()(parseResult)).SelectMany(args => args).ToArray();
151-
var targetFrameworkOption = (CliOption<string>?)buildOptions.SingleOrDefault(option => option.Name == "--framework");
151+
var targetFrameworkOption = (Option<string>?)buildOptions.SingleOrDefault(option => option.Name == "--framework");
152152

153153
return new()
154154
{
@@ -174,8 +174,8 @@ internal sealed class CommandLineOptions
174174

175175
private static IReadOnlyList<string> GetCommandArguments(
176176
ParseResult parseResult,
177-
IReadOnlyList<CliOption> watchOptions,
178-
CliCommand? explicitCommand)
177+
IReadOnlyList<Option> watchOptions,
178+
Command? explicitCommand)
179179
{
180180
var arguments = new List<string>();
181181

@@ -251,7 +251,7 @@ private static IReadOnlyList<string> GetCommandArguments(
251251
return arguments;
252252
}
253253

254-
private static CliCommand? TryGetSubcommand(ParseResult parseResult)
254+
private static Command? TryGetSubcommand(ParseResult parseResult)
255255
{
256256
// Assuming that all tokens after "--" are unmatched:
257257
var dashDashIndex = IndexOf(parseResult.Tokens, t => t.Value == "--");

Diff for: src/Cli/Microsoft.TemplateEngine.Cli/ChoiceTemplateParameter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ internal ChoiceTemplateParameter(ChoiceTemplateParameter choiceTemplateParameter
6868
};
6969
}
7070

71-
protected override CliOption GetBaseOption(IReadOnlySet<string> aliases)
71+
protected override Option GetBaseOption(IReadOnlySet<string> aliases)
7272
{
7373
string name = GetName(aliases);
7474

75-
CliOption<string> option = new(name)
75+
Option<string> option = new(name)
7676
{
7777
CustomParser = result => GetParseChoiceArgument(this)(result),
7878
Arity = new ArgumentArity(DefaultIfOptionWithoutValue == null ? 1 : 0, AllowMultipleValues ? _choices.Count : 1),

0 commit comments

Comments
 (0)