Skip to content

Commit 4f21e8d

Browse files
authored
Switch verb and noun for package/reference add/remove/list Fixes #9650 (#45384)
Switches the ordering of commands from dotnet verb noun to dotnet noun verb, as it is sometimes unclear what 'add' adds, for instance, and this is how many users of other CLIs think. In this version, dotnet verb noun (DVN) is still supported in that it works when used, but dotnet noun verb (DNV) is the priority. DVN is now hidden and doesn't appear in the help text, whereas DNV is visible and does appear in the help text. We will start attempting to move users to the new version in a later version.
1 parent 1b662ef commit 4f21e8d

File tree

131 files changed

+748
-556
lines changed

Some content is hidden

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

131 files changed

+748
-556
lines changed

src/Cli/dotnet/Parser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static class Parser
4242
PackageCommandParser.GetCommand(),
4343
ParseCommandParser.GetCommand(),
4444
PublishCommandParser.GetCommand(),
45+
ReferenceCommandParser.GetCommand(),
4546
RemoveCommandParser.GetCommand(),
4647
RestoreCommandParser.GetCommand(),
4748
RunCommandParser.GetCommand(),
@@ -335,7 +336,7 @@ public override void Write(HelpContext context)
335336
else if (command.Name.Equals(AddPackageParser.GetCommand().Name) || command.Name.Equals(AddCommandParser.GetCommand().Name))
336337
{
337338
// Don't show package completions in help
338-
AddPackageParser.CmdPackageArgument.CompletionSources.Clear();
339+
PackageAddCommandParser.CmdPackageArgument.CompletionSources.Clear();
339340
}
340341

341342
base.Write(context);

src/Cli/dotnet/commands/dotnet-add/AddCommandParser.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.CommandLine;
5+
using System.Diagnostics;
56
using Microsoft.DotNet.Tools;
67
using LocalizableStrings = Microsoft.DotNet.Tools.Add.LocalizableStrings;
78

@@ -25,7 +26,10 @@ public static CliCommand GetCommand()
2526

