8000 System.CommandLine update by adamsitnik · Pull Request #48477 · dotnet/sdk · GitHub
[go: up one dir, main page]

Skip to content

System.CommandLine update #48477

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

Merged
merged 16 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
4e0238b
Update dependencies from https://github.com/dotnet/roslyn build 20250…
dotnet-maestro[bot] Apr 15, 2025
20bffaa
bump System.CommandLine version, remove dependency to System.CommandL…
adamsitnik Apr 15, 2025
158c0e8
adjust to breaking changes: the removal of Cli prefix
adamsitnik Apr 15, 2025
c2a6e14
Update dependencies from https://github.com/dotnet/arcade build 20250…
dotnet-maestro[bot] Apr 15, 2025
bdd41bc
Update dependencies from https://github.com/dotnet/templating build 2…
dotnet-maestro[bot] Apr 15, 2025
f101c82
Update dependencies from https://github.com/dotnet/templating build 2…
dotnet-maestro[bot] Apr 15, 2025
6320064
Update dependencies from https://github.com/dotnet/sourcelink build 2…
dotnet-maestro[bot] Apr 15, 2025
5688b19
Merge branch 'main' into sclUpdate
adamsitnik Apr 15, 2025
2e39f66
Update dependencies from https://github.com/nuget/nuget.client build …
dotnet-maestro[bot] Apr 15, 2025
1e24e3b
Temporarily synchronize sourcelink again
ViktorHofer Apr 16, 2025
4bbe56d
Update dependencies from https://github.com/dotnet/runtime build 2025…
dotnet-maestro[bot] Apr 16, 2025
f5258c8
Delete src/SourceBuild/patches/runtime/0001-treat-targetos-and-rid-as…
ViktorHofer Apr 16, 2025
dff9bad
revert changes under src/SourceBuild
adamsitnik Apr 16, 2025
0c3615c
Add runtime patch
akoeplinger Apr 16, 2025
fd9cdde
Revert "Update dependencies from https://github.com/dotnet/arcade bui…
adamsitnik Apr 16, 2025
a3891d8
Merge branch 'main' into sclUpdate
ViktorHofer Apr 16, 2025
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
340 changes: 168 additions & 172 deletions eng/Version.Details.xml

Large diffs are not rendered by default.

