Skip to content

Commit 56cc63a

Browse files
committed
Improve dotnet tool exec UI
1 parent 321fd59 commit 56cc63a

15 files changed

+242
-151
lines changed

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,10 +2485,14 @@ To display a value, specify the corresponding command-line option without provid
24852485
<data name="ToolExecuteCommandMissingPackageId" xml:space="preserve">
24862486
<value>Missing package ID</value>
24872487
</data>
2488-
<data name="ToolRunFromSourceUserConfirmationPrompt" xml:space="preserve">
2489-
<value>Tool package {0}@{1} will be downloaded from source {2}. Proceed? [y/n]</value>
2488+
<data name="ToolDownloadConfirmationPrompt" xml:space="preserve">
2489+
<value>Tool package {0}@{1} will be downloaded from source {2}.
2490+
Proceed? [y/n]</value>
24902491
</data>
2491-
<data name="ToolRunFromSourceUserConfirmationFailed" xml:space="preserve">
2492-
<value>Run from source approval denied by the user</value>
2492+
<data name="ToolDownloadCanceled" xml:space="preserve">
2493+
<value>Tool package download canceled</value>
2494+
</data>
2495+
<data name="ToolDownloadNeedsConfirmation" xml:space="preserve">
2496+
<value>Tool package download needs confirmation. Run in interactive mode or use the "--yes" command-line option to confirm.</value>
24932497
</data>
24942498
</root>

src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ internal class ToolExecuteCommand(ParseResult result, ToolManifestFinder? toolMa
4646
IgnoreFailedSources: result.GetValue(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption),
4747
Interactive: result.GetValue(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption));
4848

49-
// TODO: Use prerelease
50-
private readonly bool _prerelease = result.GetValue(ToolExecuteCommandParser.PrereleaseOption);
51-
5249
private readonly ToolManifestFinder _toolManifestFinder = toolManifestFinder ?? new ToolManifestFinder(new DirectoryPath(currentWorkingDirectory ?? Directory.GetCurrentDirectory()));
5350

5451
public override int Execute()
@@ -106,9 +103,15 @@ public override int Execute()
106103
{
107104
if (!UserAgreedToRunFromSource(packageId, bestVersion, packageSource))
108105
{
109-
// TODO: Refactor this to print a better message, and probably a different message depending on whether the user selected no
110-
// or whether interactive mode was off
111-
throw new GracefulException(CliCommandStrings.ToolRunFromSourceUserConfirmationFailed, isUserError: true);
106+
if (_interactive)
107+
{
108+
// TODO: Should we return an exit code that indicates the user canceled the operation?
109+
throw new GracefulException(CliCommandStrings.ToolDownloadCanceled, isUserError: true);
110+
}
111+
else
112+
{
113+
throw new GracefulException(CliCommandStrings.ToolDownloadNeedsConfirmation, isUserError: true);
114+
}
112115
}
113116

114117
// We've already determined which source we will use and displayed that in a confirmation message to the user.
@@ -149,21 +152,14 @@ private bool UserAgreedToRunFromSource(PackageId packageId, NuGetVersion version
149152

150153
// TODO: Use a better way to ask for user input
151154
// TODO: How to localize y/n and interpret keys correctly? Does Spectre.Console handle this?
152-
string promptMessage = string.Format(CliCommandStrings.ToolRunFromSourceUserConfirmationPrompt, packageId, version.ToString(), source.Source);
155+
string promptMessage = string.Format(CliCommandStrings.ToolDownloadConfirmationPrompt + " ", packageId, version.ToString(), source.Source);
153156

154157
Console.Write(promptMessage);
155158
bool userAccepted = Console.ReadKey().Key == ConsoleKey.Y;
156159

157-
if (_verbosity >= VerbosityOptions.detailed)
158-
{
159-
Console.WriteLine();
160-
Console.WriteLine(new String('-', promptMessage.Length));
161-
}
162-
else
163-
{
164-
// Clear the line
165-
Console.Write("\r" + new string(' ', promptMessage.Length + 1) + "\r");
166-
}
160+
Console.WriteLine();
161+
// TODO: Do we want a separator like this? Seems like it's meant to separate the output of the tool from the prompt.
162+
//Console.WriteLine(new String('-', promptMessage.Length + 2));
167163

168164
return userAccepted;
169165
}

src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf

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

src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf

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

src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf

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

src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf

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

src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf

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

src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf

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

0 commit comments

Comments
 (0)