2627
private static CliCommand ConstructCommand()
2728
{
28-
var command = new DocumentedCommand("add", DocsLink, LocalizableStrings.NetAddCommand);
29+
var command = new DocumentedCommand("add", DocsLink, LocalizableStrings.NetAddCommand)
30+
{
31+
Hidden = true
32+
};
2933

3034
command.Arguments.Add(ProjectArgument);
3135
command.Subcommands.Add(AddPackageParser.GetCommand());

src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs

Lines changed: 11 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,13 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.CommandLine;
5-
using System.CommandLine.Completions;
6-
using System.Text.Json;
7-
using Microsoft.DotNet.Tools;
8-
using Microsoft.DotNet.Tools.Add.PackageReference;
9-
using Microsoft.Extensions.EnvironmentAbstractions;
10-
using NuGet.Versioning;
11-
using LocalizableStrings = Microsoft.DotNet.Tools.Add.PackageReference.LocalizableStrings;
5+
using Microsoft.DotNet.Tools.Package.Add;
6+
using LocalizableStrings = Microsoft.DotNet.Tools.Package.Add.LocalizableStrings;
127

138
namespace Microsoft.DotNet.Cli
149
{
1510
internal static class AddPackageParser
1611
{
17-
public static readonly CliArgument<string> CmdPackageArgument = new CliArgument<string>(LocalizableStrings.CmdPackage)
18-
{
19-
Description = LocalizableStrings.CmdPackageDescription
20-
}.AddCompletions((context) =>
21-
{
22-
// we should take --prerelease flags into account for version completion
23-
var allowPrerelease = context.ParseResult.GetValue(PrereleaseOption);
24-
return QueryNuGet(context.WordToComplete, allowPrerelease, CancellationToken.None).Result.Select(packageId => new CompletionItem(packageId));
25-
});
26-
27-
public static readonly CliOption<string> VersionOption = new ForwardedOption<string>("--version", "-v")
28-
{
29-
Description = LocalizableStrings.CmdVersionDescription,
30-
HelpName = LocalizableStrings.CmdVersion
31-
}.ForwardAsSingle(o => $"--version {o}")
32-
.AddCompletions((context) =>
33-
{
34-
// we can only do version completion if we have a package id
35-
if (context.ParseResult.GetValue(CmdPackageArgument) is string packageId)
36-
{
37-
// we should take --prerelease flags into account for version completion
38-
var allowPrerelease = context.ParseResult.GetValue(PrereleaseOption);
39-
return QueryVersionsForPackage(packageId, context.WordToComplete, allowPrerelease, CancellationToken.None)
40-
.Result
41-
.Select(version => new CompletionItem(version.ToNormalizedString()));
42-
}
43-
else
44-
{
45-
return Enumerable.Empty<CompletionItem>();
46-
}
47-
});
48-
49-
public static readonly CliOption<string> FrameworkOption = new ForwardedOption<string>("--framework", "-f")
50-
{
51-
Description = LocalizableStrings.CmdFrameworkDescription,
52-
HelpName = LocalizableStrings.CmdFramework
53-
}.ForwardAsSingle(o => $"--framework {o}");
54-
55-
public static readonly CliOption<bool> NoRestoreOption = new("--no-restore", "-n")
56-
{
57-
Description = LocalizableStrings.CmdNoRestoreDescription
58-
};
59-
60-
public static readonly CliOption<string> SourceOption = new ForwardedOption<string>("--source", "-s")
61-
{
62-
Description = LocalizableStrings.CmdSourceDescription,
63-
HelpName = LocalizableStrings.CmdSource
64-
}.ForwardAsSingle(o => $"--source {o}");
65-
66-
public static readonly CliOption<string> PackageDirOption = new ForwardedOption<string>("--package-directory")
67-
{
68-
Description = LocalizableStrings.CmdPackageDirectoryDescription,
69-
HelpName = LocalizableStrings.CmdPackageDirectory
70-
}.ForwardAsSingle(o => $"--package-directory {o}");
71-
72-
public static readonly CliOption<bool> InteractiveOption = new ForwardedOption<bool>("--interactive")
73-
{
74-
Description = CommonLocalizableStrings.CommandInteractiveOptionDescription,
75-
}.ForwardAs("--interactive");
76-
77-
public static readonly CliOption<bool> PrereleaseOption = new ForwardedOption<bool>("--prerelease")
78-
{
79-
Description = CommonLocalizableStrings.CommandPrereleaseOptionDescription
80-
}.ForwardAs("--prerelease");
81-
8212
private static readonly CliCommand Command = ConstructCommand();
8313

8414
public static CliCommand GetCommand()
@@ -90,46 +20,19 @@ private static CliCommand ConstructCommand()
9020
{
9121
CliCommand command = new("package", LocalizableStrings.AppFullName);
9222

93-
command.Arguments.Add(CmdPackageArgument);
94-
command.Options.Add(VersionOption);
95-
command.Options.Add(FrameworkOption);
96-
command.Options.Add(NoRestoreOption);
97-
command.Options.Add(SourceOption);
98-
command.Options.Add(PackageDirOption);
99-
command.Options.Add(InteractiveOption);
100-
command.Options.Add(PrereleaseOption);
23+
command.Arguments.Add(PackageAddCommandParser.CmdPackageArgument);
24+
command.Options.Add(PackageAddCommandParser.VersionOption);
25+
command.Options.Add(PackageAddCommandParser.FrameworkOption);
26+
command.Options.Add(PackageAddCommandParser.NoRestoreOption);
27+
command.Options.Add(PackageAddCommandParser.SourceOption);
28+
command.Options.Add(PackageAddCommandParser.PackageDirOption);
29+
command.Options.Add(PackageAddCommandParser.InteractiveOption);
30+
command.Options.Add(PackageAddCommandParser.PrereleaseOption);
31+
command.Options.Add(PackageCommandParser.ProjectOption);
10132

10233
command.SetAction((parseResult) => new AddPackageReferenceCommand(parseResult).Execute());
10334

10435
return command;
10536
}
106-
107-
public static async Task<IEnumerable<string>> QueryNuGet(string packageStem, bool allowPrerelease, CancellationToken cancellationToken)
108-
{
109-
try
110-
{
111-
var downloader = new NuGetPackageDownloader.NuGetPackageDownloader(packageInstallDir: new DirectoryPath());
112-
var versions = await downloader.GetPackageIdsAsync(packageStem, allowPrerelease, cancellationToken: cancellationToken);
113-
return versions;
114-
}
115-
catch (Exception)
116-
{
117-
return Enumerable.Empty<string>();
118-
}
119-
}
120-
121-
internal static async Task<IEnumerable<NuGetVersion>> QueryVersionsForPackage(string packageId, string versionFragment, bool allowPrerelease, CancellationToken cancellationToken)
122-
{
123-
try
124-
{
125-
var downloader = new NuGetPackageDownloader.NuGetPackageDownloader(packageInstallDir: new DirectoryPath());
126-
var versions = await downloader.GetPackageVersionsAsync(new(packageId), versionFragment, allowPrerelease, cancellationToken: cancellationToken);
127-
return versions;
128-
}
129-
catch (Exception)
130-
{
131-
return Enumerable.Empty<NuGetVersion>();
132-
}
133-
}
13437
}
13538
}

src/Cli/dotnet/commands/dotnet-add/dotnet-add-reference/AddProjectToProjectReferenceParser.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,13 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.CommandLine;
5-
using Microsoft.DotNet.Tools.Add.ProjectToProjectReference;
6-
using LocalizableStrings = Microsoft.DotNet.Tools.Add.ProjectToProjectReference.LocalizableStrings;
5+
using Microsoft.DotNet.Tools.Reference.Add;
6+
using LocalizableStrings = Microsoft.DotNet.Tools.Reference.Add.LocalizableStrings;
77

88
namespace Microsoft.DotNet.Cli
99
{
1010
internal static class AddProjectToProjectReferenceParser
1111
{
12-
public static readonly CliArgument<IEnumerable<string>> ProjectPathArgument = new(LocalizableStrings.ProjectPathArgumentName)
13-
{
14-
Description = LocalizableStrings.ProjectPathArgumentDescription,
15-
Arity = ArgumentArity.OneOrMore
16-
};
17-
18-
public static readonly CliOption<string> FrameworkOption = new CliOption<string>("--framework", "-f")
19-
{
20-
Description = LocalizableStrings.CmdFrameworkDescription,
21-
HelpName = Tools.Add.PackageReference.LocalizableStrings.CmdFramework
22-
23-
}.AddCompletions(Complete.TargetFrameworksFromProjectFile);
24-
25-
public static readonly CliOption<bool> InteractiveOption = CommonOptions.InteractiveOption;
26-
2712
private static readonly CliCommand Command = ConstructCommand();
2813

2914
public static CliCommand GetCommand()
@@ -35,9 +20,10 @@ private static CliCommand ConstructCommand()
3520
{
3621
CliCommand command = new("reference", LocalizableStrings.AppFullName);
3722

38-
command.Arguments.Add(ProjectPathArgument);
39-
command.Options.Add(FrameworkOption);
40-
command.Options.Add(InteractiveOption);
23+
command.Arguments.Add(ReferenceAddCommandParser.ProjectPathArgument);
24+
command.Options.Add(ReferenceAddCommandParser.FrameworkOption);
25+
command.Options.Add(ReferenceAddCommandParser.InteractiveOption);
26+
command.Options.Add(ReferenceCommandParser.ProjectOption);
4127

4228
command.SetAction((parseResult) => new AddProjectToProjectReferenceCommand(parseResult).Execute());
4329

src/Cli/dotnet/commands/dotnet-help/HelpUsageText.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,18 @@ internal static class HelpUsageText
3434
--version {LocalizableStrings.SDKVersionCommandDefinition}
3535
3636
{LocalizableStrings.Commands}:
37-
add {LocalizableStrings.AddDefinition}
3837
build {LocalizableStrings.BuildDefinition}
3938
build-server {LocalizableStrings.BuildServerDefinition}
4039
clean {LocalizableStrings.CleanDefinition}
4140
format {LocalizableStrings.FormatDefinition}
4241
help {LocalizableStrings.HelpDefinition}
43-
list {LocalizableStrings.ListDefinition}
4442
msbuild {LocalizableStrings.MsBuildDefinition}
4543
new {LocalizableStrings.NewDefinition}
4644
nuget {LocalizableStrings.NugetDefinition}
4745
pack {LocalizableStrings.PackDefinition}
46+
package {LocalizableStrings.PackageDefinition}
4847
publish {LocalizableStrings.PublishDefinition}
49-
remove {LocalizableStrings.RemoveDefinition}
48+
reference {LocalizableStrings.ReferenceDefinition}
5049
restore {LocalizableStrings.RestoreDefinition}
5150
run {LocalizableStrings.RunDefinition}
5251
sdk {LocalizableStrings.SdkDefinition}

src/Cli/dotnet/commands/dotnet-help/LocalizableStrings.resx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,15 @@
168168
<data name="BuildDefinition" xml:space="preserve">
169169
<value>Build a .NET project.</value>
170170
</data>
171+
<data name="PackageDefinition" xml:space="preserve">
172+
<value>Search for, add, remove, or list PackageReferences for a .NET project.</value>
173+
</data>
171174
<data name="PublishDefinition" xml:space="preserve">
172175
<value>Publish a .NET project for deployment.</value>
173176
</data>
177+
<data name="ReferenceDefinition" xml:space="preserve">
178+
<value>Add, remove, or list ProjectReferences for a .NET project.</value>
179+
</data>
174180
<data name="RunDefinition" xml:space="preserve">
175181
<value>Build and run a .NET project output.</value>
176182
</data>
@@ -186,15 +192,6 @@
186192
<data name="ProjectModificationCommands" xml:space="preserve">
187193
<value>Project modification commands</value>
188194
</data>
189-
<data name="AddDefinition" xml:space="preserve">
190-
<value>Add a package or reference to a .NET project.</value>
191-
</data>
192-
<data name="RemoveDefinition" xml:space="preserve">
193-
<value>Remove a package or reference from a .NET project.</value>
194-
</data>
195-
<data name="ListDefinition" xml:space="preserve">
196-
<value>List packages or references of a .NET project.</value>
197-
</data>
198195
<data name="AdvancedCommands" xml:space="preserve">
199196
<value>Advanced Commands</value>
200197
</data>

src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.cs.xlf

Lines changed: 10 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-help/xlf/LocalizableStrings.de.xlf

Lines changed: 10 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)