148 changes: 74 additions & 74 deletions eng/Versions.props

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/BlazorWasmSdk/Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ internal static class Program
{
public static int Main(string[] args)
{
CliRootCommand rootCommand = new();
CliCommand brotli = new("brotli");
RootCommand rootCommand = new();
Command brotli = new("brotli");

CliOption<CompressionLevel> compressionLevelOption = new("-c")
Option<CompressionLevel> compressionLevelOption = new("-c")
{
DefaultValueFactory = _ => CompressionLevel.SmallestSize,
Description = "System.IO.Compression.CompressionLevel for the Brotli compression algorithm.",
};
CliOption<List<string>> sourcesOption = new("-s")
Option<List<string>> sourcesOption = new("-s")
{
Description = "A list of files to compress.",
AllowMultipleArgumentsPerToken = false
};
CliOption<List<string>> outputsOption = new("-o")
Option<List<string>> outputsOption = new("-o")
{
Description = "The filenames to output the compressed file to.",
AllowMultipleArgumentsPerToken = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ internal static class FormatAnalyzersCommand
{
private static readonly FormatAnalyzersHandler s_analyzerHandler = new();

internal static CliCommand GetCommand()
internal static Command GetCommand()
{
var command = new CliCommand("analyzers", Resources.Run_3rd_party_analyzers__and_apply_fixes)
var command = new Command("analyzers", Resources.Run_3rd_party_analyzers__and_apply_fixes)
{
DiagnosticsOption,
ExcludeDiagnosticsOption,
Expand All @@ -25,7 +25,7 @@ internal static CliCommand GetCommand()
return command;
}

private class FormatAnalyzersHandler : AsynchronousCliAction
private class FormatAnalyzersHandler : AsynchronousCommandLineAction
{
public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
{
Expand Down
30 changes: 15 additions & 15 deletions src/BuiltInTools/dotnet-format/Commands/FormatCommandCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,67 @@ internal static class FormatCommandCommon
private static string[] VerbosityLevels => new[] { "q", "quiet", "m", "minimal", "n", "normal", "d", "detailed", "diag", "diagnostic" };
private static string[] SeverityLevels => new[] { "info", "warn", "error" };

public static readonly CliArgument<string> SlnOrProjectArgument = new CliArgument<string>(Resources.SolutionOrProjectArgumentName)
public static readonly Argument<string> SlnOrProjectArgument = new Argument<string>(Resources.SolutionOrProjectArgumentName)
{
Description = Resources.SolutionOrProjectArgumentDescription,
Arity = ArgumentArity.ZeroOrOne
}.DefaultToCurrentDirectory();

internal static readonly CliOption<bool> FolderOption = new("--folder")
internal static readonly Option<bool> FolderOption = new("--folder")
{
Description = Resources.Whether_to_treat_the_workspace_argument_as_a_simple_folder_of_files,
};
internal static readonly CliOption<bool> NoRestoreOption = new("--no-restore")
internal static readonly Option<bool> NoRestoreOption = new("--no-restore")
{
Description = Resources.Doesnt_execute_an_implicit_restore_before_formatting,
};
internal static readonly CliOption<bool> VerifyNoChanges = new("--verify-no-changes")
internal static readonly Option<bool> VerifyNoChanges = new("--verify-no-changes")
{
Description = Resources.Verify_no_formatting_changes_would_be_performed_Terminates_with_a_non_zero_exit_code_if_any_files_would_have_been_formatted,
};
internal static readonly CliOption<string[]> DiagnosticsOption = new("--diagnostics")
internal static readonly Option<string[]> DiagnosticsOption = new("--diagnostics")
{
AllowMultipleArgumentsPerToken = true,
DefaultValueFactory = _ => Array.Empty<string>(),
Description = Resources.A_space_separated_list_of_diagnostic_ids_to_use_as_a_filter_when_fixing_code_style_or_3rd_party_issues,
};
internal static readonly CliOption<string[]> ExcludeDiagnosticsOption = new("--exclude-diagnostics")
internal static readonly Option<string[]> ExcludeDiagnosticsOption = new("--exclude-diagnostics")
{
AllowMultipleArgumentsPerToken = true,
DefaultValueFactory = _ => Array.Empty<string>(),
Description = Resources.A_space_separated_list_of_diagnostic_ids_to_ignore_when_fixing_code_style_or_3rd_party_issues,
};
internal static readonly CliOption<string> SeverityOption = new CliOption<string>("--severity")
internal static readonly Option<string> SeverityOption = new Option<string>("--severity")
{
Description = Resources.The_severity_of_diagnostics_to_fix_Allowed_values_are_info_warn_and_error,
};
internal static readonly CliOption<string[]> IncludeOption = new("--include")
internal static readonly Option<string[]> IncludeOption = new("--include")
{
AllowMultipleArgumentsPerToken = true,
DefaultValueFactory = _ => Array.Empty<string>(),
Description = Resources.A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty,
};
internal static readonly CliOption<string[]> ExcludeOption = new("--exclude")
internal static readonly Option<string[]> ExcludeOption = new("--exclude")
{
AllowMultipleArgumentsPerToken = true,
DefaultValueFactory = _ => Array.Empty<string>(),
Description = Resources.A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting,
};
internal static readonly CliOption<bool> IncludeGeneratedOption = new("--include-generated")
internal static readonly Option<bool> IncludeGeneratedOption = new("--include-generated")
{
Description = Resources.Format_files_generated_by_the_SDK,
};
internal static readonly CliOption<string> VerbosityOption = new CliOption<string>("--verbosity", "-v")
internal static readonly Option<string> VerbosityOption = new Option<string>("--verbosity", "-v")
{
Description = Resources.Set_the_verbosity_level_Allowed_values_are_quiet_minimal_normal_detailed_and_diagnostic,
};
internal static readonly CliOption<string> BinarylogOption = new CliOption<string>("--binarylog")
internal static readonly Option<string> BinarylogOption = new Option<string>("--binarylog")
{
HelpName = "binary-log-path",
Arity = ArgumentArity.ZeroOrOne,
Description = Resources.Log_all_project_or_solution_load_information_to_a_binary_log_file,
};
internal static readonly CliOption<string> ReportOption = new CliOption<string>("--report")
internal static readonly Option<string> ReportOption = new Option<string>("--report")
{
HelpName = "report-path",
Arity = ArgumentArity.ZeroOrOne,
Expand Down Expand Up @@ -118,7 +118,7 @@ internal static async Task<int> FormatAsync(FormatOptions formatOptions, ILogger
return formatResult.GetExitCode(formatOptions.ChangesAreErrors);
}

public static void AddCommonOptions(this CliCommand command)
public static void AddCommonOptions(this Command command)
{
command.Arguments.Add(SlnOrProjectArgument);
command.Options.Add(NoRestoreOption);
Expand All @@ -131,7 +131,7 @@ public static void AddCommonOptions(this CliCommand command)
command.Options.Add(ReportOption);
}

public static CliArgument<string> DefaultToCurrentDirectory(this CliArgument<string> arg)
public static Argument<string> DefaultToCurrentDirectory(this Argument<string> arg)
{
arg.DefaultValueFactory = _ => EnsureTrailingSlash(Directory.GetCurrentDirectory());
return arg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ internal static class FormatStyleCommand
{
private static readonly FormatStyleHandler s_styleHandler = new();

internal static CliCommand GetCommand()
internal static Command GetCommand()
{
var command = new CliCommand("style", Resources.Run_code_style_analyzers_and_apply_fixes)
var command = new Command("style", Resources.Run_code_style_analyzers_and_apply_fixes)
{
DiagnosticsOption,
ExcludeDiagnosticsOption,
Expand All @@ -25,7 +25,7 @@ internal static CliCommand GetCommand()
return command;
}

private class FormatStyleHandler : AsynchronousCliAction
private class FormatStyleHandler : AsynchronousCommandLineAction
{
public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ internal static class FormatWhitespaceCommand
{
private static readonly FormatWhitespaceHandler s_formattingHandler = new();

internal static CliCommand GetCommand()
internal static Command GetCommand()
{
var command = new CliCommand("whitespace", Resources.Run_whitespace_formatting)
var command = new Command("whitespace", Resources.Run_whitespace_formatting)
{
FolderOption
};
Expand Down Expand Up @@ -45,7 +45,7 @@ internal static void EnsureFolderNotSpecifiedWhenLoggingBinlog(CommandResult sym
}
}

private class FormatWhitespaceHandler : AsynchronousCliAction
private class FormatWhitespaceHandler : AsynchronousCommandLineAction
{
public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ internal static class RootFormatCommand
{
private static readonly FormatCommandDefaultHandler s_formatCommandHandler = new();

public static CliRootCommand GetCommand()
public static RootCommand GetCommand()
{
var formatCommand = new CliRootCommand(Resources.Formats_code_to_match_editorconfig_settings)
var formatCommand = new RootCommand(Resources.Formats_code_to_match_editorconfig_settings)
{
FormatWhitespaceCommand.GetCommand(),
FormatStyleCommand.GetCommand(),
Expand All @@ -28,7 +28,7 @@ public static CliRootCommand GetCommand()
return formatCommand;
}

private class FormatCommandDefaultHandler : AsynchronousCliAction
private class FormatCommandDefaultHandler : AsynchronousCommandLineAction
{
public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
{
Expand Down
32 changes: 16 additions & 16 deletions src/BuiltInTools/dotnet-watch/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ internal sealed class CommandLineOptions
public string Command => ExplicitCommand ?? DefaultCommand;

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

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

verboseOption.Validators.Add(v =>
{
Ex 10000 pand All @@ -49,7 +49,7 @@ internal sealed class CommandLineOptions
}
});

CliOption[] watchOptions =
Option[] watchOptions =
[
quietOption,
verboseOption,
Expand All @@ -59,12 +59,12 @@ internal sealed class CommandLineOptions
];

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

var rootCommand = new CliRootCommand(Resources.Help)
var rootCommand = new RootCommand(Resources.Help)
{
Directives = { new EnvironmentVariablesDirective() },
};
Expand All @@ -90,7 +90,7 @@ internal sealed class CommandLineOptions
var rootCommandInvoked = false;
rootCommand.SetAction(parseResult => rootCommandInvoked = true);

var cliConfig = new CliConfiguration(rootCommand)
var cliConfig = new CommandLineConfiguration(rootCommand)
{
Output = output,
Error = output,
Expand Down Expand Up @@ -148,7 +148,7 @@ internal sealed class CommandLineOptions

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

return new()
{
Expand All @@ -174,8 +174,8 @@ internal sealed class CommandLineOptions

private static IReadOnlyList<string> GetCommandArguments(
ParseResult parseResult,
IReadOnlyList<CliOption> watchOptions,
CliCommand? explicitCommand)
IReadOnlyList<Option> watchOptions,
Command? explicitCommand)
{
var arguments = new List<string>();

Expand Down Expand Up @@ -251,7 +251,7 @@ private static IReadOnlyList<string> GetCommandArguments(
return arguments;
}

private static CliCommand? TryGetSubcommand(ParseResult parseResult)
private static Command? TryGetSubcommand(ParseResult parseResult)
{
// Assuming that all tokens after "--" are unmatched:
var dashDashIndex = IndexOf(parseResult.Tokens, t => t.Value == "--");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ internal ChoiceTemplateParameter(ChoiceTemplateParameter choiceTemplateParameter
};
}

protected override CliOption GetBaseOption(IReadOnlySet<string> aliases)
protected override Option GetBaseOption(IReadOnlySet<string> aliases)
{
string name = GetName(aliases);

CliOption<string> option = new(name)
Option<string> option = new(name)
{
CustomParser = result => GetParseChoiceArgument(this)(result),
Arity = new ArgumentArity(DefaultIfOptionWithoutValue == null ? 1 : 0, AllowMultipleValues ? _choices.Count : 1),
Expand Down
Loading
Loading
0