diff --git a/src/Cli/dotnet/Parser.cs b/src/Cli/dotnet/Parser.cs index 000f2c20a807..6a6d7c9585a5 100644 --- a/src/Cli/dotnet/Parser.cs +++ b/src/Cli/dotnet/Parser.cs @@ -42,6 +42,7 @@ public static class Parser PackageCommandParser.GetCommand(), ParseCommandParser.GetCommand(), PublishCommandParser.GetCommand(), + ReferenceCommandParser.GetCommand(), RemoveCommandParser.GetCommand(), RestoreCommandParser.GetCommand(), RunCommandParser.GetCommand(), @@ -335,7 +336,7 @@ public override void Write(HelpContext context) else if (command.Name.Equals(AddPackageParser.GetCommand().Name) || command.Name.Equals(AddCommandParser.GetCommand().Name)) { // Don't show package completions in help - AddPackageParser.CmdPackageArgument.CompletionSources.Clear(); + PackageAddCommandParser.CmdPackageArgument.CompletionSources.Clear(); } base.Write(context); diff --git a/src/Cli/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/Cli/dotnet/commands/dotnet-add/AddCommandParser.cs index 4739fd1c74fc..9bfb6d7acc34 100644 --- a/src/Cli/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; +using System.Diagnostics; using Microsoft.DotNet.Tools; using LocalizableStrings = Microsoft.DotNet.Tools.Add.LocalizableStrings; @@ -25,7 +26,10 @@ public static CliCommand GetCommand() private static CliCommand ConstructCommand() { - var command = new DocumentedCommand("add", DocsLink, LocalizableStrings.NetAddCommand); + var command = new DocumentedCommand("add", DocsLink, LocalizableStrings.NetAddCommand) + { + Hidden = true + }; command.Arguments.Add(ProjectArgument); command.Subcommands.Add(AddPackageParser.GetCommand()); diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs b/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs index 98263a0c4fc7..216e1b0480ab 100644 --- a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs +++ b/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs @@ -2,83 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; -using System.CommandLine.Completions; -using System.Text.Json; -using Microsoft.DotNet.Tools; -using Microsoft.DotNet.Tools.Add.PackageReference; -using Microsoft.Extensions.EnvironmentAbstractions; -using NuGet.Versioning; -using LocalizableStrings = Microsoft.DotNet.Tools.Add.PackageReference.LocalizableStrings; +using Microsoft.DotNet.Tools.Package.Add; +using LocalizableStrings = Microsoft.DotNet.Tools.Package.Add.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class AddPackageParser { - public static readonly CliArgument CmdPackageArgument = new CliArgument(LocalizableStrings.CmdPackage) - { - Description = LocalizableStrings.CmdPackageDescription - }.AddCompletions((context) => - { - // we should take --prerelease flags into account for version completion - var allowPrerelease = context.ParseResult.GetValue(PrereleaseOption); - return QueryNuGet(context.WordToComplete, allowPrerelease, CancellationToken.None).Result.Select(packageId => new CompletionItem(packageId)); - }); - - public static readonly CliOption VersionOption = new ForwardedOption("--version", "-v") - { - Description = LocalizableStrings.CmdVersionDescription, - HelpName = LocalizableStrings.CmdVersion - }.ForwardAsSingle(o => $"--version {o}") - .AddCompletions((context) => - { - // we can only do version completion if we have a package id - if (context.ParseResult.GetValue(CmdPackageArgument) is string packageId) - { - // we should take --prerelease flags into account for version completion - var allowPrerelease = context.ParseResult.GetValue(PrereleaseOption); - return QueryVersionsForPackage(packageId, context.WordToComplete, allowPrerelease, CancellationToken.None) - .Result - .Select(version => new CompletionItem(version.ToNormalizedString())); - } - else - { - return Enumerable.Empty(); - } - }); - - public static readonly CliOption FrameworkOption = new ForwardedOption("--framework", "-f") - { - Description = LocalizableStrings.CmdFrameworkDescription, - HelpName = LocalizableStrings.CmdFramework - }.ForwardAsSingle(o => $"--framework {o}"); - - public static readonly CliOption NoRestoreOption = new("--no-restore", "-n") - { - Description = LocalizableStrings.CmdNoRestoreDescription - }; - - public static readonly CliOption SourceOption = new ForwardedOption("--source", "-s") - { - Description = LocalizableStrings.CmdSourceDescription, - HelpName = LocalizableStrings.CmdSource - }.ForwardAsSingle(o => $"--source {o}"); - - public static readonly CliOption PackageDirOption = new ForwardedOption("--package-directory") - { - Description = LocalizableStrings.CmdPackageDirectoryDescription, - HelpName = LocalizableStrings.CmdPackageDirectory - }.ForwardAsSingle(o => $"--package-directory {o}"); - - public static readonly CliOption InteractiveOption = new ForwardedOption("--interactive") - { - Description = CommonLocalizableStrings.CommandInteractiveOptionDescription, - }.ForwardAs("--interactive"); - - public static readonly CliOption PrereleaseOption = new ForwardedOption("--prerelease") - { - Description = CommonLocalizableStrings.CommandPrereleaseOptionDescription - }.ForwardAs("--prerelease"); - private static readonly CliCommand Command = ConstructCommand(); public static CliCommand GetCommand() @@ -90,46 +20,19 @@ private static CliCommand ConstructCommand() { CliCommand command = new("package", LocalizableStrings.AppFullName); - command.Arguments.Add(CmdPackageArgument); - command.Options.Add(VersionOption); - command.Options.Add(FrameworkOption); - command.Options.Add(NoRestoreOption); - command.Options.Add(SourceOption); - command.Options.Add(PackageDirOption); - command.Options.Add(InteractiveOption); - command.Options.Add(PrereleaseOption); + command.Arguments.Add(PackageAddCommandParser.CmdPackageArgument); + command.Options.Add(PackageAddCommandParser.VersionOption); + command.Options.Add(PackageAddCommandParser.FrameworkOption); + command.Options.Add(PackageAddCommandParser.NoRestoreOption); + command.Options.Add(PackageAddCommandParser.SourceOption); + command.Options.Add(PackageAddCommandParser.PackageDirOption); + command.Options.Add(PackageAddCommandParser.InteractiveOption); + command.Options.Add(PackageAddCommandParser.PrereleaseOption); + command.Options.Add(PackageCommandParser.ProjectOption); command.SetAction((parseResult) => new AddPackageReferenceCommand(parseResult).Execute()); return command; } - - public static async Task> QueryNuGet(string packageStem, bool allowPrerelease, CancellationToken cancellationToken) - { - try - { - var downloader = new NuGetPackageDownloader.NuGetPackageDownloader(packageInstallDir: new DirectoryPath()); - var versions = await downloader.GetPackageIdsAsync(packageStem, allowPrerelease, cancellationToken: cancellationToken); - return versions; - } - catch (Exception) - { - return Enumerable.Empty(); - } - } - - internal static async Task> QueryVersionsForPackage(string packageId, string versionFragment, bool allowPrerelease, CancellationToken cancellationToken) - { - try - { - var downloader = new NuGetPackageDownloader.NuGetPackageDownloader(packageInstallDir: new DirectoryPath()); - var versions = await downloader.GetPackageVersionsAsync(new(packageId), versionFragment, allowPrerelease, cancellationToken: cancellationToken); - return versions; - } - catch (Exception) - { - return Enumerable.Empty(); - } - } } } diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/AddProjectToProjectReferenceParser.cs b/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/AddProjectToProjectReferenceParser.cs index e15a74171585..97e386e2a1d5 100644 --- a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/AddProjectToProjectReferenceParser.cs +++ b/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/AddProjectToProjectReferenceParser.cs @@ -2,28 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; -using Microsoft.DotNet.Tools.Add.ProjectToProjectReference; -using LocalizableStrings = Microsoft.DotNet.Tools.Add.ProjectToProjectReference.LocalizableStrings; +using Microsoft.DotNet.Tools.Reference.Add; +using LocalizableStrings = Microsoft.DotNet.Tools.Reference.Add.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class AddProjectToProjectReferenceParser { - public static readonly CliArgument> ProjectPathArgument = new(LocalizableStrings.ProjectPathArgumentName) - { - Description = LocalizableStrings.ProjectPathArgumentDescription, - Arity = ArgumentArity.OneOrMore - }; - - public static readonly CliOption FrameworkOption = new CliOption("--framework", "-f") - { - Description = LocalizableStrings.CmdFrameworkDescription, - HelpName = Tools.Add.PackageReference.LocalizableStrings.CmdFramework - - }.AddCompletions(Complete.TargetFrameworksFromProjectFile); - - public static readonly CliOption InteractiveOption = CommonOptions.InteractiveOption; - private static readonly CliCommand Command = ConstructCommand(); public static CliCommand GetCommand() @@ -35,9 +20,10 @@ private static CliCommand ConstructCommand() { CliCommand command = new("reference", LocalizableStrings.AppFullName); - command.Arguments.Add(ProjectPathArgument); - command.Options.Add(FrameworkOption); - command.Options.Add(InteractiveOption); + command.Arguments.Add(ReferenceAddCommandParser.ProjectPathArgument); + command.Options.Add(ReferenceAddCommandParser.FrameworkOption); + command.Options.Add(ReferenceAddCommandParser.InteractiveOption); + command.Options.Add(ReferenceCommandParser.ProjectOption); command.SetAction((parseResult) => new AddProjectToProjectReferenceCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/commands/dotnet-help/HelpUsageText.cs b/src/Cli/dotnet/commands/dotnet-help/HelpUsageText.cs index 983a73b439f5..10a2049af10b 100644 --- a/src/Cli/dotnet/commands/dotnet-help/HelpUsageText.cs +++ b/src/Cli/dotnet/commands/dotnet-help/HelpUsageText.cs @@ -34,19 +34,18 @@ internal static class HelpUsageText --version {LocalizableStrings.SDKVersionCommandDefinition} {LocalizableStrings.Commands}: - add {LocalizableStrings.AddDefinition} build {LocalizableStrings.BuildDefinition} build-server {LocalizableStrings.BuildServerDefinition} clean {LocalizableStrings.CleanDefinition} format {LocalizableStrings.FormatDefinition} help {LocalizableStrings.HelpDefinition} - list {LocalizableStrings.ListDefinition} msbuild {LocalizableStrings.MsBuildDefinition} new {LocalizableStrings.NewDefinition} nuget {LocalizableStrings.NugetDefinition} pack {LocalizableStrings.PackDefinition} + package {LocalizableStrings.PackageDefinition} publish {LocalizableStrings.PublishDefinition} - remove {LocalizableStrings.RemoveDefinition} + reference {LocalizableStrings.ReferenceDefinition} restore {LocalizableStrings.RestoreDefinition} run {LocalizableStrings.RunDefinition} sdk {LocalizableStrings.SdkDefinition} diff --git a/src/Cli/dotnet/commands/dotnet-help/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-help/LocalizableStrings.resx index 2627d80c9b9a..70a7863236f1 100644 --- a/src/Cli/dotnet/commands/dotnet-help/LocalizableStrings.resx +++ b/src/Cli/dotnet/commands/dotnet-help/LocalizableStrings.resx @@ -168,9 +168,15 @@ Build a .NET project. + + Search for, add, remove, or list PackageReferences for a .NET project. + Publish a .NET project for deployment. + + Add, remove, or list ProjectReferences for a .NET project. + Build and run a .NET project output. @@ -186,15 +192,6 @@ Project modification commands - - Add a package or reference to a .NET project. - - - Remove a package or reference from a .NET project. - - - List packages or references of a .NET project. - Advanced Commands diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.cs.xlf index 6d5839b23903..6e8a3ff2bdd0 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.cs.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.cs.xlf @@ -7,6 +7,16 @@ Aplikujte předvolby stylu na projekt nebo řešení. + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). Posune se na vyšší verzi architektury (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). @@ -122,16 +132,6 @@ Příkazy pro úpravy projektu - - Add a package or reference to a .NET project. - Přidá do projektu .NET balíček nebo odkaz. - - - - Remove a package or reference from a .NET project. - Odebere z projektu .NET balíček nebo odkaz. - - Advanced Commands Pokročilé příkazy @@ -167,11 +167,6 @@ Upraví soubory řešení sady Visual Studio. - - List packages or references of a .NET project. - Vypsat balíčky nebo odkazy projektu .NET. - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. Zadaný příkaz {0} není platným příkazem sady SDK. Zadejte platný příkaz sady SDK. Další informace získáte spuštěním příkazu dotnet help. diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.de.xlf index ad5a9365a823..5eac8ffb8cae 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.de.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.de.xlf @@ -7,6 +7,16 @@ Wenden Sie Formatvorlageneinstellungen auf ein Projekt oder eine Lösung an. + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). Rollforward zu Frameworkversion (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). @@ -122,16 +132,6 @@ Projektänderungsbefehle - - Add a package or reference to a .NET project. - Hiermit wird ein Paket oder ein Verweis zu einem .NET-Projekt hinzugefügt. - - - - Remove a package or reference from a .NET project. - Hiermit wird ein Paket oder ein Verweis aus einem .NET-Projekt entfernt. - - Advanced Commands Erweiterte Befehle @@ -167,11 +167,6 @@ Hiermit werden Visual Studio-Projektmappendateien geändert. - - List packages or references of a .NET project. - Listen die Pakete oder Verweise eines .NET-Projekts auf. - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. Der angegebene Befehl "{0}" ist kein gültiger SDK-Befehl. Geben Sie einen gültigen SDK-Befehl an. Führen Sie "dotnet help" aus, um weitere Informationen zu erhalten. diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.es.xlf index 757696574599..39b05dc15120 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.es.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.es.xlf @@ -7,6 +7,16 @@ Aplicar preferencias de estilo a un proyecto o solución. + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). Reenviar a la versión del marco (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). @@ -122,16 +132,6 @@ Comandos de modificación del proyecto - - Add a package or reference to a .NET project. - Agrega un paquete o una referencia a un proyecto de .NET. - - - - Remove a package or reference from a .NET project. - Quita un paquete o una referencia de un proyecto de .NET. - - Advanced Commands Comandos avanzados @@ -167,11 +167,6 @@ Modifica los archivos de la solución de Visual Studio. - - List packages or references of a .NET project. - Enumerar referencias o paquetes de un proyecto .NET. - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. El comando especificado "{0}" no es un comando de SDK válido. Especifique un comando de SDK válido. Para más información, ejecute la ayuda de dotnet. diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.fr.xlf index 4ae1eedf3e69..f1b0aeb785de 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.fr.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.fr.xlf @@ -7,6 +7,16 @@ Appliquez les préférences de style à un projet ou une solution. + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). Restaurer par progression la version du framework (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). @@ -122,16 +132,6 @@ Commandes de modification de projet - - Add a package or reference to a .NET project. - Ajoutez un package ou une référence à un projet .NET. - - - - Remove a package or reference from a .NET project. - Supprimez un package ou une référence d'un projet .NET. - - Advanced Commands Commandes avancées @@ -167,11 +167,6 @@ Modifiez les fichiers solution Visual Studio. - - List packages or references of a .NET project. - Répertorie les packages ou références d’un projet .NET. - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. La commande spécifiée '{0}' n'est pas une commande SDK valide. Spécifiez une commande SDK valide. Pour plus d'informations, exécutez dotnet help. diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.it.xlf index 4b836c458cc5..66cc98045220 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.it.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.it.xlf @@ -7,6 +7,16 @@ Applicare le preferenze di stile a un progetto o una soluzione. + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). Esegue il roll forward alla versione del framework (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). @@ -122,16 +132,6 @@ Comandi di modifica del progetto - - Add a package or reference to a .NET project. - Aggiunge un pacchetto o un riferimento a un progetto .NET. - - - - Remove a package or reference from a .NET project. - Rimuove un pacchetto o un riferimento da un progetto .NET. - - Advanced Commands Comandi avanzati @@ -167,11 +167,6 @@ Modifica i file di soluzione di Visual Studio. - - List packages or references of a .NET project. - Elencare i pacchetti o i riferimenti di un progetto .NET. - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. Il comando specificato '{0}' non è un comando valido dell'SDK. Specificare un comando valido dell'SDK. Per altre informazioni, eseguire dotnet help. diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ja.xlf index 8e1a314f1454..60600441035e 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ja.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ja.xlf @@ -7,6 +7,16 @@ プロジェクトやソリューションにスタイルのユーザー設定を適用します。 + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). フレームワーク バージョン (LatestPatch、Minor、LatestMinor、Major、LatestMajor、Disable) にロールフォワードします。 @@ -122,16 +132,6 @@ プロジェクト変更コマンド - - Add a package or reference to a .NET project. - .NET プロジェクトにパッケージまたは参照を追加します。 - - - - Remove a package or reference from a .NET project. - .NET プロジェクトからパッケージまたは参照を削除します。 - - Advanced Commands 高度なコマンド @@ -167,11 +167,6 @@ Visual Studio ソリューション ファイルを変更します。 - - List packages or references of a .NET project. - .NET プロジェクトのパッケージまたは参照を一覧表示します。 - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. 指定されたコマンド '{0}' は、有効な SDK コマンドではありません。有効な SDK コマンドを指定してください。詳細については、dotnet のヘルプを実行してください。 diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ko.xlf index 495756f39327..a769befa935d 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ko.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ko.xlf @@ -7,6 +7,16 @@ 프로젝트 또는 솔루션에 스타일 기본 설정을 적용합니다. + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). 프레임워크 버전(LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable)으로 롤포워드합니다. @@ -122,16 +132,6 @@ 프로젝트 수정 명령 - - Add a package or reference to a .NET project. - .NET 프로젝트에 패키지 또는 참조를 추가합니다. - - - - Remove a package or reference from a .NET project. - .NET 프로젝트에서 패키지 또는 참조를 제거합니다. - - Advanced Commands 고급 명령 @@ -167,11 +167,6 @@ Visual Studio 솔루션 파일을 수정합니다. - - List packages or references of a .NET project. - .NET 프로젝트의 패키지 또는 참조를 나열합니다. - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. 지정된 명령 '{0}'은(는) 유효한 SDK 명령이 아닙니다. 유효한 SDK 명령을 지정하세요. 자세한 내용은 dotnet 도움말을 실행하세요. diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.pl.xlf index 01f06743f03f..316d36365bb4 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.pl.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.pl.xlf @@ -7,6 +7,16 @@ Zastosuj preferencje stylu do projektu lub rozwiązania. + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). Przewiń do wersji platformy (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). @@ -122,16 +132,6 @@ Polecenia modyfikacji projektu - - Add a package or reference to a .NET project. - Dodaj pakiet lub odwołanie do projektu platformy .NET. - - - - Remove a package or reference from a .NET project. - Usuń pakiet lub odwołanie z projektu platformy .NET. - - Advanced Commands Polecenia zaawansowane @@ -167,11 +167,6 @@ Modyfikuj pliki rozwiązania programu Visual Studio. - - List packages or references of a .NET project. - Wyświetl listę pakietów lub odwołań projektu platformy .NET. - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. Określone polecenie („{0}”) nie jest prawidłowym poleceniem zestawu SDK. Określ prawidłowe polecenie zestawu SDK. Aby uzyskać więcej informacji, uruchom polecenie dotnet help. diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.pt-BR.xlf index f526f3d542b0..4a2f41591f6b 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.pt-BR.xlf @@ -7,6 +7,16 @@ Aplicar preferências de estilo a um projeto ou solução. + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). Role para frente para a versão de estrutura (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). @@ -122,16 +132,6 @@ Comandos de modificação de projeto - - Add a package or reference to a .NET project. - Adicionar um pacote ou uma referência a um projeto do .NET. - - - - Remove a package or reference from a .NET project. - Remover um pacote ou uma referência de um projeto do .NET. - - Advanced Commands Comandos Avançados @@ -167,11 +167,6 @@ Modificar os arquivos da solução do Visual Studio. - - List packages or references of a .NET project. - Listar referências ou pacotes de um projeto .NET. - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. O comando especificado '{0}' não é um comando do SDK válido. Especifique um comando do SDK válido. Para obter mais informações, execute a ajuda do dotnet. diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ru.xlf index d400badec331..80557d75d131 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ru.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.ru.xlf @@ -7,6 +7,16 @@ Применение настроек стилей к проекту или решению. + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). Накат до версии платформы (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). @@ -122,16 +132,6 @@ Команды изменения проекта - - Add a package or reference to a .NET project. - Добавление пакета или ссылки в проект .NET. - - - - Remove a package or reference from a .NET project. - Удаление пакета или ссылки из проекта .NET. - - Advanced Commands Дополнительные команды @@ -167,11 +167,6 @@ Изменение файлов решения Visual Studio. - - List packages or references of a .NET project. - Выводит список пакетов или ссылок для проекта .NET. - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. Указанная команда "{0}" не является допустимой командой пакета SDK. Укажите допустимую. Для получения дополнительных сведений выполните команду "dotnet help". diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.tr.xlf index 8e93aa950cdb..ffcc4bf53bbf 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.tr.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.tr.xlf @@ -7,6 +7,16 @@ Stil tercihlerini bir projeye veya çözüme uygulayın. + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). Şu framework sürümüne ileri sarın: (LatestPatch, İkincil, LatestMinor, Ana, LatestMajor, Devre dışı). @@ -122,16 +132,6 @@ Projede değişiklik komutları - - Add a package or reference to a .NET project. - Bir .NET projesine paket ya da başvuru ekler. - - - - Remove a package or reference from a .NET project. - Bir .NET projesinden paket ya da başvuruyu kaldırır. - - Advanced Commands Gelişmiş Komutlar @@ -167,11 +167,6 @@ Visual Studio çözüm dosyalarını değiştirir. - - List packages or references of a .NET project. - Bir .NET projesinin paketlerini veya başvurularını listeleyin. - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. Belirtilen '{0}' komutu geçerli bir SDK komutu değil. Geçerli bir SDK komutu belirtin. Daha fazla bilgi için dotnet help komutunu çalıştırın. diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.zh-Hans.xlf index 5ed7f3bde8c1..b9546c8b1b00 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.zh-Hans.xlf @@ -7,6 +7,16 @@ 将样式首选项应用到项目或解决方案。 + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). 前滚至框架版本(LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable)。 @@ -122,16 +132,6 @@ 项目修改命令 - - Add a package or reference to a .NET project. - 将包或引用添加到 .NET 项目。 - - - - Remove a package or reference from a .NET project. - 从 .NET 项目中删除包或引用。 - - Advanced Commands 高级命令 @@ -167,11 +167,6 @@ 修改 Visual Studio 解决方案文件。 - - List packages or references of a .NET project. - 列出 .NET 项目的包或引用。 - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. 指定的命令“{0}”不是有效的 SDK 命令。请指定有效的 SDK 命令。有关详细信息,请运行 dotnet help。 diff --git a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.zh-Hant.xlf index 8f8802ea2283..180a98ba1c62 100644 --- a/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.zh-Hant.xlf @@ -7,6 +7,16 @@ 將樣式喜好設定套用至專案或解決方案。 + + Search for, add, remove, or list PackageReferences for a .NET project. + Search for, add, remove, or list PackageReferences for a .NET project. + + + + Add, remove, or list ProjectReferences for a .NET project. + Add, remove, or list ProjectReferences for a .NET project. + + Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). 復原為架構版本 (LatestPatch、Minor、LatestMinor、Major、LatestMajor、Disable)。 @@ -122,16 +132,6 @@ 專案修改命令 - - Add a package or reference to a .NET project. - 對 .NET 專案新增套件或參考。 - - - - Remove a package or reference from a .NET project. - 從 .NET 專案移除套件或參考。 - - Advanced Commands 進階命令 @@ -167,11 +167,6 @@ 修改 Visual Studio 解決方案檔。 - - List packages or references of a .NET project. - 列出 .NET 專案的套件或參考。 - - Specified command '{0}' is not a valid SDK command. Specify a valid SDK command. For more information, run dotnet help. 指定的命令 '{0}' 並非有效的 SDK 命令。請指定有效的 SDK 命令。如需詳細資訊,請執行 dotnet help。 diff --git a/src/Cli/dotnet/commands/dotnet-list/ListCommandParser.cs b/src/Cli/dotnet/commands/dotnet-list/ListCommandParser.cs index 58bd724308d8..c2774866a037 100644 --- a/src/Cli/dotnet/commands/dotnet-list/ListCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-list/ListCommandParser.cs @@ -29,7 +29,10 @@ public static CliCommand GetCommand() private static CliCommand ConstructCommand() { - var command = new DocumentedCommand("list", DocsLink, LocalizableStrings.NetListCommand); + var command = new DocumentedCommand("list", DocsLink, LocalizableStrings.NetListCommand) + { + Hidden = true + }; command.Arguments.Add(SlnOrProjectArgument); command.Subcommands.Add(ListPackageReferencesCommandParser.GetCommand()); diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/ListPackageReferencesCommandParser.cs b/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/ListPackageReferencesCommandParser.cs index d26e460cb14d..c98364cb9644 100644 --- a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/ListPackageReferencesCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/ListPackageReferencesCommandParser.cs @@ -2,90 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; -using Microsoft.DotNet.Tools; -using Microsoft.DotNet.Tools.List.PackageReferences; -using LocalizableStrings = Microsoft.DotNet.Tools.List.PackageReferences.LocalizableStrings; +using Microsoft.DotNet.Tools.Package.List; +using LocalizableStrings = Microsoft.DotNet.Tools.Package.List.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class ListPackageReferencesCommandParser { - public static readonly CliOption OutdatedOption = new ForwardedOption("--outdated") - { - Description = LocalizableStrings.CmdOutdatedDescription - }.ForwardAs("--outdated"); - - public static readonly CliOption DeprecatedOption = new ForwardedOption("--deprecated") - { - Description = LocalizableStrings.CmdDeprecatedDescription - }.ForwardAs("--deprecated"); - - public static readonly CliOption VulnerableOption = new ForwardedOption("--vulnerable") - { - Description = LocalizableStrings.CmdVulnerableDescription - }.ForwardAs("--vulnerable"); - - public static readonly CliOption FrameworkOption = new ForwardedOption>("--framework", "-f") - { - Description = LocalizableStrings.CmdFrameworkDescription, - HelpName = LocalizableStrings.CmdFramework - }.ForwardAsManyArgumentsEachPrefixedByOption("--framework") - .AllowSingleArgPerToken(); - - public static readonly CliOption TransitiveOption = new ForwardedOption("--include-transitive") - { - Description = LocalizableStrings.CmdTransitiveDescription - }.ForwardAs("--include-transitive"); - - public static readonly CliOption PrereleaseOption = new ForwardedOption("--include-prerelease") - { - Description = LocalizableStrings.CmdPrereleaseDescription - }.ForwardAs("--include-prerelease"); - - public static readonly CliOption HighestPatchOption = new ForwardedOption("--highest-patch") - { - Description = LocalizableStrings.CmdHighestPatchDescription - }.ForwardAs("--highest-patch"); - - public static readonly CliOption HighestMinorOption = new ForwardedOption("--highest-minor") - { - Description = LocalizableStrings.CmdHighestMinorDescription - }.ForwardAs("--highest-minor"); - - public static readonly CliOption ConfigOption = new ForwardedOption("--config", "--configfile") - { - Description = LocalizableStrings.CmdConfigDescription, - HelpName = LocalizableStrings.CmdConfig - }.ForwardAsMany(o => new[] { "--config", o }); - - public static readonly CliOption SourceOption = new ForwardedOption>("--source", "-s") - { - Description = LocalizableStrings.CmdSourceDescription, - HelpName = LocalizableStrings.CmdSource - }.ForwardAsManyArgumentsEachPrefixedByOption("--source") - .AllowSingleArgPerToken(); - - public static readonly CliOption InteractiveOption = new ForwardedOption("--interactive") - { - Description = CommonLocalizableStrings.CommandInteractiveOptionDescription - }.ForwardAs("--interactive"); - - public static readonly CliOption VerbosityOption = new ForwardedOption("--verbosity", "-v") - { - Description = CommonLocalizableStrings.VerbosityOptionDescription, - HelpName = CommonLocalizableStrings.LevelArgumentName - }.ForwardAsSingle(o => $"--verbosity:{o}"); - - public static readonly CliOption FormatOption = new ForwardedOption("--format") - { - Description = LocalizableStrings.CmdFormatDescription - }.ForwardAsSingle(o => $"--format:{o}"); - - public static readonly CliOption OutputVersionOption = new ForwardedOption("--output-version") - { - Description = LocalizableStrings.CmdOutputVersionDescription - }.ForwardAsSingle(o => $"--output-version:{o}"); - private static readonly CliCommand Command = ConstructCommand(); public static CliCommand GetCommand() @@ -97,20 +20,20 @@ private static CliCommand ConstructCommand() { CliCommand command = new("package", LocalizableStrings.AppFullName); - command.Options.Add(VerbosityOption); - command.Options.Add(OutdatedOption); - command.Options.Add(DeprecatedOption); - command.Options.Add(VulnerableOption); - command.Options.Add(FrameworkOption); - command.Options.Add(TransitiveOption); - command.Options.Add(PrereleaseOption); - command.Options.Add(HighestPatchOption); - command.Options.Add(HighestMinorOption); - command.Options.Add(ConfigOption); - command.Options.Add(SourceOption); - command.Options.Add(InteractiveOption); - command.Options.Add(FormatOption); - command.Options.Add(OutputVersionOption); + command.Options.Add(PackageListCommandParser.VerbosityOption); + command.Options.Add(PackageListCommandParser.OutdatedOption); + command.Options.Add(PackageListCommandParser.DeprecatedOption); + command.Options.Add(PackageListCommandParser.VulnerableOption); + command.Options.Add(PackageListCommandParser.FrameworkOption); + command.Options.Add(PackageListCommandParser.TransitiveOption); + command.Options.Add(PackageListCommandParser.PrereleaseOption); + command.Options.Add(PackageListCommandParser.HighestPatchOption); + command.Options.Add(PackageListCommandParser.HighestMinorOption); + command.Options.Add(PackageListCommandParser.ConfigOption); + command.Options.Add(PackageListCommandParser.SourceOption); + command.Options.Add(PackageListCommandParser.InteractiveOption); + command.Options.Add(PackageListCommandParser.FormatOption); + command.Options.Add(PackageListCommandParser.OutputVersionOption); command.SetAction((parseResult) => new ListPackageReferencesCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/ListProjectToProjectReferencesCommandParser.cs b/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/ListProjectToProjectReferencesCommandParser.cs index c98a044dfced..52ea3bd317e4 100644 --- a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/ListProjectToProjectReferencesCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/ListProjectToProjectReferencesCommandParser.cs @@ -2,8 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; -using Microsoft.DotNet.Tools.List.ProjectToProjectReferences; -using LocalizableStrings = Microsoft.DotNet.Tools.List.ProjectToProjectReferences.LocalizableStrings; +using Microsoft.DotNet.Tools.Reference.List; +using LocalizableStrings = Microsoft.DotNet.Tools.Reference.List.LocalizableStrings; namespace Microsoft.DotNet.Cli { diff --git a/src/Cli/dotnet/commands/dotnet-new/DotnetCommandCallbacks.cs b/src/Cli/dotnet/commands/dotnet-new/DotnetCommandCallbacks.cs index ea41a6182efb..89cfa59fc29a 100644 --- a/src/Cli/dotnet/commands/dotnet-new/DotnetCommandCallbacks.cs +++ b/src/Cli/dotnet/commands/dotnet-new/DotnetCommandCallbacks.cs @@ -4,9 +4,9 @@ #nullable enable using Microsoft.DotNet.Cli; -using Microsoft.DotNet.Tools.Add.PackageReference; -using Microsoft.DotNet.Tools.Add.ProjectToProjectReference; using Microsoft.DotNet.Tools.Common; +using Microsoft.DotNet.Tools.Package.Add; +using Microsoft.DotNet.Tools.Reference.Add; using Microsoft.DotNet.Tools.Restore; using Microsoft.DotNet.Tools.Sln.Add; @@ -20,7 +20,7 @@ internal static bool AddPackageReference(string projectPath, string packageName, IEnumerable commandArgs = new[] { "add", projectPath, "package", packageName }; if (!string.IsNullOrWhiteSpace(version)) { - commandArgs = commandArgs.Append(AddPackageParser.VersionOption.Name).Append(version); + commandArgs = commandArgs.Append(PackageAddCommandParser.VersionOption.Name).Append(version); } var addPackageReferenceCommand = new AddPackageReferenceCommand(AddCommandParser.GetCommand().Parse(commandArgs.ToArray())); return addPackageReferenceCommand.Execute() == 0; diff --git a/src/Cli/dotnet/commands/dotnet-package/PackageCommandParser.cs b/src/Cli/dotnet/commands/dotnet-package/PackageCommandParser.cs index 63bf74e8faa3..8824eb241aeb 100644 --- a/src/Cli/dotnet/commands/dotnet-package/PackageCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-package/PackageCommandParser.cs @@ -9,11 +9,19 @@ internal class PackageCommandParser { private const string DocsLink = "https://aka.ms/dotnet-package"; + public static readonly CliOption ProjectOption = new("--project") + { + Recursive = true + }; + public static CliCommand GetCommand() { CliCommand command = new DocumentedCommand("package", DocsLink); command.SetAction((parseResult) => parseResult.HandleMissingCommand()); command.Subcommands.Add(PackageSearchCommandParser.GetCommand()); + command.Subcommands.Add(PackageAddCommandParser.GetCommand()); + command.Subcommands.Add(PackageListCommandParser.GetCommand()); + command.Subcommands.Add(PackageRemoveCommandParser.GetCommand()); return command; } diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-package/add/LocalizableStrings.resx similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/LocalizableStrings.resx rename to src/Cli/dotnet/commands/dotnet-package/add/LocalizableStrings.resx diff --git a/src/Cli/dotnet/commands/dotnet-package/add/PackageAddCommandParser.cs b/src/Cli/dotnet/commands/dotnet-package/add/PackageAddCommandParser.cs new file mode 100644 index 000000000000..68c911b6d553 --- /dev/null +++ b/src/Cli/dotnet/commands/dotnet-package/add/PackageAddCommandParser.cs @@ -0,0 +1,135 @@ +// 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.Tools; +using System.CommandLine.Completions; +using LocalizableStrings = Microsoft.DotNet.Tools.Package.Add.LocalizableStrings; +using Microsoft.Extensions.EnvironmentAbstractions; +using NuGet.Versioning; +using Microsoft.DotNet.Tools.Package.Add; + +namespace Microsoft.DotNet.Cli +{ + internal static class PackageAddCommandParser + { + public static readonly CliArgument CmdPackageArgument = new CliArgument(LocalizableStrings.CmdPackage) + { + Description = LocalizableStrings.CmdPackageDescription + }.AddCompletions((context) => + { + // we should take --prerelease flags into account for version completion + var allowPrerelease = context.ParseResult.GetValue(PrereleaseOption); + return QueryNuGet(context.WordToComplete, allowPrerelease, CancellationToken.None).Result.Select(packageId => new CompletionItem(packageId)); + }); + + public static readonly CliOption VersionOption = new ForwardedOption("--version", "-v") + { + Description = LocalizableStrings.CmdVersionDescription, + HelpName = LocalizableStrings.CmdVersion + }.ForwardAsSingle(o => $"--version {o}") + .AddCompletions((context) => + { + // we can only do version completion if we have a package id + if (context.ParseResult.GetValue(CmdPackageArgument) is string packageId) + { + // we should take --prerelease flags into account for version completion + var allowPrerelease = context.ParseResult.GetValue(PrereleaseOption); + return QueryVersionsForPackage(packageId, context.WordToComplete, allowPrerelease, CancellationToken.None) + .Result + .Select(version => new CompletionItem(version.ToNormalizedString())); + } + else + { + return Enumerable.Empty(); + } + }); + + public static readonly CliOption FrameworkOption = new ForwardedOption("--framework", "-f") + { + Description = LocalizableStrings.CmdFrameworkDescription, + HelpName = LocalizableStrings.CmdFramework + }.ForwardAsSingle(o => $"--framework {o}"); + + public static readonly CliOption NoRestoreOption = new("--no-restore", "-n") + { + Description = LocalizableStrings.CmdNoRestoreDescription + }; + + public static readonly CliOption SourceOption = new ForwardedOption("--source", "-s") + { + Description = LocalizableStrings.CmdSourceDescription, + HelpName = LocalizableStrings.CmdSource + }.ForwardAsSingle(o => $"--source {o}"); + + public static readonly CliOption PackageDirOption = new ForwardedOption("--package-directory") + { + Description = LocalizableStrings.CmdPackageDirectoryDescription, + HelpName = LocalizableStrings.CmdPackageDirectory + }.ForwardAsSingle(o => $"--package-directory {o}"); + + public static readonly CliOption InteractiveOption = new ForwardedOption("--interactive") + { + Description = CommonLocalizableStrings.CommandInteractiveOptionDescription, + }.ForwardAs("--interactive"); + + public static readonly CliOption PrereleaseOption = new ForwardedOption("--prerelease") + { + Description = CommonLocalizableStrings.CommandPrereleaseOptionDescription + }.ForwardAs("--prerelease"); + + private static readonly CliCommand Command = ConstructCommand(); + + public static CliCommand GetCommand() + { + return Command; + } + + private static CliCommand ConstructCommand() + { + CliCommand command = new("add", LocalizableStrings.AppFullName); + + command.Arguments.Add(CmdPackageArgument); + command.Options.Add(VersionOption); + command.Options.Add(FrameworkOption); + command.Options.Add(NoRestoreOption); + command.Options.Add(SourceOption); + command.Options.Add(PackageDirOption); + command.Options.Add(InteractiveOption); + command.Options.Add(PrereleaseOption); + command.Options.Add(PackageCommandParser.ProjectOption); + + command.SetAction((parseResult) => new AddPackageReferenceCommand(parseResult).Execute()); + + return command; + } + + public static async Task> QueryNuGet(string packageStem, bool allowPrerelease, CancellationToken cancellationToken) + { + try + { + var downloader = new NuGetPackageDownloader.NuGetPackageDownloader(packageInstallDir: new DirectoryPath()); + var versions = await downloader.GetPackageIdsAsync(packageStem, allowPrerelease, cancellationToken: cancellationToken); + return versions; + } + catch (Exception) + { + return Enumerable.Empty(); + } + } + + internal static async Task> QueryVersionsForPackage(string packageId, string versionFragment, bool allowPrerelease, CancellationToken cancellationToken) + { + try + { + var downloader = new NuGetPackageDownloader.NuGetPackageDownloader(packageInstallDir: new DirectoryPath()); + var versions = await downloader.GetPackageVersionsAsync(new(packageId), versionFragment, allowPrerelease, cancellationToken: cancellationToken); + return versions; + } + catch (Exception) + { + return Enumerable.Empty(); + } + } + } +} diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs b/src/Cli/dotnet/commands/dotnet-package/add/Program.cs similarity index 85% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs rename to src/Cli/dotnet/commands/dotnet-package/add/Program.cs index f347d2a03ab2..7b2335837d21 100644 --- a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-package/add/Program.cs @@ -4,10 +4,11 @@ using System.CommandLine; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Tools; using Microsoft.DotNet.Tools.MSBuild; using Microsoft.DotNet.Tools.NuGet; -namespace Microsoft.DotNet.Tools.Add.PackageReference +namespace Microsoft.DotNet.Tools.Package.Add { internal class AddPackageReferenceCommand : CommandBase { @@ -16,8 +17,10 @@ internal class AddPackageReferenceCommand : CommandBase public AddPackageReferenceCommand(ParseResult parseResult) : base(parseResult) { - _fileOrDirectory = parseResult.GetValue(AddCommandParser.ProjectArgument); - _packageId = parseResult.GetValue(AddPackageParser.CmdPackageArgument); + _fileOrDirectory = parseResult.HasOption(PackageCommandParser.ProjectOption) ? + parseResult.GetValue(PackageCommandParser.ProjectOption) : + parseResult.GetValue(AddCommandParser.ProjectArgument); + _packageId = parseResult.GetValue(PackageAddCommandParser.CmdPackageArgument); } public override int Execute() @@ -35,7 +38,7 @@ public override int Execute() var tempDgFilePath = string.Empty; - if (_parseResult.GetResult(AddPackageParser.NoRestoreOption) is null) + if (_parseResult.GetResult(PackageAddCommandParser.NoRestoreOption) is null) { try @@ -113,10 +116,10 @@ private string[] TransformArgs(string packageId, string tempDgFilePath, string p }; args.AddRange(_parseResult - .OptionValuesToBeForwarded(AddPackageParser.GetCommand()) + .OptionValuesToBeForwarded(PackageAddCommandParser.GetCommand()) .SelectMany(a => a.Split(' ', 2))); - if (_parseResult.GetResult(AddPackageParser.NoRestoreOption) is not null) + if (_parseResult.GetResult(PackageAddCommandParser.NoRestoreOption) is not null) { args.Add("--no-restore"); } diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.cs.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.cs.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.cs.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.de.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.de.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.de.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.es.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.es.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.es.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.fr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.fr.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.fr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.it.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.it.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.it.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.ja.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.ja.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.ja.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.ko.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.ko.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.ko.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.pl.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.pl.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.pl.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.pt-BR.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.pt-BR.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.pt-BR.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.ru.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.ru.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.ru.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.tr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.tr.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.tr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.zh-Hans.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.zh-Hans.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.zh-Hans.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.zh-Hant.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.zh-Hant.xlf rename to src/Cli/dotnet/commands/dotnet-package/add/xlf/LocalizableStrings.zh-Hant.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/ListPackageReferencesCommand.cs b/src/Cli/dotnet/commands/dotnet-package/list/ListPackageReferencesCommand.cs similarity index 88% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/ListPackageReferencesCommand.cs rename to src/Cli/dotnet/commands/dotnet-package/list/ListPackageReferencesCommand.cs index cbd10c1016f0..4b9552f431c5 100644 --- a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/ListPackageReferencesCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-package/list/ListPackageReferencesCommand.cs @@ -7,7 +7,7 @@ using Microsoft.DotNet.Tools.Common; using Microsoft.DotNet.Tools.NuGet; -namespace Microsoft.DotNet.Tools.List.PackageReferences +namespace Microsoft.DotNet.Tools.Package.List { internal class ListPackageReferencesCommand : CommandBase { @@ -18,6 +18,8 @@ public ListPackageReferencesCommand( ParseResult parseResult) : base(parseResult) { _fileOrDirectory = GetAbsolutePath(Directory.GetCurrentDirectory(), + parseResult.HasOption(PackageCommandParser.ProjectOption) ? + parseResult.GetValue(PackageCommandParser.ProjectOption) : parseResult.GetValue(ListCommandParser.SlnOrProjectArgument)); } @@ -34,9 +36,9 @@ public override int Execute() internal static void EnforceOptionRules(ParseResult parseResult) { var mutexOptionCount = 0; - mutexOptionCount += parseResult.HasOption(ListPackageReferencesCommandParser.DeprecatedOption) ? 1 : 0; - mutexOptionCount += parseResult.HasOption(ListPackageReferencesCommandParser.OutdatedOption) ? 1 : 0; - mutexOptionCount += parseResult.HasOption(ListPackageReferencesCommandParser.VulnerableOption) ? 1 : 0; + mutexOptionCount += parseResult.HasOption(PackageListCommandParser.DeprecatedOption) ? 1 : 0; + mutexOptionCount += parseResult.HasOption(PackageListCommandParser.OutdatedOption) ? 1 : 0; + mutexOptionCount += parseResult.HasOption(PackageListCommandParser.VulnerableOption) ? 1 : 0; if (mutexOptionCount > 1) { throw new GracefulException(LocalizableStrings.OptionsCannotBeCombined); @@ -53,7 +55,7 @@ private string[] TransformArgs() args.Add(GetProjectOrSolution()); - args.AddRange(_parseResult.OptionValuesToBeForwarded(ListPackageReferencesCommandParser.GetCommand())); + args.AddRange(_parseResult.OptionValuesToBeForwarded(PackageListCommandParser.GetCommand())); EnforceOptionRules(_parseResult); diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-package/list/LocalizableStrings.resx similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/LocalizableStrings.resx rename to src/Cli/dotnet/commands/dotnet-package/list/LocalizableStrings.resx diff --git a/src/Cli/dotnet/commands/dotnet-package/list/PackageListCommandParser.cs b/src/Cli/dotnet/commands/dotnet-package/list/PackageListCommandParser.cs new file mode 100644 index 000000000000..e01ddd924896 --- /dev/null +++ b/src/Cli/dotnet/commands/dotnet-package/list/PackageListCommandParser.cs @@ -0,0 +1,121 @@ +// 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.Tools.Package.List; +using Microsoft.DotNet.Tools; +using LocalizableStrings = Microsoft.DotNet.Tools.Package.List.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + internal static class PackageListCommandParser + { + public static readonly CliOption OutdatedOption = new ForwardedOption("--outdated") + { + Description = LocalizableStrings.CmdOutdatedDescription + }.ForwardAs("--outdated"); + + public static readonly CliOption DeprecatedOption = new ForwardedOption("--deprecated") + { + Description = LocalizableStrings.CmdDeprecatedDescription + }.ForwardAs("--deprecated"); + + public static readonly CliOption VulnerableOption = new ForwardedOption("--vulnerable") + { + Description = LocalizableStrings.CmdVulnerableDescription + }.ForwardAs("--vulnerable"); + + public static readonly CliOption FrameworkOption = new ForwardedOption>("--framework", "-f") + { + Description = LocalizableStrings.CmdFrameworkDescription, + HelpName = LocalizableStrings.CmdFramework + }.ForwardAsManyArgumentsEachPrefixedByOption("--framework") + .AllowSingleArgPerToken(); + + public static readonly CliOption TransitiveOption = new ForwardedOption("--include-transitive") + { + Description = LocalizableStrings.CmdTransitiveDescription + }.ForwardAs("--include-transitive"); + + public static readonly CliOption PrereleaseOption = new ForwardedOption("--include-prerelease") + { + Description = LocalizableStrings.CmdPrereleaseDescription + }.ForwardAs("--include-prerelease"); + + public static readonly CliOption HighestPatchOption = new ForwardedOption("--highest-patch") + { + Description = LocalizableStrings.CmdHighestPatchDescription + }.ForwardAs("--highest-patch"); + + public static readonly CliOption HighestMinorOption = new ForwardedOption("--highest-minor") + { + Description = LocalizableStrings.CmdHighestMinorDescription + }.ForwardAs("--highest-minor"); + + public static readonly CliOption ConfigOption = new ForwardedOption("--config", "--configfile") + { + Description = LocalizableStrings.CmdConfigDescription, + HelpName = LocalizableStrings.CmdConfig + }.ForwardAsMany(o => new[] { "--config", o }); + + public static readonly CliOption SourceOption = new ForwardedOption>("--source", "-s") + { + Description = LocalizableStrings.CmdSourceDescription, + HelpName = LocalizableStrings.CmdSource + }.ForwardAsManyArgumentsEachPrefixedByOption("--source") + .AllowSingleArgPerToken(); + + public static readonly CliOption InteractiveOption = new ForwardedOption("--interactive") + { + Description = CommonLocalizableStrings.CommandInteractiveOptionDescription + }.ForwardAs("--interactive"); + + public static readonly CliOption VerbosityOption = new ForwardedOption("--verbosity", "-v") + { + Description = CommonLocalizableStrings.VerbosityOptionDescription, + HelpName = CommonLocalizableStrings.LevelArgumentName + }.ForwardAsSingle(o => $"--verbosity:{o}"); + + public static readonly CliOption FormatOption = new ForwardedOption("--format") + { + Description = LocalizableStrings.CmdFormatDescription + }.ForwardAsSingle(o => $"--format:{o}"); + + public static readonly CliOption OutputVersionOption = new ForwardedOption("--output-version") + { + Description = LocalizableStrings.CmdOutputVersionDescription + }.ForwardAsSingle(o => $"--output-version:{o}"); + + private static readonly CliCommand Command = ConstructCommand(); + + public static CliCommand GetCommand() + { + return Command; + } + + private static CliCommand ConstructCommand() + { + CliCommand command = new("list", LocalizableStrings.AppFullName); + + command.Options.Add(VerbosityOption); + command.Options.Add(OutdatedOption); + command.Options.Add(DeprecatedOption); + command.Options.Add(VulnerableOption); + command.Options.Add(FrameworkOption); + command.Options.Add(TransitiveOption); + command.Options.Add(PrereleaseOption); + command.Options.Add(HighestPatchOption); + command.Options.Add(HighestMinorOption); + command.Options.Add(ConfigOption); + command.Options.Add(SourceOption); + command.Options.Add(InteractiveOption); + command.Options.Add(FormatOption); + command.Options.Add(OutputVersionOption); + command.Options.Add(PackageCommandParser.ProjectOption); + + command.SetAction((parseResult) => new ListPackageReferencesCommand(parseResult).Execute()); + + return command; + } + } +} diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/ReportOutputFormat.cs b/src/Cli/dotnet/commands/dotnet-package/list/ReportOutputFormat.cs similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/ReportOutputFormat.cs rename to src/Cli/dotnet/commands/dotnet-package/list/ReportOutputFormat.cs diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.cs.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.cs.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.cs.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.de.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.de.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.de.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.es.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.es.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.es.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.fr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.fr.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.fr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.it.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.it.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.it.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.ja.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.ja.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.ja.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.ko.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.ko.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.ko.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.pl.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.pl.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.pl.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.pt-BR.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.pt-BR.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.pt-BR.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.ru.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.ru.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.ru.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.tr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.tr.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.tr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.zh-Hans.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.zh-Hans.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.zh-Hans.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.zh-Hant.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.zh-Hant.xlf rename to src/Cli/dotnet/commands/dotnet-package/list/xlf/LocalizableStrings.zh-Hant.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-package/remove/LocalizableStrings.resx similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/LocalizableStrings.resx rename to src/Cli/dotnet/commands/dotnet-package/remove/LocalizableStrings.resx diff --git a/src/Cli/dotnet/commands/dotnet-package/remove/PackageRemoveCommandParser.cs b/src/Cli/dotnet/commands/dotnet-package/remove/PackageRemoveCommandParser.cs new file mode 100644 index 000000000000..fa16dfd2d672 --- /dev/null +++ b/src/Cli/dotnet/commands/dotnet-package/remove/PackageRemoveCommandParser.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. + +using System.CommandLine; +using Microsoft.DotNet.Tools; +using Microsoft.DotNet.Tools.Package.Remove; + +namespace Microsoft.DotNet.Cli +{ + internal static class PackageRemoveCommandParser + { + public static readonly CliArgument> CmdPackageArgument = new(Tools.Package.Add.LocalizableStrings.CmdPackage) + { + Description = LocalizableStrings.AppHelpText, + Arity = ArgumentArity.OneOrMore, + }; + + public static readonly CliOption InteractiveOption = new ForwardedOption("--interactive") + { + Description = CommonLocalizableStrings.CommandInteractiveOptionDescription + }.ForwardAs("--interactive"); + + private static readonly CliCommand Command = ConstructCommand(); + + public static CliCommand GetCommand() + { + return Command; + } + + private static CliCommand ConstructCommand() + { + var command = new CliCommand("remove", LocalizableStrings.AppFullName); + + command.Arguments.Add(CmdPackageArgument); + command.Options.Add(InteractiveOption); + command.Options.Add(PackageCommandParser.ProjectOption); + + command.SetAction((parseResult) => new RemovePackageReferenceCommand(parseResult).Execute()); + + return command; + } + } +} diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs b/src/Cli/dotnet/commands/dotnet-package/remove/Program.cs similarity index 79% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs rename to src/Cli/dotnet/commands/dotnet-package/remove/Program.cs index 757b6ed88df5..3cfed0274677 100644 --- a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-package/remove/Program.cs @@ -6,7 +6,7 @@ using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.NuGet; -namespace Microsoft.DotNet.Tools.Remove.PackageReference +namespace Microsoft.DotNet.Tools.Package.Remove { internal class RemovePackageReferenceCommand : CommandBase { @@ -16,8 +16,10 @@ internal class RemovePackageReferenceCommand : CommandBase public RemovePackageReferenceCommand( ParseResult parseResult) : base(parseResult) { - _fileOrDirectory = parseResult.GetValue(RemoveCommandParser.ProjectArgument); - _arguments = parseResult.GetValue(RemovePackageParser.CmdPackageArgument).ToList().AsReadOnly(); + _fileOrDirectory = parseResult.HasOption(PackageCommandParser.ProjectOption) ? + parseResult.GetValue(PackageCommandParser.ProjectOption) : + parseResult.GetValue(RemoveCommandParser.ProjectArgument); + _arguments = parseResult.GetValue(PackageRemoveCommandParser.CmdPackageArgument).ToList().AsReadOnly(); if (_fileOrDirectory == null) { throw new ArgumentNullException(nameof(_fileOrDirectory)); @@ -60,7 +62,7 @@ private string[] TransformArgs(string packageId, string projectFilePath) }; args.AddRange(_parseResult - .OptionValuesToBeForwarded(RemovePackageParser.GetCommand()) + .OptionValuesToBeForwarded(PackageRemoveCommandParser.GetCommand()) .SelectMany(a => a.Split(' '))); return args.ToArray(); diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.cs.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.cs.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.cs.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.de.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.de.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.de.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.es.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.es.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.es.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.fr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.fr.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.fr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.it.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.it.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.it.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.ja.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.ja.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.ja.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.ko.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.ko.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.ko.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.pl.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.pl.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.pl.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.pt-BR.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.pt-BR.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.pt-BR.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.ru.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.ru.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.ru.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.tr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.tr.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.tr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.zh-Hans.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.zh-Hans.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.zh-Hans.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.zh-Hant.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/xlf/LocalizableStrings.zh-Hant.xlf rename to src/Cli/dotnet/commands/dotnet-package/remove/xlf/LocalizableStrings.zh-Hant.xlf diff --git a/src/Cli/dotnet/commands/dotnet-reference/ReferenceCommandParser.cs b/src/Cli/dotnet/commands/dotnet-reference/ReferenceCommandParser.cs new file mode 100644 index 000000000000..f37cc7c5c812 --- /dev/null +++ b/src/Cli/dotnet/commands/dotnet-reference/ReferenceCommandParser.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. + +using System.CommandLine; +using Microsoft.DotNet.Tools; +using LocalizableStrings = Microsoft.DotNet.Tools.Remove.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + internal static class ReferenceCommandParser + { + public static readonly string DocsLink = "https://aka.ms/dotnet-reference"; + + public static readonly CliOption ProjectOption = new CliOption("--project") + { + Description = CommonLocalizableStrings.ProjectArgumentDescription, + Recursive = true + }; + + private static readonly CliCommand Command = ConstructCommand(); + + public static CliCommand GetCommand() + { + return Command; + } + + private static CliCommand ConstructCommand() + { + var command = new DocumentedCommand("reference", DocsLink, LocalizableStrings.NetRemoveCommand); + + command.Subcommands.Add(ReferenceAddCommandParser.GetCommand()); + command.Subcommands.Add(ReferenceListCommandParser.GetCommand()); + command.Subcommands.Add(ReferenceRemoveCommandParser.GetCommand()); + command.Options.Add(ProjectOption); + command.SetAction((parseResult) => parseResult.HandleMissingCommand()); + + return command; + } + } +} diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/LocalizableStrings.resx similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/LocalizableStrings.resx rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/LocalizableStrings.resx diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/Program.cs similarity index 87% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/Program.cs index e793b2174118..6c267a40aedc 100644 --- a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/Program.cs @@ -8,7 +8,7 @@ using Microsoft.DotNet.Tools.Common; using NuGet.Frameworks; -namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference +namespace Microsoft.DotNet.Tools.Reference.Add { internal class AddProjectToProjectReferenceCommand : CommandBase { @@ -16,21 +16,23 @@ internal class AddProjectToProjectReferenceCommand : CommandBase public AddProjectToProjectReferenceCommand(ParseResult parseResult) : base(parseResult) { - _fileOrDirectory = parseResult.GetValue(AddCommandParser.ProjectArgument); + _fileOrDirectory = parseResult.HasOption(ReferenceCommandParser.ProjectOption) ? + parseResult.GetValue(ReferenceCommandParser.ProjectOption) : + parseResult.GetValue(AddCommandParser.ProjectArgument); } public override int Execute() { using var projects = new ProjectCollection(); - bool interactive = _parseResult.GetValue(AddProjectToProjectReferenceParser.InteractiveOption); + bool interactive = _parseResult.GetValue(ReferenceAddCommandParser.InteractiveOption); MsbuildProject msbuildProj = MsbuildProject.FromFileOrDirectory( projects, _fileOrDirectory, interactive); - var frameworkString = _parseResult.GetValue(AddProjectToProjectReferenceParser.FrameworkOption); + var frameworkString = _parseResult.GetValue(ReferenceAddCommandParser.FrameworkOption); - var arguments = _parseResult.GetValue(AddProjectToProjectReferenceParser.ProjectPathArgument).ToList().AsReadOnly(); + var arguments = _parseResult.GetValue(ReferenceAddCommandParser.ProjectPathArgument).ToList().AsReadOnly(); PathUtility.EnsureAllPathsExist(arguments, CommonLocalizableStrings.CouldNotFindProjectOrDirectory, true); List refs = diff --git a/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/ReferenceAddCommandParser.cs b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/ReferenceAddCommandParser.cs new file mode 100644 index 000000000000..7cd676063445 --- /dev/null +++ b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/ReferenceAddCommandParser.cs @@ -0,0 +1,54 @@ +// 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 System.CommandLine.Parsing; +using Microsoft.DotNet.Tools; +using Microsoft.DotNet.Tools.Reference.Add; +using LocalizableStrings = Microsoft.DotNet.Tools.Reference.Add.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + internal static class ReferenceAddCommandParser + { + public static readonly CliArgument> ProjectPathArgument = new(LocalizableStrings.ProjectPathArgumentName) + { + Description = LocalizableStrings.ProjectPathArgumentDescription, + Arity = ArgumentArity.OneOrMore, + CustomParser = arguments => { + var result = arguments.Tokens.TakeWhile(t => !t.Value.StartsWith("-")); + arguments.OnlyTake(result.Count()); + return result.Select(t => t.Value); + } + }; + + public static readonly CliOption FrameworkOption = new CliOption("--framework", "-f") + { + Description = LocalizableStrings.CmdFrameworkDescription, + HelpName = CommonLocalizableStrings.CmdFramework + + }.AddCompletions(Complete.TargetFrameworksFromProjectFile); + + public static readonly CliOption InteractiveOption = CommonOptions.InteractiveOption; + + private static readonly CliCommand Command = ConstructCommand(); + + public static CliCommand GetCommand() + { + return Command; + } + + private static CliCommand ConstructCommand() + { + CliCommand command = new("add", LocalizableStrings.AppFullName); + + command.Arguments.Add(ProjectPathArgument); + command.Options.Add(FrameworkOption); + command.Options.Add(InteractiveOption); + + command.SetAction((parseResult) => new AddProjectToProjectReferenceCommand(parseResult).Execute()); + + return command; + } + } +} diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.cs.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.cs.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.cs.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.de.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.de.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.de.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.es.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.es.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.es.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.fr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.fr.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.fr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.it.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.it.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.it.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.ja.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.ja.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.ja.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.ko.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.ko.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.ko.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.pl.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.pl.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.pl.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.pt-BR.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.pt-BR.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.pt-BR.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.ru.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.ru.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.ru.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.tr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.tr.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.tr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.zh-Hans.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.zh-Hans.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.zh-Hans.xlf diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.zh-Hant.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/xlf/LocalizableStrings.zh-Hant.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-add/xlf/LocalizableStrings.zh-Hant.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/ListProjectToProjectReferencesCommand.cs b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/ListProjectToProjectReferencesCommand.cs similarity index 84% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/ListProjectToProjectReferencesCommand.cs rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/ListProjectToProjectReferencesCommand.cs index ab1ac66e72f3..ad2e4e3596ff 100644 --- a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/ListProjectToProjectReferencesCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/ListProjectToProjectReferencesCommand.cs @@ -6,7 +6,7 @@ using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Utils; -namespace Microsoft.DotNet.Tools.List.ProjectToProjectReferences +namespace Microsoft.DotNet.Tools.Reference.List { internal class ListProjectToProjectReferencesCommand : CommandBase { @@ -17,7 +17,9 @@ public ListProjectToProjectReferencesCommand( { ShowHelpOrErrorIfAppropriate(parseResult); - _fileOrDirectory = parseResult.GetValue(ListCommandParser.SlnOrProjectArgument); + _fileOrDirectory = parseResult.HasOption(ReferenceCommandParser.ProjectOption) ? + parseResult.GetValue(ReferenceCommandParser.ProjectOption) : + parseResult.GetValue(ListCommandParser.SlnOrProjectArgument); } public override int Execute() diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/LocalizableStrings.resx similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/LocalizableStrings.resx rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/LocalizableStrings.resx diff --git a/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/ReferenceListCommandParser.cs b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/ReferenceListCommandParser.cs new file mode 100644 index 000000000000..39e4305f7f03 --- /dev/null +++ b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/ReferenceListCommandParser.cs @@ -0,0 +1,28 @@ +// 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.Tools.Reference.List; +using LocalizableStrings = Microsoft.DotNet.Tools.Reference.List.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + internal static class ReferenceListCommandParser + { + private static readonly CliCommand Command = ConstructCommand(); + + public static CliCommand GetCommand() + { + return Command; + } + + private static CliCommand ConstructCommand() + { + var command = new CliCommand("list", LocalizableStrings.AppFullName); + + command.SetAction((parseResult) => new ListProjectToProjectReferencesCommand(parseResult).Execute()); + + return command; + } + } +} diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.cs.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.cs.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.cs.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.de.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.de.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.de.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.es.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.es.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.es.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.fr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.fr.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.fr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.it.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.it.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.it.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.ja.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.ja.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.ja.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.ko.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.ko.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.ko.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.pl.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.pl.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.pl.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.pt-BR.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.pt-BR.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.pt-BR.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.ru.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.ru.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.ru.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.tr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.tr.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.tr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.zh-Hans.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.zh-Hans.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.zh-Hans.xlf diff --git a/src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.zh-Hant.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-list/dotnet-list-reference/xlf/LocalizableStrings.zh-Hant.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-list/xlf/LocalizableStrings.zh-Hant.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/LocalizableStrings.resx similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/LocalizableStrings.resx rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/LocalizableStrings.resx diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/Program.cs similarity index 76% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/Program.cs index f9422952c229..7c81cd45aa7b 100644 --- a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/Program.cs @@ -5,8 +5,9 @@ using Microsoft.Build.Evaluation; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Tools; -namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference +namespace Microsoft.DotNet.Tools.Reference.Remove { internal class RemoveProjectToProjectReferenceCommand : CommandBase { @@ -16,8 +17,10 @@ internal class RemoveProjectToProjectReferenceCommand : CommandBase public RemoveProjectToProjectReferenceCommand( ParseResult parseResult) : base(parseResult) { - _fileOrDirectory = parseResult.GetValue(RemoveCommandParser.ProjectArgument); - _arguments = parseResult.GetValue(RemoveProjectToProjectReferenceParser.ProjectPathArgument).ToList().AsReadOnly(); + _fileOrDirectory = parseResult.HasOption(ReferenceCommandParser.ProjectOption) ? + parseResult.GetValue(ReferenceCommandParser.ProjectOption) : + parseResult.GetValue(RemoveCommandParser.ProjectArgument); + _arguments = parseResult.GetValue(ReferenceRemoveCommandParser.ProjectPathArgument).ToList().AsReadOnly(); if (_arguments.Count == 0) { @@ -43,7 +46,7 @@ public override int Execute() }); int numberOfRemovedReferences = msbuildProj.RemoveProjectToProjectReferences( - _parseResult.GetValue(RemoveProjectToProjectReferenceParser.FrameworkOption), + _parseResult.GetValue(ReferenceRemoveCommandParser.FrameworkOption), references); if (numberOfRemovedReferences != 0) diff --git a/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/ReferenceRemoveCommandParser.cs b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/ReferenceRemoveCommandParser.cs new file mode 100644 index 000000000000..955c52a9f2df --- /dev/null +++ b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/ReferenceRemoveCommandParser.cs @@ -0,0 +1,44 @@ +// 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.Tools; +using Microsoft.DotNet.Tools.Reference.Remove; +using LocalizableStrings = Microsoft.DotNet.Tools.Reference.Remove.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + internal static class ReferenceRemoveCommandParser + { + public static readonly CliArgument> ProjectPathArgument = new CliArgument>(LocalizableStrings.ProjectPathArgumentName) + { + Description = LocalizableStrings.ProjectPathArgumentDescription, + Arity = ArgumentArity.OneOrMore, + }.AddCompletions(Complete.ProjectReferencesFromProjectFile); + + public static readonly CliOption FrameworkOption = new("--framework", "-f") + { + Description = LocalizableStrings.CmdFrameworkDescription, + HelpName = CommonLocalizableStrings.CmdFramework + }; + + private static readonly CliCommand Command = ConstructCommand(); + + public static CliCommand GetCommand() + { + return Command; + } + + private static CliCommand ConstructCommand() + { + var command = new CliCommand("remove", LocalizableStrings.AppFullName); + + command.Arguments.Add(ProjectPathArgument); + command.Options.Add(FrameworkOption); + + command.SetAction((parseResult) => new RemoveProjectToProjectReferenceCommand(parseResult).Execute()); + + return command; + } + } +} diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.cs.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.cs.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.cs.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.de.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.de.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.de.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.es.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.es.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.es.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.fr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.fr.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.fr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.it.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.it.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.it.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.ja.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.ja.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.ja.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.ko.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.ko.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.ko.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.pl.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.pl.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.pl.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.pt-BR.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.pt-BR.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.pt-BR.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.ru.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.ru.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.ru.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.tr.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.tr.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.tr.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.zh-Hans.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.zh-Hans.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.zh-Hans.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.zh-Hant.xlf similarity index 100% rename from src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/xlf/LocalizableStrings.zh-Hant.xlf rename to src/Cli/dotnet/commands/dotnet-reference/dotnet-reference-remove/xlf/LocalizableStrings.zh-Hant.xlf diff --git a/src/Cli/dotnet/commands/dotnet-remove/RemoveCommandParser.cs b/src/Cli/dotnet/commands/dotnet-remove/RemoveCommandParser.cs index 37f94319e170..46a0ec110e05 100644 --- a/src/Cli/dotnet/commands/dotnet-remove/RemoveCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-remove/RemoveCommandParser.cs @@ -25,7 +25,10 @@ public static CliCommand GetCommand() private static CliCommand ConstructCommand() { - var command = new DocumentedCommand("remove", DocsLink, LocalizableStrings.NetRemoveCommand); + var command = new DocumentedCommand("remove", DocsLink, LocalizableStrings.NetRemoveCommand) + { + Hidden = true + }; command.Arguments.Add(ProjectArgument); command.Subcommands.Add(RemovePackageParser.GetCommand()); diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs b/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs index e12e156a4f0d..33ddc6227be6 100644 --- a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs +++ b/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs @@ -2,25 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; -using Microsoft.DotNet.Tools; -using Microsoft.DotNet.Tools.Remove.PackageReference; -using LocalizableStrings = Microsoft.DotNet.Tools.Remove.PackageReference.LocalizableStrings; +using Microsoft.DotNet.Tools.Package.Remove; +using LocalizableStrings = Microsoft.DotNet.Tools.Package.Remove.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class RemovePackageParser { - public static readonly CliArgument> CmdPackageArgument = new(Tools.Add.PackageReference.LocalizableStrings.CmdPackage) - { - Description = LocalizableStrings.AppHelpText, - Arity = ArgumentArity.OneOrMore, - }; - - public static readonly CliOption InteractiveOption = new ForwardedOption("--interactive") - { - Description = CommonLocalizableStrings.CommandInteractiveOptionDescription - }.ForwardAs("--interactive"); - private static readonly CliCommand Command = ConstructCommand(); public static CliCommand GetCommand() @@ -32,8 +20,8 @@ private static CliCommand ConstructCommand() { var command = new CliCommand("package", LocalizableStrings.AppFullName); - command.Arguments.Add(CmdPackageArgument); - command.Options.Add(InteractiveOption); + command.Arguments.Add(PackageRemoveCommandParser.CmdPackageArgument); + command.Options.Add(PackageRemoveCommandParser.InteractiveOption); command.SetAction((parseResult) => new RemovePackageReferenceCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/RemoveProjectToProjectReferenceParser.cs b/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/RemoveProjectToProjectReferenceParser.cs index 9a19eaf88a2f..cf5e671511f9 100644 --- a/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/RemoveProjectToProjectReferenceParser.cs +++ b/src/Cli/dotnet/commands/dotnet-remove/dotnet-remove-reference/RemoveProjectToProjectReferenceParser.cs @@ -2,26 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; -using Microsoft.DotNet.Tools; -using Microsoft.DotNet.Tools.Remove.ProjectToProjectReference; -using LocalizableStrings = Microsoft.DotNet.Tools.Remove.ProjectToProjectReference.LocalizableStrings; +using Microsoft.DotNet.Tools.Reference.Remove; +using LocalizableStrings = Microsoft.DotNet.Tools.Reference.Remove.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class RemoveProjectToProjectReferenceParser { - public static readonly CliArgument> ProjectPathArgument = new CliArgument>(LocalizableStrings.ProjectPathArgumentName) - { - Description = LocalizableStrings.ProjectPathArgumentDescription, - Arity = ArgumentArity.OneOrMore, - }.AddCompletions(Complete.ProjectReferencesFromProjectFile); - - public static readonly CliOption FrameworkOption = new("--framework", "-f") - { - Description = LocalizableStrings.CmdFrameworkDescription, - HelpName = CommonLocalizableStrings.CmdFramework - }; - private static readonly CliCommand Command = ConstructCommand(); public static CliCommand GetCommand() @@ -33,8 +20,8 @@ private static CliCommand ConstructCommand() { var command = new CliCommand("reference", LocalizableStrings.AppFullName); - command.Arguments.Add(ProjectPathArgument); - command.Options.Add(FrameworkOption); + command.Arguments.Add(ReferenceRemoveCommandParser.ProjectPathArgument); + command.Options.Add(ReferenceRemoveCommandParser.FrameworkOption); command.SetAction((parseResult) => new RemoveProjectToProjectReferenceCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/dotnet.csproj b/src/Cli/dotnet/dotnet.csproj index da9f09bd96c8..3e9b793811b2 100644 --- a/src/Cli/dotnet/dotnet.csproj +++ b/src/Cli/dotnet/dotnet.csproj @@ -34,8 +34,8 @@ - - + + @@ -44,15 +44,15 @@ - - + + - - + + diff --git a/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs b/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs index 57bf2bc0d503..daa849c365c0 100644 --- a/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs +++ b/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs @@ -14,32 +14,34 @@ public class GivenDotnetAddReference : SdkTest Add a project-to-project reference to the project. Usage: - dotnet add [] reference ... [options] + dotnet reference add ... [options] Arguments: - The project file to operate on. If a file is not specified, the command will search the current directory for one. [default: {PathUtility.EnsureTrailingSlash(defaultVal)}] - The paths to the projects to add as references. + The paths to the projects to add as references. Options: - -f, --framework Add the reference only when targeting a specific framework. - --interactive Allows the command to stop and wait for user input or action (for example to complete authentication). - -?, -h, --help Show command line help."; + -f, --framework Add the reference only when targeting a specific framework. + --interactive Allows the command to stop and wait for user input or action (for example to complete + authentication). + --project The project file to operate on. If a file is not specified, the command will search the + current directory for one. + -?, -h, --help Show command line help."; private Func AddCommandHelpText = (defaultVal) => $@"Description: - .NET Add Command + .NET Remove Command Usage: - dotnet add [command] [options] - -Arguments: - The project file to operate on. If a file is not specified, the command will search the current directory for one. [default: {PathUtility.EnsureTrailingSlash(defaultVal)}] + dotnet reference [command] [options] Options: - -?, -h, --help Show command line help. + --project The project file to operate on. If a file is not specified, the command will search the current + directory for one. + -?, -h, --help Show command line help. Commands: - package Add a NuGet package reference to the project. - reference Add a project-to-project reference to the project."; + add Add a project-to-project reference to the project. + list List all project-to-project references of the project. + remove Remove a project-to-project reference from the project."; const string FrameworkNet451 = "net451"; const string ConditionFrameworkNet451 = "== 'net451'"; @@ -103,26 +105,18 @@ private ProjDir NewLibWithFrameworks(string dir = null, [System.Runtime.Compiler [InlineData("-h")] public void WhenHelpOptionIsPassedItPrintsUsage(string helpArg) { - var cmd = new DotnetCommand(Log, "add", "reference").Execute(helpArg); + var cmd = new DotnetCommand(Log, "reference", "add").Execute(helpArg); cmd.Should().Pass(); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText(Directory.GetCurrentDirectory(), "FRAMEWORK")); } - [Theory] - [InlineData("")] - [InlineData("unknownCommandName")] - public void WhenNoCommandIsPassedItPrintsError(string commandName) - { - var cmd = new DotnetCommand(Log) - .Execute($"add", commandName); - cmd.Should().Fail(); - cmd.StdErr.Should().Be(CommonLocalizableStrings.RequiredCommandNotPassed); - cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(AddCommandHelpText(Directory.GetCurrentDirectory())); - } - [Fact] public void WhenTooManyArgumentsArePassedItPrintsError() { + if (!File.Exists("proj.csproj")) + { + File.Create("proj.csproj"); + } var cmd = new DotnetCommand(Log, "add", "one", "two", "three", "reference") .Execute("proj.csproj"); cmd.ExitCode.Should().NotBe(0); @@ -167,7 +161,7 @@ public void WhenBrokenProjectIsPassedItPrintsError() var cmd = new DotnetCommand(Log, "add", projName, "reference") .WithWorkingDirectory(setup.TestRoot) - .Execute($"\"{setup.ValidRefCsprojPath}\""); + .Execute($"{setup.ValidRefCsprojPath}"); cmd.ExitCode.Should().NotBe(0); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.ProjectIsInvalid, projName)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); @@ -194,7 +188,7 @@ public void WhenNoProjectsExistsInTheDirectoryItPrintsError() var cmd = new DotnetCommand(Log, "add", "reference") .WithWorkingDirectory(setup.TestRoot) - .Execute($"\"{setup.ValidRefCsprojPath}\""); + .Execute(setup.ValidRefCsprojPath); cmd.ExitCode.Should().NotBe(0); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.CouldNotFindAnyProjectInDirectory, setup.TestRoot + Path.DirectorySeparatorChar)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); diff --git a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs index ca7e57ea791e..b9b82353ae32 100644 --- a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs +++ b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs @@ -8,22 +8,7 @@ namespace Microsoft.DotNet.Help.Tests public class GivenThatIWantToShowHelpForDotnetCommand : SdkTest { private const string HelpText = -@"Usage: dotnet [runtime-options] [path-to-application] [arguments] - -Execute a .NET application. - -runtime-options: - --additionalprobingpath Path containing probing policy and assemblies to probe for. - --additional-deps Path to additional deps.json file. - --depsfile Path to .deps.json file. - --fx-version Version of the installed Shared Framework to use to run the application. - --roll-forward Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable). - --runtimeconfig Path to .runtimeconfig.json file. - -path-to-application: - The path to an application .dll file to execute. - -Usage: dotnet [sdk-options] [command] [command-options] [arguments] +@"Usage: dotnet [sdk-options] [command] [command-options] [arguments] Execute a .NET SDK command. @@ -36,19 +21,18 @@ Execute a .NET SDK command. --version Display .NET SDK version in use. SDK commands: - add Add a package or reference to a .NET project. build Build a .NET project. build-server Interact with servers started by a build. clean Clean build outputs of a .NET project. format Apply style preferences to a project or solution. help Opens the reference page in a browser for the specified command. - list List packages or references of a .NET project. msbuild Run Microsoft Build Engine (MSBuild) commands. new Create a new .NET project or file. nuget Provides additional NuGet commands. pack Create a NuGet package. + package Search for, add, remove, or list PackageReferences for a .NET project. publish Publish a .NET project for deployment. - remove Remove a package or reference from a .NET project. + reference Add, remove, or list ProjectReferences for a .NET project. restore Restore dependencies specified in a .NET project. run Build and run a .NET project output. sdk Manage .NET SDK installation. diff --git a/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs b/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs index 46eaed94b8eb..9c6c59bd7700 100644 --- a/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs +++ b/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.Tools.List.PackageReferences; +using Microsoft.DotNet.Tools.Package.List; namespace Microsoft.DotNet.Cli.List.Package.Tests { diff --git a/test/dotnet.Tests/CommandTests/CompleteCommandTests.cs b/test/dotnet.Tests/CommandTests/CompleteCommandTests.cs index 28737029377c..1879ec636fb9 100644 --- a/test/dotnet.Tests/CommandTests/CompleteCommandTests.cs +++ b/test/dotnet.Tests/CommandTests/CompleteCommandTests.cs @@ -27,7 +27,6 @@ public void GivenOnlyDotnetItSuggestsTopLevelCommandsAndOptions() "-h", "/?", "/h", - "add", "build", "build-server", "clean", @@ -35,14 +34,13 @@ public void GivenOnlyDotnetItSuggestsTopLevelCommandsAndOptions() "sdk", "fsi", "help", - "list", "msbuild", "new", "nuget", "pack", "package", "publish", - "remove", + "reference", "restore", "run", "sln", diff --git a/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs b/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs index 2c97a02e0077..5817d3f742e4 100644 --- a/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs +++ b/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs @@ -33,7 +33,7 @@ public void AddReferenceHasInteractiveFlag() { var result = Parser.Instance.Parse("dotnet add reference my.csproj --interactive"); - result.GetValue(AddProjectToProjectReferenceParser.InteractiveOption) + result.GetValue(ReferenceAddCommandParser.InteractiveOption) .Should().BeTrue(); } @@ -42,7 +42,7 @@ public void AddReferenceDoesNotHaveInteractiveFlagByDefault() { var result = Parser.Instance.Parse("dotnet add reference my.csproj"); - result.GetValue(AddProjectToProjectReferenceParser.InteractiveOption) + result.GetValue(ReferenceAddCommandParser.InteractiveOption) .Should().BeFalse(); }