Skip to content

Commit 2e33374

Browse files
committed
Improve confirmation prompt and other text updates
1 parent cde3627 commit 2e33374

29 files changed

+303
-142
lines changed

src/Cli/dotnet/CliStrings.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,6 @@ For a list of locations searched, specify the "-d" option before the tool name.<
813813
<comment>{Locked="--version"}</comment>
814814
</data>
815815
<data name="YesOptionDescription" xml:space="preserve">
816-
<value>Overrides confirmation prompt with "yes" value. </value>
816+
<value>Suppresses confirmation prompt with "yes" value.</value>
817817
</data>
818818
</root>

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,17 +2482,26 @@ To display a value, specify the corresponding command-line option without provid
24822482
<data name="ToolExecuteCommandDescription" xml:space="preserve">
24832483
<value>Executes a tool from source without permanently installing it.</value>
24842484
</data>
2485-
<data name="ToolExecuteCommandMissingPackageId" xml:space="preserve">
2486-
<value>Missing package ID</value>
2487-
</data>
24882485
<data name="ToolDownloadConfirmationPrompt" xml:space="preserve">
24892486
<value>Tool package {0}@{1} will be downloaded from source {2}.
2490-
Proceed? [y/n]</value>
2487+
Proceed?</value>
2488+
</data>
2489+
<data name="ConfirmationPromptYesValue" xml:space="preserve">
2490+
<value>y</value>
2491+
<comment>For a command line connfirmation prompt, this is the key that should be pressed for "yes", ie to agree.</comment>
2492+
</data>
2493+
<data name="ConfirmationPromptNoValue" xml:space="preserve">
2494+
<value>n</value>
2495+
<comment>For a command line connfirmation prompt, this is the key that should be pressed for "no", ie to cancel the operation.</comment>
2496+
</data>
2497+
<data name="ConfirmationPromptInvalidChoiceMessage" xml:space="preserve">
2498+
<value>Please type '{0}' for yes or '{1}' for no.</value>
24912499
</data>
24922500
<data name="ToolDownloadCanceled" xml:space="preserve">
24932501
<value>Tool package download canceled</value>
24942502
</data>
24952503
<data name="ToolDownloadNeedsConfirmation" xml:space="preserve">
24962504
<value>Tool package download needs confirmation. Run in interactive mode or use the "--yes" command-line option to confirm.</value>
2505+
<comment>{Locked="--yes"}</comment>
24972506
</data>
24982507
</root>

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,37 @@ private bool UserAgreedToRunFromSource(PackageId packageId, NuGetVersion version
155155

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

160-
Console.Write(promptMessage);
161-
bool userAccepted = Console.ReadKey().Key == ConsoleKey.Y;
160+
static string AddPromptOptions(string message)
161+
{
162+
return $"{message} [{CliCommandStrings.ConfirmationPromptYesValue}/{CliCommandStrings.ConfirmationPromptNoValue}] ({CliCommandStrings.ConfirmationPromptYesValue}): ";
163+
}
164+
165+
Console.Write(AddPromptOptions(promptMessage));
166+
167+
static bool KeyMatches(ConsoleKeyInfo pressedKey, string valueKey)
168+
{
169+
// Apparently you can't do invariant case insensitive comparison on a char directly, so we have to convert it to a string.
170+
// The resource string should be a single character, but we take the first character just to be sure.
171+
return pressedKey.KeyChar.ToString().ToLowerInvariant().Equals(
172+
valueKey.ToLowerInvariant().Substring(0, 1));
173+
}
162174

163-
Console.WriteLine();
164-
// TODO: Do we want a separator like this? Seems like it's meant to separate the output of the tool from the prompt.
165-
//Console.WriteLine(new String('-', promptMessage.Length + 2));
175+
while (true)
176+
{
177+
var key = Console.ReadKey();
178+
Console.WriteLine();
179+
if (key.Key == ConsoleKey.Enter || KeyMatches(key, CliCommandStrings.ConfirmationPromptYesValue))
180+
{
181+
return true;
182+
}
183+
if (key.Key == ConsoleKey.Escape || KeyMatches(key, CliCommandStrings.ConfirmationPromptNoValue))
184+
{
185+
return false;
186+
}
166187

167-
return userAccepted;
188+
Console.Write(AddPromptOptions(string.Format(CliCommandStrings.ConfirmationPromptInvalidChoiceMessage, CliCommandStrings.ConfirmationPromptYesValue, CliCommandStrings.ConfirmationPromptNoValue)));
189+
}
168190
}
169191
}

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

Lines changed: 18 additions & 8 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: 18 additions & 8 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: 18 additions & 8 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: 18 additions & 8 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: 18 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)