diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000000..fa052f175c36 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Apply dotnet format - Thu Dec 11 22:23:23 UTC 2025 +a02f341 diff --git a/src/Cli/dotnet/CommandFactory/CommandResolution/ProjectToolsCommandResolver.cs b/src/Cli/dotnet/CommandFactory/CommandResolution/ProjectToolsCommandResolver.cs index aa844850e316..32b6de03cfae 100644 --- a/src/Cli/dotnet/CommandFactory/CommandResolution/ProjectToolsCommandResolver.cs +++ b/src/Cli/dotnet/CommandFactory/CommandResolution/ProjectToolsCommandResolver.cs @@ -385,7 +385,7 @@ internal void GenerateDepsJsonFile( string? stdOut; string? stdErr; - var msbuildArgs = MSBuildArgs.AnalyzeMSBuildArguments([..args], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandParser.TargetOption, BuildCommandParser.VerbosityOption, BuildCommandParser.NoLogoOption); + var msbuildArgs = MSBuildArgs.AnalyzeMSBuildArguments([.. args], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandParser.TargetOption, BuildCommandParser.VerbosityOption, BuildCommandParser.NoLogoOption); var forwardingAppWithoutLogging = new MSBuildForwardingAppWithoutLogging(msbuildArgs, msBuildExePath); if (forwardingAppWithoutLogging.ExecuteMSBuildOutOfProc) { diff --git a/src/Cli/dotnet/Commands/Build/BuildCommand.cs b/src/Cli/dotnet/Commands/Build/BuildCommand.cs index 264abdad7d80..59fcbf217932 100644 --- a/src/Cli/dotnet/Commands/Build/BuildCommand.cs +++ b/src/Cli/dotnet/Commands/Build/BuildCommand.cs @@ -13,7 +13,7 @@ public static class BuildCommand { public static CommandBase FromArgs(string[] args, string? msbuildPath = null) { - var parseResult = Parser.Parse(["dotnet", "build", ..args]); + var parseResult = Parser.Parse(["dotnet", "build", .. args]); return FromParseResult(parseResult, msbuildPath); } diff --git a/src/Cli/dotnet/Commands/BuildServer/BuildServerCommandParser.cs b/src/Cli/dotnet/Commands/BuildServer/BuildServerCommandParser.cs index 468e60ad4fe1..0ca2108f124a 100644 --- a/src/Cli/dotnet/Commands/BuildServer/BuildServerCommandParser.cs +++ b/src/Cli/dotnet/Commands/BuildServer/BuildServerCommandParser.cs @@ -4,8 +4,8 @@ #nullable disable using System.CommandLine; -using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown; using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown; using Microsoft.DotNet.Cli.Extensions; namespace Microsoft.DotNet.Cli.Commands.BuildServer; diff --git a/src/Cli/dotnet/Commands/Clean/CleanCommand.cs b/src/Cli/dotnet/Commands/Clean/CleanCommand.cs index c7e48c376ee9..14e7e0f3c925 100644 --- a/src/Cli/dotnet/Commands/Clean/CleanCommand.cs +++ b/src/Cli/dotnet/Commands/Clean/CleanCommand.cs @@ -13,7 +13,7 @@ public class CleanCommand(MSBuildArgs msbuildArgs, string? msbuildPath = null) : { public static CommandBase FromArgs(string[] args, string? msbuildPath = null) { - var result = Parser.Parse(["dotnet", "clean", ..args]); + var result = Parser.Parse(["dotnet", "clean", .. args]); return FromParseResult(result, msbuildPath); } @@ -33,7 +33,7 @@ public static CommandBase FromParseResult(ParseResult result, string? msbuildPat NoWriteBuildMarkers = true, }, static (msbuildArgs, msbuildPath) => new CleanCommand(msbuildArgs, msbuildPath), - [ CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, CleanCommandParser.TargetOption, CleanCommandParser.VerbosityOption, CleanCommandParser.NoLogoOption], + [CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, CleanCommandParser.TargetOption, CleanCommandParser.VerbosityOption, CleanCommandParser.NoLogoOption], result, msbuildPath ); diff --git a/src/Cli/dotnet/Commands/Format/FormatCommand.cs b/src/Cli/dotnet/Commands/Format/FormatCommand.cs index 9ee9296172fa..d6629af67720 100644 --- a/src/Cli/dotnet/Commands/Format/FormatCommand.cs +++ b/src/Cli/dotnet/Commands/Format/FormatCommand.cs @@ -13,7 +13,7 @@ public class FormatCommand(IEnumerable argsToForward) : FormatForwarding { public static FormatCommand FromArgs(string[] args) { - var result = Parser.Parse(["dotnet", "format", ..args]); + var result = Parser.Parse(["dotnet", "format", .. args]); return FromParseResult(result); } diff --git a/src/Cli/dotnet/Commands/Fsi/FsiCommandParser.cs b/src/Cli/dotnet/Commands/Fsi/FsiCommandParser.cs index c81c34e79566..ac57e60e87d4 100644 --- a/src/Cli/dotnet/Commands/Fsi/FsiCommandParser.cs +++ b/src/Cli/dotnet/Commands/Fsi/FsiCommandParser.cs @@ -23,7 +23,8 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("fsi") { + Command command = new("fsi") + { Arguments = { Arguments }, DocsLink = DocsLink, }; diff --git a/src/Cli/dotnet/Commands/Hidden/Add/AddCommandParser.cs b/src/Cli/dotnet/Commands/Hidden/Add/AddCommandParser.cs index c2d21405b1f2..adf7357cbb2f 100644 --- a/src/Cli/dotnet/Commands/Hidden/Add/AddCommandParser.cs +++ b/src/Cli/dotnet/Commands/Hidden/Add/AddCommandParser.cs @@ -2,10 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Hidden.Add.Package; using Microsoft.DotNet.Cli.Commands.Hidden.Add.Reference; using Microsoft.DotNet.Cli.Commands.Package; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Extensions; namespace Microsoft.DotNet.Cli.Commands.Hidden.Add; diff --git a/src/Cli/dotnet/Commands/Hidden/Complete/CompleteCommand.cs b/src/Cli/dotnet/Commands/Hidden/Complete/CompleteCommand.cs index 5cdf66cfca6e..33904941b817 100644 --- a/src/Cli/dotnet/Commands/Hidden/Complete/CompleteCommand.cs +++ b/src/Cli/dotnet/Commands/Hidden/Complete/CompleteCommand.cs @@ -19,7 +19,7 @@ public static int Run(ParseResult parseResult) public static int RunWithReporter(string[] args, IReporter reporter) { - var result = Parser.Parse(["dotnet", "complete", ..args]); + var result = Parser.Parse(["dotnet", "complete", .. args]); return RunWithReporter(result, reporter); } diff --git a/src/Cli/dotnet/Commands/Hidden/InternalReportInstallSuccess/InternalReportInstallSuccessCommand.cs b/src/Cli/dotnet/Commands/Hidden/InternalReportInstallSuccess/InternalReportInstallSuccessCommand.cs index 744289023948..bed479d01816 100644 --- a/src/Cli/dotnet/Commands/Hidden/InternalReportInstallSuccess/InternalReportInstallSuccessCommand.cs +++ b/src/Cli/dotnet/Commands/Hidden/InternalReportInstallSuccess/InternalReportInstallSuccessCommand.cs @@ -25,7 +25,7 @@ public static int Run(ParseResult parseResult) public static void ProcessInputAndSendTelemetry(string[] args, ITelemetry telemetry) { - var result = Parser.Parse(["dotnet", "internal-reportinstallsuccess", ..args]); + var result = Parser.Parse(["dotnet", "internal-reportinstallsuccess", .. args]); ProcessInputAndSendTelemetry(result, telemetry); } diff --git a/src/Cli/dotnet/Commands/Hidden/List/ListCommandParser.cs b/src/Cli/dotnet/Commands/Hidden/List/ListCommandParser.cs index f471c20b62d1..22c148c8e803 100644 --- a/src/Cli/dotnet/Commands/Hidden/List/ListCommandParser.cs +++ b/src/Cli/dotnet/Commands/Hidden/List/ListCommandParser.cs @@ -4,10 +4,10 @@ #nullable disable using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Hidden.List.Package; using Microsoft.DotNet.Cli.Commands.Hidden.List.Reference; using Microsoft.DotNet.Cli.Extensions; -using Microsoft.DotNet.Cli.CommandLine; namespace Microsoft.DotNet.Cli.Commands.Hidden.List; diff --git a/src/Cli/dotnet/Commands/Hidden/Remove/RemoveCommandParser.cs b/src/Cli/dotnet/Commands/Hidden/Remove/RemoveCommandParser.cs index a91ed69540f8..f01f0c21ab7d 100644 --- a/src/Cli/dotnet/Commands/Hidden/Remove/RemoveCommandParser.cs +++ b/src/Cli/dotnet/Commands/Hidden/Remove/RemoveCommandParser.cs @@ -2,10 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Hidden.Remove.Package; using Microsoft.DotNet.Cli.Commands.Hidden.Remove.Reference; using Microsoft.DotNet.Cli.Commands.Package; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Extensions; namespace Microsoft.DotNet.Cli.Commands.Hidden.Remove; diff --git a/src/Cli/dotnet/Commands/MSBuild/MSBuildCommand.cs b/src/Cli/dotnet/Commands/MSBuild/MSBuildCommand.cs index 7e28945067a3..1e96509e2bdb 100644 --- a/src/Cli/dotnet/Commands/MSBuild/MSBuildCommand.cs +++ b/src/Cli/dotnet/Commands/MSBuild/MSBuildCommand.cs @@ -25,7 +25,7 @@ public class MSBuildCommand( { public static MSBuildCommand FromArgs(string[] args, string? msbuildPath = null) { - var result = Parser.Parse(["dotnet", "msbuild", ..args]); + var result = Parser.Parse(["dotnet", "msbuild", .. args]); return FromParseResult(result, msbuildPath); } diff --git a/src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs b/src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs index 2656f9798a9e..8015091a345e 100644 --- a/src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs +++ b/src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Globalization; diff --git a/src/Cli/dotnet/Commands/Pack/PackCommand.cs b/src/Cli/dotnet/Commands/Pack/PackCommand.cs index 9f31bfa145fe..751513edf2c0 100644 --- a/src/Cli/dotnet/Commands/Pack/PackCommand.cs +++ b/src/Cli/dotnet/Commands/Pack/PackCommand.cs @@ -25,7 +25,7 @@ public class PackCommand( { public static CommandBase FromArgs(string[] args, string? msbuildPath = null) { - var parseResult = Parser.Parse(["dotnet", "pack", ..args]); + var parseResult = Parser.Parse(["dotnet", "pack", .. args]); return FromParseResult(parseResult, msbuildPath); } diff --git a/src/Cli/dotnet/Commands/Package/Add/PackageAddCommand.cs b/src/Cli/dotnet/Commands/Package/Add/PackageAddCommand.cs index a463165828cb..0a77c290942f 100644 --- a/src/Cli/dotnet/Commands/Package/Add/PackageAddCommand.cs +++ b/src/Cli/dotnet/Commands/Package/Add/PackageAddCommand.cs @@ -6,10 +6,10 @@ using Microsoft.Build.Construction; using Microsoft.Build.Evaluation; using Microsoft.CodeAnalysis; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.MSBuild; using Microsoft.DotNet.Cli.Commands.NuGet; using Microsoft.DotNet.Cli.Commands.Run; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.FileBasedPrograms; diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs index 4ff46b804d2c..f14723e119d6 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs @@ -4,13 +4,13 @@ #nullable disable using System.CommandLine; +using System.Globalization; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Hidden.List; +using Microsoft.DotNet.Cli.Commands.MSBuild; using Microsoft.DotNet.Cli.Commands.NuGet; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.Utils; -using System.Globalization; -using Microsoft.DotNet.Cli.Commands.MSBuild; namespace Microsoft.DotNet.Cli.Commands.Package.List; diff --git a/src/Cli/dotnet/Commands/Package/PackageCommandParser.cs b/src/Cli/dotnet/Commands/Package/PackageCommandParser.cs index 16eb5873794d..85f235f8453c 100644 --- a/src/Cli/dotnet/Commands/Package/PackageCommandParser.cs +++ b/src/Cli/dotnet/Commands/Package/PackageCommandParser.cs @@ -2,12 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Package.Add; using Microsoft.DotNet.Cli.Commands.Package.List; using Microsoft.DotNet.Cli.Commands.Package.Remove; using Microsoft.DotNet.Cli.Commands.Package.Search; using Microsoft.DotNet.Cli.Commands.Run; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.Utils; using Command = System.CommandLine.Command; diff --git a/src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs b/src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs index e90099382273..e5413767c16f 100644 --- a/src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs +++ b/src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs @@ -3,9 +3,9 @@ using System.CommandLine; using System.Diagnostics; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.NuGet; using Microsoft.DotNet.Cli.Commands.Run; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.FileBasedPrograms; diff --git a/src/Cli/dotnet/Commands/Package/Search/PackageSearchCommand.cs b/src/Cli/dotnet/Commands/Package/Search/PackageSearchCommand.cs index d26a96fab237..d12c10bb0dd0 100644 --- a/src/Cli/dotnet/Commands/Package/Search/PackageSearchCommand.cs +++ b/src/Cli/dotnet/Commands/Package/Search/PackageSearchCommand.cs @@ -3,9 +3,9 @@ #nullable disable -using Microsoft.DotNet.Cli.Commands.NuGet; -using Microsoft.DotNet.Cli.CommandLine; using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Cli.Commands.NuGet; namespace Microsoft.DotNet.Cli.Commands.Package.Search; diff --git a/src/Cli/dotnet/Commands/Publish/PublishCommand.cs b/src/Cli/dotnet/Commands/Publish/PublishCommand.cs index 424a2250c25a..187238113a81 100644 --- a/src/Cli/dotnet/Commands/Publish/PublishCommand.cs +++ b/src/Cli/dotnet/Commands/Publish/PublishCommand.cs @@ -22,7 +22,7 @@ private PublishCommand( public static CommandBase FromArgs(string[] args, string? msbuildPath = null) { - var parseResult = Parser.Parse(["dotnet", "publish", ..args]); + var parseResult = Parser.Parse(["dotnet", "publish", .. args]); return FromParseResult(parseResult); } diff --git a/src/Cli/dotnet/Commands/Reference/ReferenceCommandParser.cs b/src/Cli/dotnet/Commands/Reference/ReferenceCommandParser.cs index e26cd6cd8c35..78186fcff851 100644 --- a/src/Cli/dotnet/Commands/Reference/ReferenceCommandParser.cs +++ b/src/Cli/dotnet/Commands/Reference/ReferenceCommandParser.cs @@ -4,10 +4,10 @@ #nullable disable using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Reference.Add; using Microsoft.DotNet.Cli.Commands.Reference.List; using Microsoft.DotNet.Cli.Commands.Reference.Remove; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Extensions; namespace Microsoft.DotNet.Cli.Commands.Reference; diff --git a/src/Cli/dotnet/Commands/Restore/RestoreCommand.cs b/src/Cli/dotnet/Commands/Restore/RestoreCommand.cs index 5a9ff6a37056..cd878f122ad0 100644 --- a/src/Cli/dotnet/Commands/Restore/RestoreCommand.cs +++ b/src/Cli/dotnet/Commands/Restore/RestoreCommand.cs @@ -13,7 +13,7 @@ public static class RestoreCommand { public static CommandBase FromArgs(string[] args, string? msbuildPath = null) { - var result = Parser.Parse(["dotnet", "restore", ..args]); + var result = Parser.Parse(["dotnet", "restore", .. args]); return FromParseResult(result, msbuildPath); } diff --git a/src/Cli/dotnet/Commands/Restore/RestoringCommand.cs b/src/Cli/dotnet/Commands/Restore/RestoringCommand.cs index bf75c95e16a6..f87701357182 100644 --- a/src/Cli/dotnet/Commands/Restore/RestoringCommand.cs +++ b/src/Cli/dotnet/Commands/Restore/RestoringCommand.cs @@ -37,7 +37,7 @@ public RestoringCommand( string? msbuildPath = null, string? userProfileDir = null, bool? advertiseWorkloadUpdates = null) - : base(GetCommandArguments(msbuildArgs, noRestore), msbuildPath) + : base(GetCommandArguments(msbuildArgs, noRestore), msbuildPath) { userProfileDir = CliFolderPathCalculator.DotnetUserProfileFolderPath; Task.Run(() => WorkloadManifestUpdater.BackgroundUpdateAdvertisingManifestsAsync(userProfileDir)); @@ -118,13 +118,13 @@ private static MSBuildArgs GetCommandArguments( ReadOnlyDictionary restoreProperties = msbuildArgs.GlobalProperties? .Where(kvp => !IsPropertyExcludedFromRestore(kvp.Key))? - .ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.OrdinalIgnoreCase) is { } filteredList ? new(filteredList): ReadOnlyDictionary.Empty; + .ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.OrdinalIgnoreCase) is { } filteredList ? new(filteredList) : ReadOnlyDictionary.Empty; var restoreMSBuildArgs = MSBuildArgs.FromProperties(RestoreOptimizationProperties) .CloneWithAdditionalTargets("Restore") .CloneWithExplicitArgs([.. newArgumentsToAdd, .. existingArgumentsToForward]) .CloneWithAdditionalProperties(restoreProperties); - if (msbuildArgs.Verbosity is {} verbosity) + if (msbuildArgs.Verbosity is { } verbosity) { restoreMSBuildArgs = restoreMSBuildArgs.CloneWithVerbosity(verbosity); } @@ -171,7 +171,7 @@ private static bool HasPropertyToExcludeFromRestore(MSBuildArgs msbuildArgs) private static readonly List FlagsThatTriggerSilentSeparateRestore = [.. ComputeFlags(FlagsThatTriggerSilentRestore)]; - private static readonly List PropertiesToExcludeFromSeparateRestore = [ .. PropertiesToExcludeFromRestore ]; + private static readonly List PropertiesToExcludeFromSeparateRestore = [.. PropertiesToExcludeFromRestore]; /// /// We investigate the arguments we're about to send to a separate restore call and filter out diff --git a/src/Cli/dotnet/Commands/Run/LaunchSettings/LaunchSettingsManager.cs b/src/Cli/dotnet/Commands/Run/LaunchSettings/LaunchSettingsManager.cs index a1776027476d..3e4c7b2bd53e 100644 --- a/src/Cli/dotnet/Commands/Run/LaunchSettings/LaunchSettingsManager.cs +++ b/src/Cli/dotnet/Commands/Run/LaunchSettings/LaunchSettingsManager.cs @@ -84,7 +84,7 @@ public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSett { if (prop.Value.TryGetProperty(CommandNameKey, out var commandNameElement) && commandNameElement.ValueKind == JsonValueKind.String) { - if (commandNameElement.GetString() is { } commandNameElementKey && _providers.ContainsKey(commandNameElementKey)) + if (commandNameElement.GetString() is { } commandNameElementKey && _providers.ContainsKey(commandNameElementKey)) { profileObject = prop.Value; break; @@ -120,7 +120,7 @@ public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSett } } - private static bool TryLocateHandler(string? commandName, [NotNullWhen(true)]out ILaunchSettingsProvider? provider) + private static bool TryLocateHandler(string? commandName, [NotNullWhen(true)] out ILaunchSettingsProvider? provider) { if (commandName == null) { diff --git a/src/Cli/dotnet/Commands/Run/RunCommand.cs b/src/Cli/dotnet/Commands/Run/RunCommand.cs index fb5dffd622f5..f342f1a293bd 100644 --- a/src/Cli/dotnet/Commands/Run/RunCommand.cs +++ b/src/Cli/dotnet/Commands/Run/RunCommand.cs @@ -151,7 +151,7 @@ public int Execute() // Create a single logger for all MSBuild operations (device selection + build/run) // File-based runs (.cs files) don't support device selection and should use the existing logger behavior - FacadeLogger? logger = ProjectFileFullPath is not null + FacadeLogger? logger = ProjectFileFullPath is not null ? LoggerUtility.DetermineBinlogger([.. MSBuildArgs.OtherMSBuildArgs], "dotnet-run") : null; try @@ -241,7 +241,7 @@ private bool TrySelectTargetFrameworkAndDeviceIfNeeded(FacadeLogger? logger) Debug.Assert(ProjectFileFullPath is not null); var globalProperties = CommonRunHelpers.GetGlobalPropertiesFromArgs(MSBuildArgs); - + // If user specified --device on command line, add it to global properties and MSBuildArgs if (!string.IsNullOrWhiteSpace(Device)) { @@ -255,7 +255,7 @@ private bool TrySelectTargetFrameworkAndDeviceIfNeeded(FacadeLogger? logger) // we can skip both framework selection and device selection entirely bool hasFramework = globalProperties.TryGetValue("TargetFramework", out var existingFramework) && !string.IsNullOrWhiteSpace(existingFramework); bool hasDevice = globalProperties.TryGetValue("Device", out var preSpecifiedDevice) && !string.IsNullOrWhiteSpace(preSpecifiedDevice); - + if (!ListDevices && hasFramework && hasDevice) { // Both framework and device are pre-specified, no need to create selector or logger @@ -264,7 +264,7 @@ private bool TrySelectTargetFrameworkAndDeviceIfNeeded(FacadeLogger? logger) // Create a single selector for both framework and device selection using var selector = new RunCommandSelector(ProjectFileFullPath, globalProperties, Interactive, MSBuildArgs, logger); - + // Step 1: Select target framework if needed if (!selector.TrySelectTargetFramework(out string? selectedFramework)) { @@ -274,7 +274,7 @@ private bool TrySelectTargetFrameworkAndDeviceIfNeeded(FacadeLogger? logger) if (selectedFramework is not null) { ApplySelectedFramework(selectedFramework); - + // Re-evaluate project with the selected framework so device selection sees the right devices var properties = CommonRunHelpers.GetGlobalPropertiesFromArgs(MSBuildArgs); selector.InvalidateGlobalProperties(properties); @@ -331,7 +331,7 @@ private bool TrySelectTargetFrameworkForFileBasedProject() Debug.Assert(EntryPointFileFullPath is not null); var globalProperties = CommonRunHelpers.GetGlobalPropertiesFromArgs(MSBuildArgs); - + // If a framework is already specified via --framework, no need to check if (globalProperties.TryGetValue("TargetFramework", out var existingFramework) && !string.IsNullOrWhiteSpace(existingFramework)) { @@ -363,10 +363,10 @@ private bool TrySelectTargetFrameworkForFileBasedProject() { var sourceFile = SourceFile.Load(sourceFilePath); var directives = FileLevelDirectiveHelpers.FindDirectives(sourceFile, reportAllErrors: false, DiagnosticBag.Ignore()); - + var targetFrameworksDirective = directives.OfType() .FirstOrDefault(p => string.Equals(p.Name, "TargetFrameworks", StringComparison.OrdinalIgnoreCase)); - + if (targetFrameworksDirective is null) { return null; diff --git a/src/Cli/dotnet/Commands/Run/RunCommandSelector.cs b/src/Cli/dotnet/Commands/Run/RunCommandSelector.cs index f10239673125..5ffd47961be6 100644 --- a/src/Cli/dotnet/Commands/Run/RunCommandSelector.cs +++ b/src/Cli/dotnet/Commands/Run/RunCommandSelector.cs @@ -28,7 +28,7 @@ internal sealed class RunCommandSelector : IDisposable private readonly FacadeLogger? _binaryLogger; private readonly bool _isInteractive; private readonly MSBuildArgs _msbuildArgs; - + private ProjectCollection? _collection; private Microsoft.Build.Evaluation.Project? _project; private ProjectInstance? _projectInstance; @@ -316,7 +316,7 @@ public bool TrySelectDevice( // Try to get available devices from the project bool targetExists = TryComputeAvailableDevices(noRestore, out var devices, out restoreWasPerformed); - + // If the target doesn't exist, continue without device selection if (!targetExists) { diff --git a/src/Cli/dotnet/Commands/Sdk/SdkCommandParser.cs b/src/Cli/dotnet/Commands/Sdk/SdkCommandParser.cs index 0911409cee7a..97ae4279b5dd 100644 --- a/src/Cli/dotnet/Commands/Sdk/SdkCommandParser.cs +++ b/src/Cli/dotnet/Commands/Sdk/SdkCommandParser.cs @@ -4,8 +4,8 @@ #nullable disable using System.CommandLine; -using Microsoft.DotNet.Cli.Commands.Sdk.Check; using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Cli.Commands.Sdk.Check; using Microsoft.DotNet.Cli.Extensions; namespace Microsoft.DotNet.Cli.Commands.Sdk; diff --git a/src/Cli/dotnet/Commands/Solution/Migrate/SolutionMigrateCommand.cs b/src/Cli/dotnet/Commands/Solution/Migrate/SolutionMigrateCommand.cs index 074431c8981b..8c445a02d87f 100644 --- a/src/Cli/dotnet/Commands/Solution/Migrate/SolutionMigrateCommand.cs +++ b/src/Cli/dotnet/Commands/Solution/Migrate/SolutionMigrateCommand.cs @@ -29,7 +29,9 @@ public override int Execute() { ConvertToSlnxAsync(slnFileFullPath, slnxFileFullPath, CancellationToken.None).Wait(); return 0; - } catch (Exception ex) { + } + catch (Exception ex) + { throw new GracefulException(ex.Message, ex); } } diff --git a/src/Cli/dotnet/Commands/Solution/Remove/SolutionRemoveCommand.cs b/src/Cli/dotnet/Commands/Solution/Remove/SolutionRemoveCommand.cs index 36030bd22621..a0e624ef5a4a 100644 --- a/src/Cli/dotnet/Commands/Solution/Remove/SolutionRemoveCommand.cs +++ b/src/Cli/dotnet/Commands/Solution/Remove/SolutionRemoveCommand.cs @@ -124,7 +124,7 @@ private static async Task RemoveProjectsAsync(string solutionFileFullPath, IEnum { solution.RemoveFolder(folder); // After removal, adjust index and continue to avoid skipping folders after removal - i--; + i--; } } diff --git a/src/Cli/dotnet/Commands/Solution/SolutionCommandParser.cs b/src/Cli/dotnet/Commands/Solution/SolutionCommandParser.cs index f5cc8869a10f..0bbd1cb3ab17 100644 --- a/src/Cli/dotnet/Commands/Solution/SolutionCommandParser.cs +++ b/src/Cli/dotnet/Commands/Solution/SolutionCommandParser.cs @@ -4,11 +4,11 @@ #nullable disable using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Solution.Add; using Microsoft.DotNet.Cli.Commands.Solution.List; using Microsoft.DotNet.Cli.Commands.Solution.Migrate; using Microsoft.DotNet.Cli.Commands.Solution.Remove; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Extensions; namespace Microsoft.DotNet.Cli.Commands.Solution; diff --git a/src/Cli/dotnet/Commands/Store/StoreCommand.cs b/src/Cli/dotnet/Commands/Store/StoreCommand.cs index 8ced53fdb48f..06c2b55ed631 100644 --- a/src/Cli/dotnet/Commands/Store/StoreCommand.cs +++ b/src/Cli/dotnet/Commands/Store/StoreCommand.cs @@ -4,8 +4,8 @@ #nullable disable using System.CommandLine; -using Microsoft.DotNet.Cli.Commands.MSBuild; using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Cli.Commands.MSBuild; using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.Utils; @@ -20,7 +20,7 @@ private StoreCommand(IEnumerable msbuildArgs, string msbuildPath = null) public static StoreCommand FromArgs(string[] args, string msbuildPath = null) { - var result = Parser.Parse(["dotnet", "store", ..args]); + var result = Parser.Parse(["dotnet", "store", .. args]); return FromParseResult(result, msbuildPath); } diff --git a/src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs b/src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs index fc1d2eaf2b35..768efbb7bc55 100644 --- a/src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs +++ b/src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs @@ -8,9 +8,9 @@ using Microsoft.Build.Evaluation; using Microsoft.Build.Evaluation.Context; using Microsoft.Build.Execution; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Restore; using Microsoft.DotNet.Cli.Commands.Run; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.Utils; using Microsoft.VisualStudio.SolutionPersistence.Model; diff --git a/src/Cli/dotnet/Commands/Test/MTP/TestApplicationActionQueue.cs b/src/Cli/dotnet/Commands/Test/MTP/TestApplicationActionQueue.cs index 41ee319317e7..4496703ace28 100644 --- a/src/Cli/dotnet/Commands/Test/MTP/TestApplicationActionQueue.cs +++ b/src/Cli/dotnet/Commands/Test/MTP/TestApplicationActionQueue.cs @@ -78,7 +78,7 @@ private async Task Read(BuildOptions buildOptions, TestOptions testOptions, Term { result = ExitCode.GenericFailure; } - + lock (_lock) { if (_aggregateExitCode is null) diff --git a/src/Cli/dotnet/Commands/Test/MTP/ValidationUtility.cs b/src/Cli/dotnet/Commands/Test/MTP/ValidationUtility.cs index 1e16d5cea36a..faf49f0e2175 100644 --- a/src/Cli/dotnet/Commands/Test/MTP/ValidationUtility.cs +++ b/src/Cli/dotnet/Commands/Test/MTP/ValidationUtility.cs @@ -3,8 +3,8 @@ using System.CommandLine; using System.Diagnostics.CodeAnalysis; -using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Cli.Commands.Test; diff --git a/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs b/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs index 7ef075d87530..e596c14dabb1 100644 --- a/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs +++ b/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs @@ -6,8 +6,8 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using System.Text.RegularExpressions; -using Microsoft.DotNet.Cli.Commands.Restore; using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Cli.Commands.Restore; using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils.Extensions; @@ -175,7 +175,7 @@ private static int ForwardToVSTestConsole(ParseResult parseResult, string[] args public static TestCommand FromArgs(string[] args, string? testSessionCorrelationId = null, string? msbuildPath = null) { - var parseResult = Parser.Parse(["dotnet", "test", ..args]); + var parseResult = Parser.Parse(["dotnet", "test", .. args]); // settings parameters are after -- (including --), these should not be considered by the parser string[] settings = [.. args.SkipWhile(a => a != "--")]; @@ -260,7 +260,8 @@ private static TestCommand FromParseResult(ParseResult result, string[] settings Dictionary variables = VSTestForwardingApp.GetVSTestRootVariables(); - foreach (var (rootVariableName, rootValue) in variables) { + foreach (var (rootVariableName, rootValue) in variables) + { testCommand.EnvironmentVariable(rootVariableName, rootValue); VSTestTrace.SafeWriteTrace(() => $"Root variable set {rootVariableName}:{rootValue}"); } diff --git a/src/Cli/dotnet/Commands/Test/VSTest/VSTestForwardingApp.cs b/src/Cli/dotnet/Commands/Test/VSTest/VSTestForwardingApp.cs index fb81e15466f9..26a021485c97 100644 --- a/src/Cli/dotnet/Commands/Test/VSTest/VSTestForwardingApp.cs +++ b/src/Cli/dotnet/Commands/Test/VSTest/VSTestForwardingApp.cs @@ -20,7 +20,7 @@ public VSTestForwardingApp(IEnumerable argsToForward) WithEnvironmentVariable(rootVariableName, rootValue); VSTestTrace.SafeWriteTrace(() => $"Root variable set {rootVariableName}:{rootValue}"); } - + VSTestTrace.SafeWriteTrace(() => $"Forwarding to '{GetVSTestExePath()}' with args \"{argsToForward?.Aggregate((a, b) => $"{a} | {b}")}\""); } diff --git a/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommandDefinition.cs b/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommandDefinition.cs new file mode 100644 index 000000000000..87eeeb51668e --- /dev/null +++ b/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommandDefinition.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.CommandLine; +using Microsoft.DotNet.Cli.Commands.Tool.Install; + +namespace Microsoft.DotNet.Cli.Commands.Tool.Execute; + +internal static class ToolExecuteCommandDefinition +{ + public static readonly Argument PackageIdentityArgument = ToolInstallCommandParser.PackageIdentityArgument; + + public static readonly Argument> CommandArgument = new("commandArguments") + { + Description = CliCommandStrings.ToolRunArgumentsDescription + }; + + public static readonly Option VersionOption = ToolInstallCommandParser.VersionOption; + public static readonly Option RollForwardOption = ToolInstallCommandParser.RollForwardOption; + public static readonly Option PrereleaseOption = ToolInstallCommandParser.PrereleaseOption; + public static readonly Option ConfigOption = ToolInstallCommandParser.ConfigOption; + public static readonly Option SourceOption = ToolInstallCommandParser.SourceOption; + public static readonly Option AddSourceOption = ToolInstallCommandParser.AddSourceOption; + public static readonly Option InteractiveOption = CommonOptions.InteractiveOption(); + public static readonly Option YesOption = CommonOptions.YesOption; + public static readonly Option VerbosityOption = ToolInstallCommandParser.VerbosityOption; + + public static Command Create() + { + Command command = new("execute", CliCommandStrings.ToolExecuteCommandDescription); + + command.Aliases.Add("exec"); + + command.Arguments.Add(PackageIdentityArgument); + command.Arguments.Add(CommandArgument); + + command.Options.Add(VersionOption); + command.Options.Add(YesOption); + command.Options.Add(InteractiveOption); + command.Options.Add(RollForwardOption); + command.Options.Add(PrereleaseOption); + command.Options.Add(ConfigOption); + command.Options.Add(SourceOption); + command.Options.Add(AddSourceOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.DisableParallelOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.NoCacheOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.NoHttpCacheOption); + command.Options.Add(VerbosityOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommandParser.cs b/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommandParser.cs index 8bc5479916c5..8571801cf2cb 100644 --- a/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommandParser.cs +++ b/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommandParser.cs @@ -7,27 +7,23 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Execute; internal static class ToolExecuteCommandParser - { - public static readonly Argument PackageIdentityArgument = ToolInstallCommandParser.PackageIdentityArgument; - - public static readonly Argument> CommandArgument = new("commandArguments") - { - Description = CliCommandStrings.ToolRunArgumentsDescription - }; + public static readonly Argument PackageIdentityArgument = ToolExecuteCommandDefinition.PackageIdentityArgument; - public static readonly Option VersionOption = ToolInstallCommandParser.VersionOption; - public static readonly Option RollForwardOption = ToolInstallCommandParser.RollForwardOption; - public static readonly Option PrereleaseOption = ToolInstallCommandParser.PrereleaseOption; - public static readonly Option ConfigOption = ToolInstallCommandParser.ConfigOption; - public static readonly Option SourceOption = ToolInstallCommandParser.SourceOption; - public static readonly Option AddSourceOption = ToolInstallCommandParser.AddSourceOption; - public static readonly Option InteractiveOption = CommonOptions.InteractiveOption(); - public static readonly Option YesOption = CommonOptions.YesOption; - public static readonly Option VerbosityOption = ToolInstallCommandParser.VerbosityOption; + public static readonly Argument> CommandArgument = ToolExecuteCommandDefinition.CommandArgument; + public static readonly Option VersionOption = ToolExecuteCommandDefinition.VersionOption; + public static readonly Option RollForwardOption = ToolExecuteCommandDefinition.RollForwardOption; + public static readonly Option PrereleaseOption = ToolExecuteCommandDefinition.PrereleaseOption; + public static readonly Option ConfigOption = ToolExecuteCommandDefinition.ConfigOption; + public static readonly Option SourceOption = ToolExecuteCommandDefinition.SourceOption; + public static readonly Option AddSourceOption = ToolExecuteCommandDefinition.AddSourceOption; + public static readonly Option InteractiveOption = ToolExecuteCommandDefinition.InteractiveOption; + public static readonly Option YesOption = ToolExecuteCommandDefinition.YesOption; + public static readonly Option VerbosityOption = ToolExecuteCommandDefinition.VerbosityOption; public static readonly Command Command = ConstructCommand(); + public static Command GetCommand() { return Command; @@ -35,26 +31,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("execute", CliCommandStrings.ToolExecuteCommandDescription); - - command.Aliases.Add("exec"); - - command.Arguments.Add(PackageIdentityArgument); - command.Arguments.Add(CommandArgument); - - command.Options.Add(VersionOption); - command.Options.Add(YesOption); - command.Options.Add(InteractiveOption); - command.Options.Add(RollForwardOption); - command.Options.Add(PrereleaseOption); - command.Options.Add(ConfigOption); - command.Options.Add(SourceOption); - command.Options.Add(AddSourceOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.DisableParallelOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.NoCacheOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.NoHttpCacheOption); - command.Options.Add(VerbosityOption); + Command command = ToolExecuteCommandDefinition.Create(); command.SetAction((parseResult) => new ToolExecuteCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Tool/Install/ToolInstallCommandDefinition.cs b/src/Cli/dotnet/Commands/Tool/Install/ToolInstallCommandDefinition.cs new file mode 100644 index 000000000000..b97f33ead35a --- /dev/null +++ b/src/Cli/dotnet/Commands/Tool/Install/ToolInstallCommandDefinition.cs @@ -0,0 +1,118 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Cli.Commands.Tool.Common; +using Microsoft.DotNet.Cli.Commands.Tool.Search; + +namespace Microsoft.DotNet.Cli.Commands.Tool.Install; + +internal static class ToolInstallCommandDefinition +{ + public static readonly Argument PackageIdentityArgument = CommonArguments.RequiredPackageIdentityArgument("dotnetsay", "2.1.7"); + + public static readonly Option VersionOption = new("--version") + { + Description = CliCommandStrings.ToolInstallVersionOptionDescription, + HelpName = CliCommandStrings.ToolInstallVersionOptionName + }; + + public static readonly Option ConfigOption = new("--configfile") + { + Description = CliCommandStrings.ToolInstallConfigFileOptionDescription, + HelpName = CliCommandStrings.ToolInstallConfigFileOptionName + }; + + public static readonly Option SourceOption = new Option("--source") + { + Description = CliCommandStrings.ToolInstallSourceOptionDescription, + HelpName = CliCommandStrings.ToolInstallSourceOptionName + }.AllowSingleArgPerToken(); + + public static readonly Option AddSourceOption = new Option("--add-source") + { + Description = CliCommandStrings.ToolInstallAddSourceOptionDescription, + HelpName = CliCommandStrings.ToolInstallAddSourceOptionName + }.AllowSingleArgPerToken(); + + public static readonly Option FrameworkOption = new("--framework") + { + Description = CliCommandStrings.ToolInstallFrameworkOptionDescription, + HelpName = CliCommandStrings.ToolInstallFrameworkOptionName + }; + + public static readonly Option PrereleaseOption = ToolSearchCommandParser.PrereleaseOption; + + public static readonly Option CreateManifestIfNeededOption = new("--create-manifest-if-needed") + { + Description = CliCommandStrings.CreateManifestIfNeededOptionDescription, + Arity = ArgumentArity.ZeroOrOne, + DefaultValueFactory = _ => true, + }; + + public static readonly Option AllowPackageDowngradeOption = new("--allow-downgrade") + { + Description = CliCommandStrings.AllowPackageDowngradeOptionDescription, + Arity = ArgumentArity.Zero + }; + + public static readonly Option VerbosityOption = CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal); + + // Don't use the common options version as we don't want this to be a forwarded option + public static readonly Option ArchitectureOption = new("--arch", "-a") + { + Description = CliStrings.ArchitectureOptionDescription + }; + + public static readonly Option RollForwardOption = new("--allow-roll-forward") + { + Description = CliCommandStrings.RollForwardOptionDescription, + Arity = ArgumentArity.Zero + }; + + public static readonly Option GlobalOption = ToolAppliedOption.GlobalOption(CliCommandStrings.ToolInstallGlobalOptionDescription); + + public static readonly Option LocalOption = ToolAppliedOption.LocalOption(CliCommandStrings.ToolInstallLocalOptionDescription); + + public static readonly Option ToolPathOption = ToolAppliedOption.ToolPathOption(CliCommandStrings.ToolInstallToolPathOptionDescription); + + public static readonly Option ToolManifestOption = ToolAppliedOption.ToolManifestOption(CliCommandStrings.ToolInstallManifestPathOptionDescription); + + public static Command Create() + { + Command command = new("install", CliCommandStrings.ToolInstallCommandDescription); + command.Arguments.Add(PackageIdentityArgument); + + AddCommandOptions(command); + + command.Options.Add(ArchitectureOption); + command.Options.Add(CreateManifestIfNeededOption); + command.Options.Add(AllowPackageDowngradeOption); + command.Options.Add(RollForwardOption); + + return command; + } + + public static Command AddCommandOptions(Command command) + { + command.Options.Add(GlobalOption); + command.Options.Add(LocalOption); + command.Options.Add(ToolPathOption); + command.Options.Add(VersionOption); + command.Options.Add(ConfigOption); + command.Options.Add(ToolManifestOption); + command.Options.Add(AddSourceOption); + command.Options.Add(SourceOption); + command.Options.Add(FrameworkOption); + command.Options.Add(PrereleaseOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.DisableParallelOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.NoCacheOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.NoHttpCacheOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption); + command.Options.Add(VerbosityOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Tool/Install/ToolInstallCommandParser.cs b/src/Cli/dotnet/Commands/Tool/Install/ToolInstallCommandParser.cs index 53e1367eee08..3e05f538ed53 100644 --- a/src/Cli/dotnet/Commands/Tool/Install/ToolInstallCommandParser.cs +++ b/src/Cli/dotnet/Commands/Tool/Install/ToolInstallCommandParser.cs @@ -2,82 +2,45 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Tool.Common; using Microsoft.DotNet.Cli.Commands.Tool.Search; -using Microsoft.DotNet.Cli.CommandLine; namespace Microsoft.DotNet.Cli.Commands.Tool.Install; internal static class ToolInstallCommandParser { - public static readonly Argument PackageIdentityArgument = CommonArguments.RequiredPackageIdentityArgument("dotnetsay", "2.1.7"); + public static readonly Argument PackageIdentityArgument = ToolInstallCommandDefinition.PackageIdentityArgument; - public static readonly Option VersionOption = new("--version") - { - Description = CliCommandStrings.ToolInstallVersionOptionDescription, - HelpName = CliCommandStrings.ToolInstallVersionOptionName - }; + public static readonly Option VersionOption = ToolInstallCommandDefinition.VersionOption; - public static readonly Option ConfigOption = new("--configfile") - { - Description = CliCommandStrings.ToolInstallConfigFileOptionDescription, - HelpName = CliCommandStrings.ToolInstallConfigFileOptionName - }; + public static readonly Option ConfigOption = ToolInstallCommandDefinition.ConfigOption; - public static readonly Option SourceOption = new Option("--source") - { - Description = CliCommandStrings.ToolInstallSourceOptionDescription, - HelpName = CliCommandStrings.ToolInstallSourceOptionName - }.AllowSingleArgPerToken(); + public static readonly Option SourceOption = ToolInstallCommandDefinition.SourceOption; - public static readonly Option AddSourceOption = new Option("--add-source") - { - Description = CliCommandStrings.ToolInstallAddSourceOptionDescription, - HelpName = CliCommandStrings.ToolInstallAddSourceOptionName - }.AllowSingleArgPerToken(); + public static readonly Option AddSourceOption = ToolInstallCommandDefinition.AddSourceOption; - public static readonly Option FrameworkOption = new("--framework") - { - Description = CliCommandStrings.ToolInstallFrameworkOptionDescription, - HelpName = CliCommandStrings.ToolInstallFrameworkOptionName - }; + public static readonly Option FrameworkOption = ToolInstallCommandDefinition.FrameworkOption; - public static readonly Option PrereleaseOption = ToolSearchCommandParser.PrereleaseOption; + public static readonly Option PrereleaseOption = ToolInstallCommandDefinition.PrereleaseOption; - public static readonly Option CreateManifestIfNeededOption = new("--create-manifest-if-needed") - { - Description = CliCommandStrings.CreateManifestIfNeededOptionDescription, - Arity = ArgumentArity.ZeroOrOne, - DefaultValueFactory = _ => true, - }; + public static readonly Option CreateManifestIfNeededOption = ToolInstallCommandDefinition.CreateManifestIfNeededOption; - public static readonly Option AllowPackageDowngradeOption = new("--allow-downgrade") - { - Description = CliCommandStrings.AllowPackageDowngradeOptionDescription, - Arity = ArgumentArity.Zero - }; + public static readonly Option AllowPackageDowngradeOption = ToolInstallCommandDefinition.AllowPackageDowngradeOption; - public static readonly Option VerbosityOption = CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal); + public static readonly Option VerbosityOption = ToolInstallCommandDefinition.VerbosityOption; - // Don't use the common options version as we don't want this to be a forwarded option - public static readonly Option ArchitectureOption = new("--arch", "-a") - { - Description = CliStrings.ArchitectureOptionDescription - }; + public static readonly Option ArchitectureOption = ToolInstallCommandDefinition.ArchitectureOption; - public static readonly Option RollForwardOption = new("--allow-roll-forward") - { - Description = CliCommandStrings.RollForwardOptionDescription, - Arity = ArgumentArity.Zero - }; + public static readonly Option RollForwardOption = ToolInstallCommandDefinition.RollForwardOption; - public static readonly Option GlobalOption = ToolAppliedOption.GlobalOption(CliCommandStrings.ToolInstallGlobalOptionDescription); + public static readonly Option GlobalOption = ToolInstallCommandDefinition.GlobalOption; - public static readonly Option LocalOption = ToolAppliedOption.LocalOption(CliCommandStrings.ToolInstallLocalOptionDescription); + public static readonly Option LocalOption = ToolInstallCommandDefinition.LocalOption; - public static readonly Option ToolPathOption = ToolAppliedOption.ToolPathOption(CliCommandStrings.ToolInstallToolPathOptionDescription); + public static readonly Option ToolPathOption = ToolInstallCommandDefinition.ToolPathOption; - public static readonly Option ToolManifestOption = ToolAppliedOption.ToolManifestOption(CliCommandStrings.ToolInstallManifestPathOptionDescription); + public static readonly Option ToolManifestOption = ToolInstallCommandDefinition.ToolManifestOption; private static readonly Command Command = ConstructCommand(); @@ -88,15 +51,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("install", CliCommandStrings.ToolInstallCommandDescription); - command.Arguments.Add(PackageIdentityArgument); - - AddCommandOptions(command); - - command.Options.Add(ArchitectureOption); - command.Options.Add(CreateManifestIfNeededOption); - command.Options.Add(AllowPackageDowngradeOption); - command.Options.Add(RollForwardOption); + Command command = ToolInstallCommandDefinition.Create(); command.SetAction((parseResult) => new ToolInstallCommand(parseResult).Execute()); @@ -105,23 +60,6 @@ private static Command ConstructCommand() public static Command AddCommandOptions(Command command) { - command.Options.Add(GlobalOption); - command.Options.Add(LocalOption); - command.Options.Add(ToolPathOption); - command.Options.Add(VersionOption); - command.Options.Add(ConfigOption); - command.Options.Add(ToolManifestOption); - command.Options.Add(AddSourceOption); - command.Options.Add(SourceOption); - command.Options.Add(FrameworkOption); - command.Options.Add(PrereleaseOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.DisableParallelOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.NoCacheOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.NoHttpCacheOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption); - command.Options.Add(VerbosityOption); - - return command; + return ToolInstallCommandDefinition.AddCommandOptions(command); } } diff --git a/src/Cli/dotnet/Commands/Tool/Install/ToolInstallGlobalOrToolPathCommand.cs b/src/Cli/dotnet/Commands/Tool/Install/ToolInstallGlobalOrToolPathCommand.cs index b0e6af77de1a..4474482fb151 100644 --- a/src/Cli/dotnet/Commands/Tool/Install/ToolInstallGlobalOrToolPathCommand.cs +++ b/src/Cli/dotnet/Commands/Tool/Install/ToolInstallGlobalOrToolPathCommand.cs @@ -2,20 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Cli.Commands.Tool.List; +using Microsoft.DotNet.Cli.Commands.Tool.Uninstall; +using Microsoft.DotNet.Cli.Commands.Tool.Update; +using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.NuGetPackageDownloader; +using Microsoft.DotNet.Cli.ShellShim; using Microsoft.DotNet.Cli.ToolPackage; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Cli.Utils.Extensions; using Microsoft.Extensions.EnvironmentAbstractions; using NuGet.Common; using NuGet.Frameworks; using NuGet.Versioning; -using Microsoft.DotNet.Cli.Utils.Extensions; -using Microsoft.DotNet.Cli.CommandLine; -using Microsoft.DotNet.Cli.Extensions; -using Microsoft.DotNet.Cli.ShellShim; -using Microsoft.DotNet.Cli.Commands.Tool.Update; -using Microsoft.DotNet.Cli.Commands.Tool.Uninstall; -using Microsoft.DotNet.Cli.Commands.Tool.List; namespace Microsoft.DotNet.Cli.Commands.Tool.Install; diff --git a/src/Cli/dotnet/Commands/Tool/Install/ToolInstallLocalCommand.cs b/src/Cli/dotnet/Commands/Tool/Install/ToolInstallLocalCommand.cs index 87fb7860f992..e0bf8ccd3247 100644 --- a/src/Cli/dotnet/Commands/Tool/Install/ToolInstallLocalCommand.cs +++ b/src/Cli/dotnet/Commands/Tool/Install/ToolInstallLocalCommand.cs @@ -83,7 +83,7 @@ public override int Execute() } else { - return ExecuteInstallCommand((PackageId) _packageId); + return ExecuteInstallCommand((PackageId)_packageId); } } diff --git a/src/Cli/dotnet/Commands/Tool/List/ToolListCommandDefinition.cs b/src/Cli/dotnet/Commands/Tool/List/ToolListCommandDefinition.cs new file mode 100644 index 000000000000..6e9ca95c7e90 --- /dev/null +++ b/src/Cli/dotnet/Commands/Tool/List/ToolListCommandDefinition.cs @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; +using Microsoft.DotNet.Cli.Commands.Tool.Common; +using Microsoft.DotNet.Cli.Extensions; + +namespace Microsoft.DotNet.Cli.Commands.Tool.List; + +internal static class ToolListCommandDefinition +{ + public static readonly Argument PackageIdArgument = new("packageId") + { + HelpName = CliCommandStrings.ToolListPackageIdArgumentName, + Description = CliCommandStrings.ToolListPackageIdArgumentDescription, + Arity = ArgumentArity.ZeroOrOne, + }; + + public static readonly Option GlobalOption = ToolAppliedOption.GlobalOption(CliCommandStrings.ToolListGlobalOptionDescription); + + public static readonly Option LocalOption = ToolAppliedOption.LocalOption(CliCommandStrings.ToolListLocalOptionDescription); + + public static readonly Option ToolPathOption = ToolAppliedOption.ToolPathOption(CliCommandStrings.ToolListToolPathOptionDescription); + + public static readonly Option ToolListFormatOption = new("--format") + { + Arity = ArgumentArity.ZeroOrOne, + DefaultValueFactory = _ => ToolListOutputFormat.table, + Description = CliCommandStrings.ToolListFormatOptionDescription + }; + + public static Command Create() + { + Command command = new("list", CliCommandStrings.ToolListCommandDescription); + + command.Arguments.Add(PackageIdArgument); + command.Options.Add(GlobalOption); + command.Options.Add(LocalOption); + command.Options.Add(ToolPathOption); + command.Options.Add(ToolListFormatOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Tool/List/ToolListCommandParser.cs b/src/Cli/dotnet/Commands/Tool/List/ToolListCommandParser.cs index 89ad305f7872..18d15832e0cf 100644 --- a/src/Cli/dotnet/Commands/Tool/List/ToolListCommandParser.cs +++ b/src/Cli/dotnet/Commands/Tool/List/ToolListCommandParser.cs @@ -11,25 +11,15 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.List; internal static class ToolListCommandParser { - public static readonly Argument PackageIdArgument = new("packageId") - { - HelpName = CliCommandStrings.ToolListPackageIdArgumentName, - Description = CliCommandStrings.ToolListPackageIdArgumentDescription, - Arity = ArgumentArity.ZeroOrOne, - }; + public static readonly Argument PackageIdArgument = ToolListCommandDefinition.PackageIdArgument; - public static readonly Option GlobalOption = ToolAppliedOption.GlobalOption(CliCommandStrings.ToolListGlobalOptionDescription); + public static readonly Option GlobalOption = ToolListCommandDefinition.GlobalOption; - public static readonly Option LocalOption = ToolAppliedOption.LocalOption(CliCommandStrings.ToolListLocalOptionDescription); + public static readonly Option LocalOption = ToolListCommandDefinition.LocalOption; - public static readonly Option ToolPathOption = ToolAppliedOption.ToolPathOption(CliCommandStrings.ToolListToolPathOptionDescription); + public static readonly Option ToolPathOption = ToolListCommandDefinition.ToolPathOption; - public static readonly Option ToolListFormatOption = new("--format") - { - Arity = ArgumentArity.ZeroOrOne, - DefaultValueFactory = _ => ToolListOutputFormat.table, - Description = CliCommandStrings.ToolListFormatOptionDescription - }; + public static readonly Option ToolListFormatOption = ToolListCommandDefinition.ToolListFormatOption; private static readonly Command Command = ConstructCommand(); @@ -40,13 +30,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("list", CliCommandStrings.ToolListCommandDescription); - - command.Arguments.Add(PackageIdArgument); - command.Options.Add(GlobalOption); - command.Options.Add(LocalOption); - command.Options.Add(ToolPathOption); - command.Options.Add(ToolListFormatOption); + Command command = ToolListCommandDefinition.Create(); command.SetAction((parseResult) => new ToolListCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Tool/List/ToolListJsonHelper.cs b/src/Cli/dotnet/Commands/Tool/List/ToolListJsonHelper.cs index 2ff9552ceeca..914f19efe192 100644 --- a/src/Cli/dotnet/Commands/Tool/List/ToolListJsonHelper.cs +++ b/src/Cli/dotnet/Commands/Tool/List/ToolListJsonHelper.cs @@ -10,12 +10,12 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.List; internal sealed class VersionedDataContract { - /// - /// The version of the JSON format for dotnet tool list. - /// + /// + /// The version of the JSON format for dotnet tool list. + /// [JsonPropertyName("version")] public int Version { get; init; } = 1; - + [JsonPropertyName("data")] public required TContract Data { get; init; } } @@ -24,10 +24,10 @@ internal class ToolListJsonContract { [JsonPropertyName("packageId")] public required string PackageId { get; init; } - + [JsonPropertyName("version")] public required string Version { get; init; } - + [JsonPropertyName("commands")] public required string[] Commands { get; init; } } diff --git a/src/Cli/dotnet/Commands/Tool/Restore/ToolPackageRestorer.cs b/src/Cli/dotnet/Commands/Tool/Restore/ToolPackageRestorer.cs index b1c3b3f4ed52..1377a97cb006 100644 --- a/src/Cli/dotnet/Commands/Tool/Restore/ToolPackageRestorer.cs +++ b/src/Cli/dotnet/Commands/Tool/Restore/ToolPackageRestorer.cs @@ -109,7 +109,7 @@ private static bool ManifestCommandMatchesActualInPackage( IReadOnlyList toolPackageCommands) { ToolCommandName[] commandsFromPackage = [.. toolPackageCommands.Select(t => t.Name)]; -return !commandsFromManifest.Any(cmd => !commandsFromPackage.Contains(cmd)) && !commandsFromPackage.Any(cmd => !commandsFromManifest.Contains(cmd)); + return !commandsFromManifest.Any(cmd => !commandsFromPackage.Contains(cmd)) && !commandsFromPackage.Any(cmd => !commandsFromManifest.Contains(cmd)); } public bool PackageHasBeenRestored( diff --git a/src/Cli/dotnet/Commands/Tool/Restore/ToolRestoreCommandDefinition.cs b/src/Cli/dotnet/Commands/Tool/Restore/ToolRestoreCommandDefinition.cs new file mode 100644 index 000000000000..364c7f92a5ef --- /dev/null +++ b/src/Cli/dotnet/Commands/Tool/Restore/ToolRestoreCommandDefinition.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; +using Microsoft.DotNet.Cli.Commands.Tool.Common; +using Microsoft.DotNet.Cli.Commands.Tool.Install; +using Microsoft.DotNet.Cli.Extensions; + +namespace Microsoft.DotNet.Cli.Commands.Tool.Restore; + +internal static class ToolRestoreCommandDefinition +{ + public static readonly Option ConfigOption = ToolInstallCommandParser.ConfigOption; + + public static readonly Option AddSourceOption = ToolInstallCommandParser.AddSourceOption; + + public static readonly Option ToolManifestOption = ToolAppliedOption.ToolManifestOption(CliCommandStrings.ToolRestoreManifestPathOptionDescription); + + public static readonly Option VerbosityOption = ToolInstallCommandParser.VerbosityOption; + + public static Command Create() + { + Command command = new("restore", CliCommandStrings.ToolRestoreCommandDescription); + + command.Options.Add(ConfigOption); + command.Options.Add(AddSourceOption); + command.Options.Add(ToolManifestOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.DisableParallelOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.NoCacheOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.NoHttpCacheOption); + command.Options.Add(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption); + command.Options.Add(VerbosityOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Tool/Restore/ToolRestoreCommandParser.cs b/src/Cli/dotnet/Commands/Tool/Restore/ToolRestoreCommandParser.cs index ee39785b855c..7cfc7d94590f 100644 --- a/src/Cli/dotnet/Commands/Tool/Restore/ToolRestoreCommandParser.cs +++ b/src/Cli/dotnet/Commands/Tool/Restore/ToolRestoreCommandParser.cs @@ -12,13 +12,13 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Restore; internal static class ToolRestoreCommandParser { - public static readonly Option ConfigOption = ToolInstallCommandParser.ConfigOption; + public static readonly Option ConfigOption = ToolRestoreCommandDefinition.ConfigOption; - public static readonly Option AddSourceOption = ToolInstallCommandParser.AddSourceOption; + public static readonly Option AddSourceOption = ToolRestoreCommandDefinition.AddSourceOption; - public static readonly Option ToolManifestOption = ToolAppliedOption.ToolManifestOption(CliCommandStrings.ToolRestoreManifestPathOptionDescription); + public static readonly Option ToolManifestOption = ToolRestoreCommandDefinition.ToolManifestOption; - public static readonly Option VerbosityOption = ToolInstallCommandParser.VerbosityOption; + public static readonly Option VerbosityOption = ToolRestoreCommandDefinition.VerbosityOption; private static readonly Command Command = ConstructCommand(); @@ -29,17 +29,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("restore", CliCommandStrings.ToolRestoreCommandDescription); - - command.Options.Add(ConfigOption); - command.Options.Add(AddSourceOption); - command.Options.Add(ToolManifestOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.DisableParallelOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.NoCacheOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.NoHttpCacheOption); - command.Options.Add(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption); - command.Options.Add(VerbosityOption); + Command command = ToolRestoreCommandDefinition.Create(); command.SetAction((parseResult) => new ToolRestoreCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Tool/Run/ToolRunCommandDefinition.cs b/src/Cli/dotnet/Commands/Tool/Run/ToolRunCommandDefinition.cs new file mode 100644 index 000000000000..985f74129824 --- /dev/null +++ b/src/Cli/dotnet/Commands/Tool/Run/ToolRunCommandDefinition.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; + +namespace Microsoft.DotNet.Cli.Commands.Tool.Run; + +internal static class ToolRunCommandDefinition +{ + public static readonly Argument CommandNameArgument = new("commandName") + { + HelpName = CliCommandStrings.CommandNameArgumentName, + Description = CliCommandStrings.CommandNameArgumentDescription + }; + + public static readonly Argument> CommandArgument = new("toolArguments") + { + Description = CliCommandStrings.ToolRunArgumentsDescription + }; + + public static readonly Option RollForwardOption = new("--allow-roll-forward") + { + Description = CliCommandStrings.RollForwardOptionDescription, + Arity = ArgumentArity.Zero + }; + + public static Command Create() + { + Command command = new("run", CliCommandStrings.ToolRunCommandDescription); + + command.Arguments.Add(CommandNameArgument); + command.Arguments.Add(CommandArgument); + command.Options.Add(RollForwardOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Tool/Run/ToolRunCommandParser.cs b/src/Cli/dotnet/Commands/Tool/Run/ToolRunCommandParser.cs index 05d085926580..d621e649bcbf 100644 --- a/src/Cli/dotnet/Commands/Tool/Run/ToolRunCommandParser.cs +++ b/src/Cli/dotnet/Commands/Tool/Run/ToolRunCommandParser.cs @@ -9,22 +9,11 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Run; internal static class ToolRunCommandParser { - public static readonly Argument CommandNameArgument = new("commandName") - { - HelpName = CliCommandStrings.CommandNameArgumentName, - Description = CliCommandStrings.CommandNameArgumentDescription - }; + public static readonly Argument CommandNameArgument = ToolRunCommandDefinition.CommandNameArgument; - public static readonly Argument> CommandArgument = new("toolArguments") - { - Description = CliCommandStrings.ToolRunArgumentsDescription - }; + public static readonly Argument> CommandArgument = ToolRunCommandDefinition.CommandArgument; - public static readonly Option RollForwardOption = new("--allow-roll-forward") - { - Description = CliCommandStrings.RollForwardOptionDescription, - Arity = ArgumentArity.Zero - }; + public static readonly Option RollForwardOption = ToolRunCommandDefinition.RollForwardOption; private static readonly Command Command = ConstructCommand(); @@ -35,11 +24,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("run", CliCommandStrings.ToolRunCommandDescription); - - command.Arguments.Add(CommandNameArgument); - command.Arguments.Add(CommandArgument); - command.Options.Add(RollForwardOption); + Command command = ToolRunCommandDefinition.Create(); command.SetAction((parseResult) => new ToolRunCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Tool/Search/ToolSearchCommandDefinition.cs b/src/Cli/dotnet/Commands/Tool/Search/ToolSearchCommandDefinition.cs new file mode 100644 index 000000000000..12f88fb10398 --- /dev/null +++ b/src/Cli/dotnet/Commands/Tool/Search/ToolSearchCommandDefinition.cs @@ -0,0 +1,55 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; + +namespace Microsoft.DotNet.Cli.Commands.Tool.Search; + +internal static class ToolSearchCommandDefinition +{ + public static readonly Argument SearchTermArgument = new("searchTerm") + { + HelpName = CliCommandStrings.ToolSearchSearchTermArgumentName, + Description = CliCommandStrings.ToolSearchSearchTermDescription + }; + + public static readonly Option DetailOption = new("--detail") + { + Description = CliCommandStrings.DetailDescription, + Arity = ArgumentArity.Zero + }; + + public static readonly Option SkipOption = new("--skip") + { + Description = CliCommandStrings.ToolSearchSkipDescription, + HelpName = CliCommandStrings.ToolSearchSkipArgumentName + }; + + public static readonly Option TakeOption = new("--take") + { + Description = CliCommandStrings.ToolSearchTakeDescription, + HelpName = CliCommandStrings.ToolSearchTakeArgumentName + }; + + public static readonly Option PrereleaseOption = new("--prerelease") + { + Description = CliCommandStrings.ToolSearchPrereleaseDescription, + Arity = ArgumentArity.Zero + }; + + public static Command Create() + { + Command command = new("search", CliCommandStrings.ToolSearchCommandDescription); + + command.Arguments.Add(SearchTermArgument); + + command.Options.Add(DetailOption); + command.Options.Add(SkipOption); + command.Options.Add(TakeOption); + command.Options.Add(PrereleaseOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Tool/Search/ToolSearchCommandParser.cs b/src/Cli/dotnet/Commands/Tool/Search/ToolSearchCommandParser.cs index 2be6a3a4e7ec..7379f03c6f21 100644 --- a/src/Cli/dotnet/Commands/Tool/Search/ToolSearchCommandParser.cs +++ b/src/Cli/dotnet/Commands/Tool/Search/ToolSearchCommandParser.cs @@ -9,35 +9,15 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Search; internal static class ToolSearchCommandParser { - public static readonly Argument SearchTermArgument = new("searchTerm") - { - HelpName = CliCommandStrings.ToolSearchSearchTermArgumentName, - Description = CliCommandStrings.ToolSearchSearchTermDescription - }; + public static readonly Argument SearchTermArgument = ToolSearchCommandDefinition.SearchTermArgument; - public static readonly Option DetailOption = new("--detail") - { - Description = CliCommandStrings.DetailDescription, - Arity = ArgumentArity.Zero - }; + public static readonly Option DetailOption = ToolSearchCommandDefinition.DetailOption; - public static readonly Option SkipOption = new("--skip") - { - Description = CliCommandStrings.ToolSearchSkipDescription, - HelpName = CliCommandStrings.ToolSearchSkipArgumentName - }; + public static readonly Option SkipOption = ToolSearchCommandDefinition.SkipOption; - public static readonly Option TakeOption = new("--take") - { - Description = CliCommandStrings.ToolSearchTakeDescription, - HelpName = CliCommandStrings.ToolSearchTakeArgumentName - }; + public static readonly Option TakeOption = ToolSearchCommandDefinition.TakeOption; - public static readonly Option PrereleaseOption = new("--prerelease") - { - Description = CliCommandStrings.ToolSearchPrereleaseDescription, - Arity = ArgumentArity.Zero - }; + public static readonly Option PrereleaseOption = ToolSearchCommandDefinition.PrereleaseOption; private static readonly Command Command = ConstructCommand(); @@ -48,14 +28,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("search", CliCommandStrings.ToolSearchCommandDescription); - - command.Arguments.Add(SearchTermArgument); - - command.Options.Add(DetailOption); - command.Options.Add(SkipOption); - command.Options.Add(TakeOption); - command.Options.Add(PrereleaseOption); + Command command = ToolSearchCommandDefinition.Create(); command.SetAction((parseResult) => new ToolSearchCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Tool/ToolCommandParser.cs b/src/Cli/dotnet/Commands/Tool/ToolCommandParser.cs index 5354c9355e67..ca68d2b813f0 100644 --- a/src/Cli/dotnet/Commands/Tool/ToolCommandParser.cs +++ b/src/Cli/dotnet/Commands/Tool/ToolCommandParser.cs @@ -4,6 +4,7 @@ #nullable disable using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Tool.Execute; using Microsoft.DotNet.Cli.Commands.Tool.Install; using Microsoft.DotNet.Cli.Commands.Tool.List; @@ -12,7 +13,6 @@ using Microsoft.DotNet.Cli.Commands.Tool.Search; using Microsoft.DotNet.Cli.Commands.Tool.Uninstall; using Microsoft.DotNet.Cli.Commands.Tool.Update; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Extensions; namespace Microsoft.DotNet.Cli.Commands.Tool; diff --git a/src/Cli/dotnet/Commands/Tool/Uninstall/ToolUninstallCommandDefinition.cs b/src/Cli/dotnet/Commands/Tool/Uninstall/ToolUninstallCommandDefinition.cs new file mode 100644 index 000000000000..959dfbef2a31 --- /dev/null +++ b/src/Cli/dotnet/Commands/Tool/Uninstall/ToolUninstallCommandDefinition.cs @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; +using Microsoft.DotNet.Cli.Commands.Tool.Common; +using Microsoft.DotNet.Cli.Commands.Tool.Install; +using Microsoft.DotNet.Cli.Extensions; +using NuGet.Packaging.Core; + +namespace Microsoft.DotNet.Cli.Commands.Tool.Uninstall; + +internal static class ToolUninstallCommandDefinition +{ + public static readonly Argument PackageIdArgument = new("packageId") + { + HelpName = "PACKAGE_ID", + Description = CliStrings.PackageReference, + Arity = ArgumentArity.ExactlyOne + }; + + public static readonly Option GlobalOption = ToolAppliedOption.GlobalOption(CliCommandStrings.ToolUninstallGlobalOptionDescription); + + public static readonly Option LocalOption = ToolAppliedOption.LocalOption(CliCommandStrings.ToolUninstallLocalOptionDescription); + + public static readonly Option ToolPathOption = ToolAppliedOption.ToolPathOption(CliCommandStrings.ToolUninstallToolPathOptionDescription); + + public static readonly Option ToolManifestOption = ToolAppliedOption.ToolManifestOption(CliCommandStrings.ToolUninstallManifestPathOptionDescription); + + public static Command Create() + { + Command command = new("uninstall", CliCommandStrings.ToolUninstallCommandDescription); + + command.Arguments.Add(PackageIdArgument); + command.Options.Add(GlobalOption); + command.Options.Add(LocalOption); + command.Options.Add(ToolPathOption); + command.Options.Add(ToolManifestOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Tool/Uninstall/ToolUninstallCommandParser.cs b/src/Cli/dotnet/Commands/Tool/Uninstall/ToolUninstallCommandParser.cs index 5ec3e2ce05b4..8de86a2613d6 100644 --- a/src/Cli/dotnet/Commands/Tool/Uninstall/ToolUninstallCommandParser.cs +++ b/src/Cli/dotnet/Commands/Tool/Uninstall/ToolUninstallCommandParser.cs @@ -13,20 +13,15 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Uninstall; internal static class ToolUninstallCommandParser { - public static readonly Argument PackageIdArgument = new("packageId") - { - HelpName = "PACKAGE_ID", - Description = CliStrings.PackageReference, - Arity = ArgumentArity.ExactlyOne - }; + public static readonly Argument PackageIdArgument = ToolUninstallCommandDefinition.PackageIdArgument; - public static readonly Option GlobalOption = ToolAppliedOption.GlobalOption(CliCommandStrings.ToolUninstallGlobalOptionDescription); + public static readonly Option GlobalOption = ToolUninstallCommandDefinition.GlobalOption; - public static readonly Option LocalOption = ToolAppliedOption.LocalOption(CliCommandStrings.ToolUninstallLocalOptionDescription); + public static readonly Option LocalOption = ToolUninstallCommandDefinition.LocalOption; - public static readonly Option ToolPathOption = ToolAppliedOption.ToolPathOption(CliCommandStrings.ToolUninstallToolPathOptionDescription); + public static readonly Option ToolPathOption = ToolUninstallCommandDefinition.ToolPathOption; - public static readonly Option ToolManifestOption = ToolAppliedOption.ToolManifestOption(CliCommandStrings.ToolUninstallManifestPathOptionDescription); + public static readonly Option ToolManifestOption = ToolUninstallCommandDefinition.ToolManifestOption; private static readonly Command Command = ConstructCommand(); @@ -37,13 +32,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("uninstall", CliCommandStrings.ToolUninstallCommandDescription); - - command.Arguments.Add(PackageIdArgument); - command.Options.Add(GlobalOption); - command.Options.Add(LocalOption); - command.Options.Add(ToolPathOption); - command.Options.Add(ToolManifestOption); + Command command = ToolUninstallCommandDefinition.Create(); command.SetAction((parseResult) => new ToolUninstallCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Tool/Uninstall/ToolUninstallGlobalOrToolPathCommand.cs b/src/Cli/dotnet/Commands/Tool/Uninstall/ToolUninstallGlobalOrToolPathCommand.cs index 58db9f55cc04..6db95e91941a 100644 --- a/src/Cli/dotnet/Commands/Tool/Uninstall/ToolUninstallGlobalOrToolPathCommand.cs +++ b/src/Cli/dotnet/Commands/Tool/Uninstall/ToolUninstallGlobalOrToolPathCommand.cs @@ -73,7 +73,7 @@ public override int Execute() TransactionalAction.Run(() => { shellShimRepository.RemoveShim(package.Command); - + toolPackageUninstaller.Uninstall(package.PackageDirectory); }); diff --git a/src/Cli/dotnet/Commands/Tool/Update/ToolUpdateCommandDefinition.cs b/src/Cli/dotnet/Commands/Tool/Update/ToolUpdateCommandDefinition.cs new file mode 100644 index 000000000000..754e366bf257 --- /dev/null +++ b/src/Cli/dotnet/Commands/Tool/Update/ToolUpdateCommandDefinition.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.CommandLine; +using Microsoft.DotNet.Cli.Commands.Tool.Common; +using Microsoft.DotNet.Cli.Commands.Tool.Install; + +namespace Microsoft.DotNet.Cli.Commands.Tool.Update; + +internal static class ToolUpdateCommandDefinition +{ + public static readonly Argument PackageIdentityArgument = CommonArguments.OptionalPackageIdentityArgument("dotnetsay", "2.1.7"); + + public static readonly Option UpdateAllOption = ToolAppliedOption.UpdateAllOption; + + public static readonly Option AllowPackageDowngradeOption = ToolInstallCommandParser.AllowPackageDowngradeOption; + + public static Command Create() + { + Command command = new("update", CliCommandStrings.ToolUpdateCommandDescription); + + command.Arguments.Add(PackageIdentityArgument); + + ToolInstallCommandParser.AddCommandOptions(command); + command.Options.Add(AllowPackageDowngradeOption); + command.Options.Add(UpdateAllOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Tool/Update/ToolUpdateCommandParser.cs b/src/Cli/dotnet/Commands/Tool/Update/ToolUpdateCommandParser.cs index f29fce2f7086..9dba4aba74cf 100644 --- a/src/Cli/dotnet/Commands/Tool/Update/ToolUpdateCommandParser.cs +++ b/src/Cli/dotnet/Commands/Tool/Update/ToolUpdateCommandParser.cs @@ -9,11 +9,11 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Update; internal static class ToolUpdateCommandParser { - public static readonly Argument PackageIdentityArgument = CommonArguments.OptionalPackageIdentityArgument("dotnetsay", "2.1.7"); + public static readonly Argument PackageIdentityArgument = ToolUpdateCommandDefinition.PackageIdentityArgument; - public static readonly Option UpdateAllOption = ToolAppliedOption.UpdateAllOption; + public static readonly Option UpdateAllOption = ToolUpdateCommandDefinition.UpdateAllOption; - public static readonly Option AllowPackageDowngradeOption = ToolInstallCommandParser.AllowPackageDowngradeOption; + public static readonly Option AllowPackageDowngradeOption = ToolUpdateCommandDefinition.AllowPackageDowngradeOption; private static readonly Command Command = ConstructCommand(); @@ -24,13 +24,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("update", CliCommandStrings.ToolUpdateCommandDescription); - - command.Arguments.Add(PackageIdentityArgument); - - ToolInstallCommandParser.AddCommandOptions(command); - command.Options.Add(AllowPackageDowngradeOption); - command.Options.Add(UpdateAllOption); + Command command = ToolUpdateCommandDefinition.Create(); command.SetAction((parseResult) => new ToolUpdateCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Tool/Update/ToolUpdateGlobalOrToolPathCommand.cs b/src/Cli/dotnet/Commands/Tool/Update/ToolUpdateGlobalOrToolPathCommand.cs index 4c73cebd76f0..2d4c881bbc83 100644 --- a/src/Cli/dotnet/Commands/Tool/Update/ToolUpdateGlobalOrToolPathCommand.cs +++ b/src/Cli/dotnet/Commands/Tool/Update/ToolUpdateGlobalOrToolPathCommand.cs @@ -4,12 +4,12 @@ #nullable disable using System.CommandLine; +using Microsoft.DotNet.Cli.Commands.Tool.Install; +using Microsoft.DotNet.Cli.ShellShim; +using Microsoft.DotNet.Cli.ToolPackage; using Microsoft.DotNet.Cli.Utils; using Microsoft.Extensions.EnvironmentAbstractions; -using Microsoft.DotNet.Cli.ToolPackage; using CreateShellShimRepository = Microsoft.DotNet.Cli.Commands.Tool.Install.CreateShellShimRepository; -using Microsoft.DotNet.Cli.ShellShim; -using Microsoft.DotNet.Cli.Commands.Tool.Install; namespace Microsoft.DotNet.Cli.Commands.Tool.Update; diff --git a/src/Cli/dotnet/Commands/Workload/Clean/WorkloadCleanCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/Clean/WorkloadCleanCommandDefinition.cs new file mode 100644 index 000000000000..dfdbb545f469 --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/Clean/WorkloadCleanCommandDefinition.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; + +namespace Microsoft.DotNet.Cli.Commands.Workload.Clean; + +internal static class WorkloadCleanCommandDefinition +{ + public static readonly Option CleanAllOption = new("--all") { Description = CliCommandStrings.CleanAllOptionDescription }; + + public static Command Create() + { + Command command = new("clean", CliCommandStrings.WorkloadCleanCommandDescription); + + command.Options.Add(CleanAllOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Workload/Clean/WorkloadCleanCommandParser.cs b/src/Cli/dotnet/Commands/Workload/Clean/WorkloadCleanCommandParser.cs index bb012ccfe442..be543c489b56 100644 --- a/src/Cli/dotnet/Commands/Workload/Clean/WorkloadCleanCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/Clean/WorkloadCleanCommandParser.cs @@ -9,7 +9,7 @@ namespace Microsoft.DotNet.Cli.Commands.Workload.Clean; internal static class WorkloadCleanCommandParser { - public static readonly Option CleanAllOption = new("--all") { Description = CliCommandStrings.CleanAllOptionDescription }; + public static readonly Option CleanAllOption = WorkloadCleanCommandDefinition.CleanAllOption; private static readonly Command Command = ConstructCommand(); @@ -20,9 +20,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("clean", CliCommandStrings.WorkloadCleanCommandDescription); - - command.Options.Add(CleanAllOption); + Command command = WorkloadCleanCommandDefinition.Create(); command.SetAction((parseResult) => new WorkloadCleanCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Workload/Config/WorkloadConfigCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/Config/WorkloadConfigCommandDefinition.cs new file mode 100644 index 000000000000..19b7f16f5939 --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/Config/WorkloadConfigCommandDefinition.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; + +namespace Microsoft.DotNet.Cli.Commands.Workload.Config; + +internal static class WorkloadConfigCommandDefinition +{ + // dotnet workload config --update-mode workload-set + + public static readonly string UpdateMode_WorkloadSet = "workload-set"; + public static readonly string UpdateMode_Manifests = "manifests"; + + public static readonly Option UpdateMode = new("--update-mode") + { + Description = CliCommandStrings.UpdateModeDescription, + Arity = ArgumentArity.ZeroOrOne + }; + + public static Command Create() + { + UpdateMode.AcceptOnlyFromAmong(UpdateMode_WorkloadSet, UpdateMode_Manifests); + + Command command = new("config", CliCommandStrings.WorkloadConfigCommandDescription); + command.Options.Add(UpdateMode); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Workload/Config/WorkloadConfigCommandParser.cs b/src/Cli/dotnet/Commands/Workload/Config/WorkloadConfigCommandParser.cs index 0ddd6481ab7b..710c676e2ff7 100644 --- a/src/Cli/dotnet/Commands/Workload/Config/WorkloadConfigCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/Config/WorkloadConfigCommandParser.cs @@ -11,14 +11,10 @@ internal static class WorkloadConfigCommandParser { // dotnet workload config --update-mode workload-set - public static readonly string UpdateMode_WorkloadSet = "workload-set"; - public static readonly string UpdateMode_Manifests = "manifests"; + public static readonly string UpdateMode_WorkloadSet = WorkloadConfigCommandDefinition.UpdateMode_WorkloadSet; + public static readonly string UpdateMode_Manifests = WorkloadConfigCommandDefinition.UpdateMode_Manifests; - public static readonly Option UpdateMode = new("--update-mode") - { - Description = CliCommandStrings.UpdateModeDescription, - Arity = ArgumentArity.ZeroOrOne - }; + public static readonly Option UpdateMode = WorkloadConfigCommandDefinition.UpdateMode; private static readonly Command Command = ConstructCommand(); @@ -29,10 +25,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - UpdateMode.AcceptOnlyFromAmong(UpdateMode_WorkloadSet, UpdateMode_Manifests); - - Command command = new("config", CliCommandStrings.WorkloadConfigCommandDescription); - command.Options.Add(UpdateMode); + Command command = WorkloadConfigCommandDefinition.Create(); command.SetAction(parseResult => { diff --git a/src/Cli/dotnet/Commands/Workload/Elevate/WorkloadElevateCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/Elevate/WorkloadElevateCommandDefinition.cs new file mode 100644 index 000000000000..942f7205f630 --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/Elevate/WorkloadElevateCommandDefinition.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; + +namespace Microsoft.DotNet.Cli.Commands.Workload.Elevate; + +internal static class WorkloadElevateCommandDefinition +{ + public static Command Create() + { + Command command = new("elevate", CliCommandStrings.WorkloadElevateCommandDescription) + { + Hidden = true + }; + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Workload/Elevate/WorkloadElevateCommandParser.cs b/src/Cli/dotnet/Commands/Workload/Elevate/WorkloadElevateCommandParser.cs index f20c589e2f16..9a6a28874fb4 100644 --- a/src/Cli/dotnet/Commands/Workload/Elevate/WorkloadElevateCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/Elevate/WorkloadElevateCommandParser.cs @@ -18,10 +18,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("elevate", CliCommandStrings.WorkloadElevateCommandDescription) - { - Hidden = true - }; + Command command = WorkloadElevateCommandDefinition.Create(); command.SetAction((parseResult) => new WorkloadElevateCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Workload/History/WorkloadHistoryCommand.cs b/src/Cli/dotnet/Commands/Workload/History/WorkloadHistoryCommand.cs index ceebc46404a9..cbb727effd59 100644 --- a/src/Cli/dotnet/Commands/Workload/History/WorkloadHistoryCommand.cs +++ b/src/Cli/dotnet/Commands/Workload/History/WorkloadHistoryCommand.cs @@ -4,11 +4,11 @@ #nullable disable using System.CommandLine; +using Microsoft.Deployment.DotNet.Releases; +using Microsoft.DotNet.Cli.Commands.Workload.Install; using Microsoft.DotNet.Cli.NuGetPackageDownloader; using Microsoft.DotNet.Cli.Utils; using Microsoft.NET.Sdk.WorkloadManifestReader; -using Microsoft.Deployment.DotNet.Releases; -using Microsoft.DotNet.Cli.Commands.Workload.Install; namespace Microsoft.DotNet.Cli.Commands.Workload.History; diff --git a/src/Cli/dotnet/Commands/Workload/History/WorkloadHistoryCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/History/WorkloadHistoryCommandDefinition.cs new file mode 100644 index 000000000000..30388537d189 --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/History/WorkloadHistoryCommandDefinition.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; + +namespace Microsoft.DotNet.Cli.Commands.Workload.History; + +internal static class WorkloadHistoryCommandDefinition +{ + public static Command Create() + { + var command = new Command("history", CliCommandStrings.WorkloadHistoryCommandDescription); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Workload/History/WorkloadHistoryCommandParser.cs b/src/Cli/dotnet/Commands/Workload/History/WorkloadHistoryCommandParser.cs index 1e3f596c0572..cf6fb74c818d 100644 --- a/src/Cli/dotnet/Commands/Workload/History/WorkloadHistoryCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/History/WorkloadHistoryCommandParser.cs @@ -18,7 +18,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - var command = new Command("history", CliCommandStrings.WorkloadHistoryCommandDescription); + var command = WorkloadHistoryCommandDefinition.Create(); command.SetAction(parseResult => new WorkloadHistoryCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallCommandDefinition.cs new file mode 100644 index 000000000000..3ee65b16cae1 --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallCommandDefinition.cs @@ -0,0 +1,58 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.CommandLine; + +namespace Microsoft.DotNet.Cli.Commands.Workload.Install; + +internal static class WorkloadInstallCommandDefinition +{ + public static readonly Argument> WorkloadIdArgument = new("workloadId") + { + HelpName = CliCommandStrings.WorkloadIdArgumentName, + Arity = ArgumentArity.OneOrMore, + Description = CliCommandStrings.WorkloadIdArgumentDescription + }; + + public static readonly Option SkipSignCheckOption = new("--skip-sign-check") + { + Description = CliCommandStrings.SkipSignCheckOptionDescription, + Hidden = true, + Arity = ArgumentArity.Zero + }; + + public static readonly Option SkipManifestUpdateOption = new("--skip-manifest-update") + { + Description = CliCommandStrings.SkipManifestUpdateOptionDescription, + Arity = ArgumentArity.Zero + }; + + public static readonly Option TempDirOption = new("--temp-dir") + { + Description = CliCommandStrings.TempDirOptionDescription + }; + + public static readonly Option VerbosityOption = CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal); + + public static Command Create() + { + Command command = new("install", CliCommandStrings.WorkloadInstallCommandDescription); + + command.Arguments.Add(WorkloadIdArgument); + AddWorkloadInstallCommandOptions(command); + + return command; + } + + internal static void AddWorkloadInstallCommandOptions(Command command) + { + InstallingWorkloadCommandParser.AddWorkloadInstallCommandOptions(command); + + command.Options.Add(SkipManifestUpdateOption); + command.Options.Add(TempDirOption); + command.AddWorkloadCommandNuGetRestoreActionConfigOptions(); + command.Options.Add(VerbosityOption); + command.Options.Add(SkipSignCheckOption); + command.Options.Add(InstallingWorkloadCommandParser.WorkloadSetVersionOption); + } +} diff --git a/src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallCommandParser.cs b/src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallCommandParser.cs index 36ae60c10e50..52f69d2cdb48 100644 --- a/src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallCommandParser.cs @@ -7,32 +7,15 @@ namespace Microsoft.DotNet.Cli.Commands.Workload.Install; internal static class WorkloadInstallCommandParser { - public static readonly Argument> WorkloadIdArgument = new("workloadId") - { - HelpName = CliCommandStrings.WorkloadIdArgumentName, - Arity = ArgumentArity.OneOrMore, - Description = CliCommandStrings.WorkloadIdArgumentDescription - }; + public static readonly Argument> WorkloadIdArgument = WorkloadInstallCommandDefinition.WorkloadIdArgument; - public static readonly Option SkipSignCheckOption = new("--skip-sign-check") - { - Description = CliCommandStrings.SkipSignCheckOptionDescription, - Hidden = true, - Arity = ArgumentArity.Zero - }; + public static readonly Option SkipSignCheckOption = WorkloadInstallCommandDefinition.SkipSignCheckOption; - public static readonly Option SkipManifestUpdateOption = new("--skip-manifest-update") - { - Description = CliCommandStrings.SkipManifestUpdateOptionDescription, - Arity = ArgumentArity.Zero - }; + public static readonly Option SkipManifestUpdateOption = WorkloadInstallCommandDefinition.SkipManifestUpdateOption; - public static readonly Option TempDirOption = new("--temp-dir") - { - Description = CliCommandStrings.TempDirOptionDescription - }; + public static readonly Option TempDirOption = WorkloadInstallCommandDefinition.TempDirOption; - public static readonly Option VerbosityOption = CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal); + public static readonly Option VerbosityOption = WorkloadInstallCommandDefinition.VerbosityOption; private static readonly Command Command = ConstructCommand(); @@ -43,10 +26,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("install", CliCommandStrings.WorkloadInstallCommandDescription); - - command.Arguments.Add(WorkloadIdArgument); - AddWorkloadInstallCommandOptions(command); + Command command = WorkloadInstallCommandDefinition.Create(); command.SetAction((parseResult) => new WorkloadInstallCommand(parseResult).Execute()); @@ -55,13 +35,7 @@ private static Command ConstructCommand() internal static void AddWorkloadInstallCommandOptions(Command command) { - InstallingWorkloadCommandParser.AddWorkloadInstallCommandOptions(command); - - command.Options.Add(SkipManifestUpdateOption); - command.Options.Add(TempDirOption); - command.AddWorkloadCommandNuGetRestoreActionConfigOptions(); - command.Options.Add(VerbosityOption); - command.Options.Add(SkipSignCheckOption); - command.Options.Add(InstallingWorkloadCommandParser.WorkloadSetVersionOption); + WorkloadInstallCommandDefinition.AddWorkloadInstallCommandOptions(command); } } + diff --git a/src/Cli/dotnet/Commands/Workload/InstallingWorkloadCommand.cs b/src/Cli/dotnet/Commands/Workload/InstallingWorkloadCommand.cs index 7eaf2b2f2e80..b85eb8c69240 100644 --- a/src/Cli/dotnet/Commands/Workload/InstallingWorkloadCommand.cs +++ b/src/Cli/dotnet/Commands/Workload/InstallingWorkloadCommand.cs @@ -5,11 +5,11 @@ using System.CommandLine; using Microsoft.Deployment.DotNet.Releases; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Workload.Install; using Microsoft.DotNet.Cli.Commands.Workload.List; using Microsoft.DotNet.Cli.Commands.Workload.Search; using Microsoft.DotNet.Cli.Commands.Workload.Update; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.NuGetPackageDownloader; using Microsoft.DotNet.Cli.ToolPackage; diff --git a/src/Cli/dotnet/Commands/Workload/List/WorkloadListCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/List/WorkloadListCommandDefinition.cs new file mode 100644 index 000000000000..4e383a284804 --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/List/WorkloadListCommandDefinition.cs @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli.Commands.Workload.List; + +internal static class WorkloadListCommandDefinition +{ + // arguments are a list of workload to be detected + public static readonly Option MachineReadableOption = new("--machine-readable") { Hidden = true }; + + public static readonly Option VersionOption = InstallingWorkloadCommandParser.VersionOption; + + public static readonly Option TempDirOption = new Option("--temp-dir") + { + Description = CliCommandStrings.TempDirOptionDescription + }.Hide(); + + public static readonly Option IncludePreviewsOption = new Option("--include-previews") + { + Description = CliCommandStrings.IncludePreviewOptionDescription + }.Hide(); + + public static Command Create() + { + Command command = new("list", CliCommandStrings.WorkloadListCommandDescription); + command.Options.Add(MachineReadableOption); + command.Options.Add(CommonOptions.HiddenVerbosityOption); + command.Options.Add(VersionOption); + command.Options.Add(TempDirOption); + command.Options.Add(IncludePreviewsOption); + command.AddWorkloadCommandNuGetRestoreActionConfigOptions(true); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Workload/List/WorkloadListCommandParser.cs b/src/Cli/dotnet/Commands/Workload/List/WorkloadListCommandParser.cs index ac7823f6b513..135b8f9c4751 100644 --- a/src/Cli/dotnet/Commands/Workload/List/WorkloadListCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/List/WorkloadListCommandParser.cs @@ -11,19 +11,13 @@ namespace Microsoft.DotNet.Cli.Commands.Workload.List; internal static class WorkloadListCommandParser { // arguments are a list of workload to be detected - public static readonly Option MachineReadableOption = new("--machine-readable") { Hidden = true }; + public static readonly Option MachineReadableOption = WorkloadListCommandDefinition.MachineReadableOption; - public static readonly Option VersionOption = InstallingWorkloadCommandParser.VersionOption; + public static readonly Option VersionOption = WorkloadListCommandDefinition.VersionOption; - public static readonly Option TempDirOption = new Option("--temp-dir") - { - Description = CliCommandStrings.TempDirOptionDescription - }.Hide(); + public static readonly Option TempDirOption = WorkloadListCommandDefinition.TempDirOption; - public static readonly Option IncludePreviewsOption = new Option("--include-previews") - { - Description = CliCommandStrings.IncludePreviewOptionDescription - }.Hide(); + public static readonly Option IncludePreviewsOption = WorkloadListCommandDefinition.IncludePreviewsOption; private static readonly Command Command = ConstructCommand(); @@ -34,13 +28,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("list", CliCommandStrings.WorkloadListCommandDescription); - command.Options.Add(MachineReadableOption); - command.Options.Add(CommonOptions.HiddenVerbosityOption); - command.Options.Add(VersionOption); - command.Options.Add(TempDirOption); - command.Options.Add(IncludePreviewsOption); - command.AddWorkloadCommandNuGetRestoreActionConfigOptions(true); + Command command = WorkloadListCommandDefinition.Create(); command.SetAction((parseResult) => new WorkloadListCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Workload/Repair/WorkloadRepairCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/Repair/WorkloadRepairCommandDefinition.cs new file mode 100644 index 000000000000..6c46b91742fb --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/Repair/WorkloadRepairCommandDefinition.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.CommandLine; +using Microsoft.DotNet.Cli.Commands.Workload.Install; + +namespace Microsoft.DotNet.Cli.Commands.Workload.Repair; + +internal static class WorkloadRepairCommandDefinition +{ + public static readonly Option ConfigOption = InstallingWorkloadCommandParser.ConfigOption; + + public static readonly Option SourceOption = InstallingWorkloadCommandParser.SourceOption; + + public static readonly Option VersionOption = InstallingWorkloadCommandParser.VersionOption; + + public static readonly Option VerbosityOption = CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal); + + public static Command Create() + { + Command command = new("repair", CliCommandStrings.WorkloadRepairCommandDescription); + + command.Options.Add(VersionOption); + command.Options.Add(ConfigOption); + command.Options.Add(SourceOption); + command.Options.Add(VerbosityOption); + command.AddWorkloadCommandNuGetRestoreActionConfigOptions(); + command.Options.Add(WorkloadInstallCommandParser.SkipSignCheckOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Workload/Repair/WorkloadRepairCommandParser.cs b/src/Cli/dotnet/Commands/Workload/Repair/WorkloadRepairCommandParser.cs index 2afba3218845..9baa5bf4b513 100644 --- a/src/Cli/dotnet/Commands/Workload/Repair/WorkloadRepairCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/Repair/WorkloadRepairCommandParser.cs @@ -8,13 +8,13 @@ namespace Microsoft.DotNet.Cli.Commands.Workload.Repair; internal static class WorkloadRepairCommandParser { - public static readonly Option ConfigOption = InstallingWorkloadCommandParser.ConfigOption; + public static readonly Option ConfigOption = WorkloadRepairCommandDefinition.ConfigOption; - public static readonly Option SourceOption = InstallingWorkloadCommandParser.SourceOption; + public static readonly Option SourceOption = WorkloadRepairCommandDefinition.SourceOption; - public static readonly Option VersionOption = InstallingWorkloadCommandParser.VersionOption; + public static readonly Option VersionOption = WorkloadRepairCommandDefinition.VersionOption; - public static readonly Option VerbosityOption = CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal); + public static readonly Option VerbosityOption = WorkloadRepairCommandDefinition.VerbosityOption; private static readonly Command Command = ConstructCommand(); @@ -25,14 +25,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("repair", CliCommandStrings.WorkloadRepairCommandDescription); - - command.Options.Add(VersionOption); - command.Options.Add(ConfigOption); - command.Options.Add(SourceOption); - command.Options.Add(VerbosityOption); - command.AddWorkloadCommandNuGetRestoreActionConfigOptions(); - command.Options.Add(WorkloadInstallCommandParser.SkipSignCheckOption); + Command command = WorkloadRepairCommandDefinition.Create(); command.SetAction((parseResult) => new WorkloadRepairCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommand.cs b/src/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommand.cs index 1dbc16110933..e1f64e74fb98 100644 --- a/src/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommand.cs +++ b/src/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommand.cs @@ -60,7 +60,7 @@ public override int Execute() }); workloadInstaller.Shutdown(); - + return 0; } diff --git a/src/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommandDefinition.cs new file mode 100644 index 000000000000..ee019d9ca1f0 --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommandDefinition.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; +using Microsoft.DotNet.Cli.Commands.Restore; +using Microsoft.DotNet.Cli.Commands.Workload.Install; + +namespace Microsoft.DotNet.Cli.Commands.Workload.Restore; + +internal static class WorkloadRestoreCommandDefinition +{ + public static readonly Argument> SlnOrProjectArgument = new(CliStrings.SolutionOrProjectArgumentName) + { + Description = CliStrings.SolutionOrProjectArgumentDescription, + Arity = ArgumentArity.ZeroOrMore + }; + + public static Command Create() + { + Command command = new("restore", CliCommandStrings.WorkloadRestoreCommandDescription); + + command.Arguments.Add(SlnOrProjectArgument); + WorkloadInstallCommandParser.AddWorkloadInstallCommandOptions(command); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommandParser.cs b/src/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommandParser.cs index f517783429c5..a0d9ea021fb4 100644 --- a/src/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/Restore/WorkloadRestoreCommandParser.cs @@ -11,11 +11,7 @@ namespace Microsoft.DotNet.Cli.Commands.Workload.Restore; internal static class WorkloadRestoreCommandParser { - public static readonly Argument> SlnOrProjectArgument = new(CliStrings.SolutionOrProjectArgumentName) - { - Description = CliStrings.SolutionOrProjectArgumentDescription, - Arity = ArgumentArity.ZeroOrMore - }; + public static readonly Argument> SlnOrProjectArgument = WorkloadRestoreCommandDefinition.SlnOrProjectArgument; private static readonly Command Command = ConstructCommand(); @@ -26,10 +22,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("restore", CliCommandStrings.WorkloadRestoreCommandDescription); - - command.Arguments.Add(SlnOrProjectArgument); - WorkloadInstallCommandParser.AddWorkloadInstallCommandOptions(command); + Command command = WorkloadRestoreCommandDefinition.Create(); command.SetAction((parseResult) => new WorkloadRestoreCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchCommandDefinition.cs new file mode 100644 index 000000000000..867457386bf8 --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchCommandDefinition.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; + +namespace Microsoft.DotNet.Cli.Commands.Workload.Search; + +internal static class WorkloadSearchCommandDefinition +{ + public static readonly Argument WorkloadIdStubArgument = + new(CliCommandStrings.WorkloadIdStubArgumentName) + { + Arity = ArgumentArity.ZeroOrOne, + Description = CliCommandStrings.WorkloadIdStubArgumentDescription + }; + + public static readonly Option VersionOption = InstallingWorkloadCommandParser.VersionOption; + + public static Command Create() + { + var command = new Command("search", CliCommandStrings.WorkloadSearchCommandDescription); + command.Subcommands.Add(WorkloadSearchVersionsCommandParser.GetCommand()); + command.Arguments.Add(WorkloadIdStubArgument); + command.Options.Add(CommonOptions.HiddenVerbosityOption); + command.Options.Add(VersionOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchCommandParser.cs b/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchCommandParser.cs index 584e99924348..9f5d3b80f88f 100644 --- a/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchCommandParser.cs @@ -9,14 +9,9 @@ namespace Microsoft.DotNet.Cli.Commands.Workload.Search; internal static class WorkloadSearchCommandParser { - public static readonly Argument WorkloadIdStubArgument = - new(CliCommandStrings.WorkloadIdStubArgumentName) - { - Arity = ArgumentArity.ZeroOrOne, - Description = CliCommandStrings.WorkloadIdStubArgumentDescription - }; + public static readonly Argument WorkloadIdStubArgument = WorkloadSearchCommandDefinition.WorkloadIdStubArgument; - public static readonly Option VersionOption = InstallingWorkloadCommandParser.VersionOption; + public static readonly Option VersionOption = WorkloadSearchCommandDefinition.VersionOption; private static readonly Command Command = ConstructCommand(); @@ -27,11 +22,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - var command = new Command("search", CliCommandStrings.WorkloadSearchCommandDescription); - command.Subcommands.Add(WorkloadSearchVersionsCommandParser.GetCommand()); - command.Arguments.Add(WorkloadIdStubArgument); - command.Options.Add(CommonOptions.HiddenVerbosityOption); - command.Options.Add(VersionOption); + var command = WorkloadSearchCommandDefinition.Create(); command.SetAction((parseResult) => new WorkloadSearchCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchVersionsCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchVersionsCommandDefinition.cs new file mode 100644 index 000000000000..65ffa68b143b --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchVersionsCommandDefinition.cs @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.CommandLine; + +namespace Microsoft.DotNet.Cli.Commands.Workload.Search; + +internal static class WorkloadSearchVersionsCommandDefinition +{ + public static readonly Argument> WorkloadVersionArgument = + new(CliCommandStrings.WorkloadVersionArgument) + { + Arity = ArgumentArity.ZeroOrMore, + Description = CliCommandStrings.WorkloadVersionArgumentDescription + }; + + public static readonly Option TakeOption = new("--take") { DefaultValueFactory = (_) => 5 }; + + public static readonly Option FormatOption = new("--format") + { + Description = CliCommandStrings.FormatOptionDescription + }; + + public static readonly Option IncludePreviewsOption = new("--include-previews"); + + public static Command Create() + { + var command = new Command("version", CliCommandStrings.PrintSetVersionsDescription); + command.Arguments.Add(WorkloadVersionArgument); + command.Options.Add(FormatOption); + command.Options.Add(TakeOption); + command.Options.Add(IncludePreviewsOption); + + TakeOption.Validators.Add(optionResult => + { + if (optionResult.GetValueOrDefault() <= 0) + { + throw new ArgumentException("The --take option must be positive."); + } + }); + + command.Validators.Add(result => + { + if (result.GetValue(WorkloadSearchCommandParser.WorkloadIdStubArgument) != null) + { + result.AddError(string.Format(CliCommandStrings.CannotCombineSearchStringAndVersion, WorkloadSearchCommandParser.WorkloadIdStubArgument.Name, command.Name)); + } + }); + + command.Validators.Add(result => + { + var versionArgument = result.GetValue(WorkloadVersionArgument); + if (versionArgument is not null && !versionArgument.All(v => v.Contains('@')) && !WorkloadSetVersion.IsWorkloadSetPackageVersion(versionArgument.SingleOrDefault(defaultValue: string.Empty))) + { + result.AddError(string.Format(CliStrings.UnrecognizedCommandOrArgument, string.Join(' ', versionArgument))); + } + }); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchVersionsCommandParser.cs b/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchVersionsCommandParser.cs index a9a64d756313..b6054c06b273 100644 --- a/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchVersionsCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchVersionsCommandParser.cs @@ -9,21 +9,13 @@ namespace Microsoft.DotNet.Cli.Commands.Workload.Search; internal static class WorkloadSearchVersionsCommandParser { - public static readonly Argument> WorkloadVersionArgument = - new(CliCommandStrings.WorkloadVersionArgument) - { - Arity = ArgumentArity.ZeroOrMore, - Description = CliCommandStrings.WorkloadVersionArgumentDescription - }; + public static readonly Argument> WorkloadVersionArgument = WorkloadSearchVersionsCommandDefinition.WorkloadVersionArgument; - public static readonly Option TakeOption = new("--take") { DefaultValueFactory = (_) => 5 }; + public static readonly Option TakeOption = WorkloadSearchVersionsCommandDefinition.TakeOption; - public static readonly Option FormatOption = new("--format") - { - Description = CliCommandStrings.FormatOptionDescription - }; + public static readonly Option FormatOption = WorkloadSearchVersionsCommandDefinition.FormatOption; - public static readonly Option IncludePreviewsOption = new("--include-previews"); + public static readonly Option IncludePreviewsOption = WorkloadSearchVersionsCommandDefinition.IncludePreviewsOption; private static readonly Command Command = ConstructCommand(); @@ -34,36 +26,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - var command = new Command("version", CliCommandStrings.PrintSetVersionsDescription); - command.Arguments.Add(WorkloadVersionArgument); - command.Options.Add(FormatOption); - command.Options.Add(TakeOption); - command.Options.Add(IncludePreviewsOption); - - TakeOption.Validators.Add(optionResult => - { - if (optionResult.GetValueOrDefault() <= 0) - { - throw new ArgumentException("The --take option must be positive."); - } - }); - - command.Validators.Add(result => - { - if (result.GetValue(WorkloadSearchCommandParser.WorkloadIdStubArgument) != null) - { - result.AddError(string.Format(CliCommandStrings.CannotCombineSearchStringAndVersion, WorkloadSearchCommandParser.WorkloadIdStubArgument.Name, command.Name)); - } - }); - - command.Validators.Add(result => - { - var versionArgument = result.GetValue(WorkloadVersionArgument); - if (versionArgument is not null && !versionArgument.All(v => v.Contains('@')) && !WorkloadSetVersion.IsWorkloadSetPackageVersion(versionArgument.SingleOrDefault(defaultValue: string.Empty))) - { - result.AddError(string.Format(CliStrings.UnrecognizedCommandOrArgument, string.Join(' ', versionArgument))); - } - }); + var command = WorkloadSearchVersionsCommandDefinition.Create(); command.SetAction(parseResult => new WorkloadSearchVersionsCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Workload/Uninstall/WorkloadUninstallCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/Uninstall/WorkloadUninstallCommandDefinition.cs new file mode 100644 index 000000000000..ba0ef4ef0eff --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/Uninstall/WorkloadUninstallCommandDefinition.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.CommandLine; +using Microsoft.DotNet.Cli.Commands.Workload.Install; + +namespace Microsoft.DotNet.Cli.Commands.Workload.Uninstall; + +internal static class WorkloadUninstallCommandDefinition +{ + public static readonly Argument> WorkloadIdArgument = WorkloadInstallCommandParser.WorkloadIdArgument; + public static readonly Option VersionOption = InstallingWorkloadCommandParser.VersionOption; + public static readonly Option VerbosityOption = CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal); + + public static Command Create() + { + Command command = new("uninstall", CliCommandStrings.WorkloadUninstallCommandDescription); + command.Arguments.Add(WorkloadIdArgument); + command.Options.Add(WorkloadInstallCommandParser.SkipSignCheckOption); + command.Options.Add(VerbosityOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Workload/Uninstall/WorkloadUninstallCommandParser.cs b/src/Cli/dotnet/Commands/Workload/Uninstall/WorkloadUninstallCommandParser.cs index 3197537691a2..b621ec0a8d8a 100644 --- a/src/Cli/dotnet/Commands/Workload/Uninstall/WorkloadUninstallCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/Uninstall/WorkloadUninstallCommandParser.cs @@ -8,9 +8,9 @@ namespace Microsoft.DotNet.Cli.Commands.Workload.Uninstall; internal static class WorkloadUninstallCommandParser { - public static readonly Argument> WorkloadIdArgument = WorkloadInstallCommandParser.WorkloadIdArgument; - public static readonly Option VersionOption = InstallingWorkloadCommandParser.VersionOption; - public static readonly Option VerbosityOption = CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal); + public static readonly Argument> WorkloadIdArgument = WorkloadUninstallCommandDefinition.WorkloadIdArgument; + public static readonly Option VersionOption = WorkloadUninstallCommandDefinition.VersionOption; + public static readonly Option VerbosityOption = WorkloadUninstallCommandDefinition.VerbosityOption; private static readonly Command Command = ConstructCommand(); @@ -21,10 +21,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("uninstall", CliCommandStrings.WorkloadUninstallCommandDescription); - command.Arguments.Add(WorkloadIdArgument); - command.Options.Add(WorkloadInstallCommandParser.SkipSignCheckOption); - command.Options.Add(VerbosityOption); + Command command = WorkloadUninstallCommandDefinition.Create(); command.SetAction((parseResult) => new WorkloadUninstallCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Workload/Update/WorkloadUpdateCommandDefinition.cs b/src/Cli/dotnet/Commands/Workload/Update/WorkloadUpdateCommandDefinition.cs new file mode 100644 index 000000000000..26932439db04 --- /dev/null +++ b/src/Cli/dotnet/Commands/Workload/Update/WorkloadUpdateCommandDefinition.cs @@ -0,0 +1,61 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.CommandLine; +using Microsoft.DotNet.Cli.Commands.Workload.Install; + +namespace Microsoft.DotNet.Cli.Commands.Workload.Update; + +internal static class WorkloadUpdateCommandDefinition +{ + public static readonly Option TempDirOption = WorkloadInstallCommandParser.TempDirOption; + + public static readonly Option FromPreviousSdkOption = new("--from-previous-sdk") + { + Description = CliCommandStrings.FromPreviousSdkOptionDescription + }; + + public static readonly Option AdManifestOnlyOption = new("--advertising-manifests-only") + { + Description = CliCommandStrings.AdManifestOnlyOptionDescription, + Arity = ArgumentArity.Zero + }; + + public static readonly Option PrintRollbackOption = new("--print-rollback") + { + Hidden = true, + Arity = ArgumentArity.Zero + }; + + public static readonly Option FromHistoryOption = new("--from-history") + { + Description = CliCommandStrings.FromHistoryOptionDescription + }; + + public static readonly Option HistoryManifestOnlyOption = new("--manifests-only") + { + Description = CliCommandStrings.HistoryManifestOnlyOptionDescription + }; + + public static readonly Option VerbosityOption = CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal); + + public static Command Create() + { + Command command = new("update", CliCommandStrings.WorkloadUpdateCommandDescription); + + InstallingWorkloadCommandParser.AddWorkloadInstallCommandOptions(command); + + command.Options.Add(TempDirOption); + command.Options.Add(FromPreviousSdkOption); + command.Options.Add(AdManifestOnlyOption); + command.Options.Add(InstallingWorkloadCommandParser.WorkloadSetVersionOption); + command.AddWorkloadCommandNuGetRestoreActionConfigOptions(); + command.Options.Add(VerbosityOption); + command.Options.Add(PrintRollbackOption); + command.Options.Add(WorkloadInstallCommandParser.SkipSignCheckOption); + command.Options.Add(FromHistoryOption); + command.Options.Add(HistoryManifestOnlyOption); + + return command; + } +} diff --git a/src/Cli/dotnet/Commands/Workload/Update/WorkloadUpdateCommandParser.cs b/src/Cli/dotnet/Commands/Workload/Update/WorkloadUpdateCommandParser.cs index 91522e862fa0..684937b29ec7 100644 --- a/src/Cli/dotnet/Commands/Workload/Update/WorkloadUpdateCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/Update/WorkloadUpdateCommandParser.cs @@ -8,36 +8,19 @@ namespace Microsoft.DotNet.Cli.Commands.Workload.Update; internal static class WorkloadUpdateCommandParser { - public static readonly Option TempDirOption = WorkloadInstallCommandParser.TempDirOption; + public static readonly Option TempDirOption = WorkloadUpdateCommandDefinition.TempDirOption; - public static readonly Option FromPreviousSdkOption = new("--from-previous-sdk") - { - Description = CliCommandStrings.FromPreviousSdkOptionDescription - }; + public static readonly Option FromPreviousSdkOption = WorkloadUpdateCommandDefinition.FromPreviousSdkOption; - public static readonly Option AdManifestOnlyOption = new("--advertising-manifests-only") - { - Description = CliCommandStrings.AdManifestOnlyOptionDescription, - Arity = ArgumentArity.Zero - }; + public static readonly Option AdManifestOnlyOption = WorkloadUpdateCommandDefinition.AdManifestOnlyOption; - public static readonly Option PrintRollbackOption = new("--print-rollback") - { - Hidden = true, - Arity = ArgumentArity.Zero - }; + public static readonly Option PrintRollbackOption = WorkloadUpdateCommandDefinition.PrintRollbackOption; - public static readonly Option FromHistoryOption = new("--from-history") - { - Description = CliCommandStrings.FromHistoryOptionDescription - }; + public static readonly Option FromHistoryOption = WorkloadUpdateCommandDefinition.FromHistoryOption; - public static readonly Option HistoryManifestOnlyOption = new("--manifests-only") - { - Description = CliCommandStrings.HistoryManifestOnlyOptionDescription - }; + public static readonly Option HistoryManifestOnlyOption = WorkloadUpdateCommandDefinition.HistoryManifestOnlyOption; - public static readonly Option VerbosityOption = CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal); + public static readonly Option VerbosityOption = WorkloadUpdateCommandDefinition.VerbosityOption; private static readonly Command Command = ConstructCommand(); @@ -48,20 +31,7 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("update", CliCommandStrings.WorkloadUpdateCommandDescription); - - InstallingWorkloadCommandParser.AddWorkloadInstallCommandOptions(command); - - command.Options.Add(TempDirOption); - command.Options.Add(FromPreviousSdkOption); - command.Options.Add(AdManifestOnlyOption); - command.Options.Add(InstallingWorkloadCommandParser.WorkloadSetVersionOption); - command.AddWorkloadCommandNuGetRestoreActionConfigOptions(); - command.Options.Add(VerbosityOption); - command.Options.Add(PrintRollbackOption); - command.Options.Add(WorkloadInstallCommandParser.SkipSignCheckOption); - command.Options.Add(FromHistoryOption); - command.Options.Add(HistoryManifestOnlyOption); + Command command = WorkloadUpdateCommandDefinition.Create(); command.SetAction((parseResult) => new WorkloadUpdateCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Workload/WorkloadCommandBase.cs b/src/Cli/dotnet/Commands/Workload/WorkloadCommandBase.cs index 44b441349be3..83c3622afd18 100644 --- a/src/Cli/dotnet/Commands/Workload/WorkloadCommandBase.cs +++ b/src/Cli/dotnet/Commands/Workload/WorkloadCommandBase.cs @@ -96,7 +96,7 @@ public WorkloadCommandBase( Verbosity = verbosityOptions == null ? parseResult.GetValue(CommonOptions.VerbosityOption(VerbosityOptions.normal)) - : parseResult.GetValue(verbosityOptions) ; + : parseResult.GetValue(verbosityOptions); ILogger nugetLogger = Verbosity.IsDetailedOrDiagnostic() ? new NuGetConsoleLogger() : new NullLogger(); diff --git a/src/Cli/dotnet/Commands/Workload/WorkloadCommandParser.cs b/src/Cli/dotnet/Commands/Workload/WorkloadCommandParser.cs index 753413943036..de12a6d560ed 100644 --- a/src/Cli/dotnet/Commands/Workload/WorkloadCommandParser.cs +++ b/src/Cli/dotnet/Commands/Workload/WorkloadCommandParser.cs @@ -5,6 +5,7 @@ using System.CommandLine; using System.CommandLine.Invocation; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Commands.Workload.Clean; using Microsoft.DotNet.Cli.Commands.Workload.Config; using Microsoft.DotNet.Cli.Commands.Workload.Elevate; @@ -20,9 +21,8 @@ using Microsoft.DotNet.Cli.Utils; using Microsoft.NET.Sdk.WorkloadManifestReader; using Microsoft.TemplateEngine.Cli.Commands; -using IReporter = Microsoft.DotNet.Cli.Utils.IReporter; using Command = System.CommandLine.Command; -using Microsoft.DotNet.Cli.CommandLine; +using IReporter = Microsoft.DotNet.Cli.Utils.IReporter; namespace Microsoft.DotNet.Cli.Commands.Workload; diff --git a/src/Cli/dotnet/DotNetCommandFactory.cs b/src/Cli/dotnet/DotNetCommandFactory.cs index ea5eb912e8f6..dcb70b05e6c9 100644 --- a/src/Cli/dotnet/DotNetCommandFactory.cs +++ b/src/Cli/dotnet/DotNetCommandFactory.cs @@ -38,7 +38,7 @@ private static bool TryGetBuiltInCommand(string commandName, out Func Parser.Invoke([commandName, ..args]); + commandFunc = (args) => Parser.Invoke([commandName, .. args]); return true; } commandFunc = null; diff --git a/src/Cli/dotnet/Extensions/CommonOptionsExtensions.cs b/src/Cli/dotnet/Extensions/CommonOptionsExtensions.cs index 9254bbd73b77..a225056f02f8 100644 --- a/src/Cli/dotnet/Extensions/CommonOptionsExtensions.cs +++ b/src/Cli/dotnet/Extensions/CommonOptionsExtensions.cs @@ -4,8 +4,8 @@ #nullable disable using Microsoft.Build.Framework; -using Microsoft.Extensions.Logging; using Microsoft.DotNet.Cli.Utils; +using Microsoft.Extensions.Logging; namespace Microsoft.DotNet.Cli.Extensions; diff --git a/src/Cli/dotnet/NugetPackageDownloader/INuGetPackageDownloader.cs b/src/Cli/dotnet/NugetPackageDownloader/INuGetPackageDownloader.cs index a5e54ba06bb9..0c606c61dbf7 100644 --- a/src/Cli/dotnet/NugetPackageDownloader/INuGetPackageDownloader.cs +++ b/src/Cli/dotnet/NugetPackageDownloader/INuGetPackageDownloader.cs @@ -43,4 +43,4 @@ Task GetBestPackageVersionAsync(PackageId packageId, Task<(NuGetVersion version, PackageSource source)> GetBestPackageVersionAndSourceAsync(PackageId packageId, VersionRange versionRange, PackageSourceLocation packageSourceLocation = null); -} +} diff --git a/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs b/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs index a311e88c646d..a0ce16fe6d0b 100644 --- a/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs +++ b/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs @@ -75,7 +75,7 @@ public NuGetPackageDownloader( _retryTimer = timer; _sourceRepositories = new(); // If windows or env variable is set, verify signatures - _verifySignatures = verifySignatures && (OperatingSystem.IsWindows() ? true + _verifySignatures = verifySignatures && (OperatingSystem.IsWindows() ? true : bool.TryParse(Environment.GetEnvironmentVariable(NuGetSignatureVerificationEnabler.DotNetNuGetSignatureVerification), out var shouldVerifySignature) ? shouldVerifySignature : OperatingSystem.IsLinux()); _cacheSettings = new SourceCacheContext @@ -122,7 +122,7 @@ public async Task DownloadPackageAsync(PackageId packageId, throw new ArgumentException($"Package download folder must be specified either via {nameof(NuGetPackageDownloader)} constructor or via {nameof(downloadFolder)} method argument."); } var pathResolver = new VersionFolderPathResolver(resolvedDownloadFolder); - + string nupkgPath = pathResolver.GetPackageFilePath(packageId.ToString(), resolvedPackageVersion); Directory.CreateDirectory(Path.GetDirectoryName(nupkgPath)); diff --git a/src/Cli/dotnet/ReleasePropertyProjectLocator.cs b/src/Cli/dotnet/ReleasePropertyProjectLocator.cs index e85fb9878d4c..7c03df034464 100644 --- a/src/Cli/dotnet/ReleasePropertyProjectLocator.cs +++ b/src/Cli/dotnet/ReleasePropertyProjectLocator.cs @@ -230,7 +230,8 @@ DependentCommandOptions commandOptions { return projectData; } - }; + } + ; return null; } diff --git a/src/Cli/dotnet/Telemetry/DevDeviceIDGetter.cs b/src/Cli/dotnet/Telemetry/DevDeviceIDGetter.cs index 015af6723629..7960deb22cc7 100644 --- a/src/Cli/dotnet/Telemetry/DevDeviceIDGetter.cs +++ b/src/Cli/dotnet/Telemetry/DevDeviceIDGetter.cs @@ -85,11 +85,11 @@ private static void CacheDeviceId(string deviceId) // Cache device Id in Windows registry matching the OS architecture using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64)) { - using(var key = baseKey.CreateSubKey(@"SOFTWARE\Microsoft\DeveloperTools")) + using (var key = baseKey.CreateSubKey(@"SOFTWARE\Microsoft\DeveloperTools")) { if (key != null) { - key.SetValue("deviceid", deviceId); + key.SetValue("deviceid", deviceId); } } } diff --git a/src/Cli/dotnet/Telemetry/EnvironmentDetectionRule.cs b/src/Cli/dotnet/Telemetry/EnvironmentDetectionRule.cs index 079b8d287d3a..ebdf6321ddd7 100644 --- a/src/Cli/dotnet/Telemetry/EnvironmentDetectionRule.cs +++ b/src/Cli/dotnet/Telemetry/EnvironmentDetectionRule.cs @@ -97,7 +97,7 @@ public EnvironmentDetectionRuleWithResult(T result, EnvironmentDetectionRule rul public T? GetResult() { return _rule.IsMatch() - ? _result + ? _result : null; } -} \ No newline at end of file +} diff --git a/src/Cli/dotnet/Telemetry/ILLMEnvironmentDetector.cs b/src/Cli/dotnet/Telemetry/ILLMEnvironmentDetector.cs index ed7db2596f88..e2ee21591567 100644 --- a/src/Cli/dotnet/Telemetry/ILLMEnvironmentDetector.cs +++ b/src/Cli/dotnet/Telemetry/ILLMEnvironmentDetector.cs @@ -14,4 +14,4 @@ internal interface ILLMEnvironmentDetector /// Returns true if the current environment is detected to be an LLM/agentic environment, false otherwise. /// bool IsLLMEnvironment(); -} \ No newline at end of file +} diff --git a/src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs b/src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs index 78111c753f30..dca7838e4321 100644 --- a/src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs +++ b/src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs @@ -30,4 +30,4 @@ internal class LLMEnvironmentDetectorForTelemetry : ILLMEnvironmentDetector /// public bool IsLLMEnvironment() => !string.IsNullOrEmpty(GetLLMEnvironment()); -} \ No newline at end of file +} diff --git a/src/Cli/dotnet/Telemetry/Telemetry.cs b/src/Cli/dotnet/Telemetry/Telemetry.cs index d9c3a59bd8a1..38f0d1c7ca19 100644 --- a/src/Cli/dotnet/Telemetry/Telemetry.cs +++ b/src/Cli/dotnet/Telemetry/Telemetry.cs @@ -258,6 +258,6 @@ static IDictionary Combine(IDictionary { eventMeasurements[measurement.Key] = measurement.Value; } - return eventMeasurements; - } + return eventMeasurements; + } } diff --git a/src/Cli/dotnet/ToolPackage/ToolConfiguration.cs b/src/Cli/dotnet/ToolPackage/ToolConfiguration.cs index 641c8c583a7c..9da8558f5384 100644 --- a/src/Cli/dotnet/ToolPackage/ToolConfiguration.cs +++ b/src/Cli/dotnet/ToolPackage/ToolConfiguration.cs @@ -62,7 +62,7 @@ private static void EnsureNoLeadingDot(string commandName) } } - + public string CommandName { get; } public string ToolAssemblyEntryPoint { get; } diff --git a/src/Cli/dotnet/ToolPackage/ToolPackageInstance.cs b/src/Cli/dotnet/ToolPackage/ToolPackageInstance.cs index 8253562c236d..d99252129744 100644 --- a/src/Cli/dotnet/ToolPackage/ToolPackageInstance.cs +++ b/src/Cli/dotnet/ToolPackage/ToolPackageInstance.cs @@ -180,7 +180,7 @@ private static ToolConfiguration DeserializeToolConfiguration(LockFileTargetLibr // Load available frameworks from the package to provide better error messages var installPath = new VersionFolderPathResolver(packageDirectory.Value).GetInstallPath(library.Name, library.Version); var toolsPackagePath = Path.Combine(installPath, "tools"); - + if (fileSystem.Directory.Exists(toolsPackagePath)) { var availableFrameworks = fileSystem.Directory.EnumerateDirectories(toolsPackagePath)