Skip to content

Commit

Permalink
(GH-710) prompt with timeout on some commands
Browse files Browse the repository at this point in the history
- When running as non-admin, the prompt should be presented with a
timeout.
- When running auto uninstaller and it can not find silent commands, it
should prompt with a timeout.
  • Loading branch information
ferventcoder committed Apr 24, 2016
1 parent 72934ba commit 0e9b775
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
7 changes: 4 additions & 3 deletions src/chocolatey/infrastructure.app/runners/GenericRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void warn_when_admin_needs_elevation(ChocolateyConfiguration config)
}

// NOTE: blended options may not have been fully initialized yet
if (!config.PromptForConfirmation) return;
var timeoutInSeconds = config.PromptForConfirmation ? 0 : 20;

if (shouldWarn)
{
Expand All @@ -205,9 +205,10 @@ require admin rights. Only advanced users should run choco w/out an
var selection = InteractivePrompt.prompt_for_confirmation(@"
Do you want to continue?", new[] { "yes", "no" },
defaultChoice: null,
requireAnswer: true,
requireAnswer: false,
allowShortAnswer: true,
shortPrompt: true
shortPrompt: true,
timeoutInSeconds: timeoutInSeconds
);

if (selection.is_equal_to("no"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,20 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config)
if (!key.HasQuietUninstall && installer.GetType() == typeof(CustomInstaller))
{
var skipUninstaller = true;
if (config.PromptForConfirmation)
{
var selection = InteractivePrompt.prompt_for_confirmation(
"Uninstall may not be silent (could not detect). Proceed?",
new[] { "yes", "no" },
defaultChoice: null,
requireAnswer: true,
allowShortAnswer: true,
shortPrompt: true
);
if (selection.is_equal_to("yes")) skipUninstaller = false;
}

var timeout = config.PromptForConfirmation ? 0 : 30;

var selection = InteractivePrompt.prompt_for_confirmation(
"Uninstall may not be silent (could not detect). Proceed?",
new[] { "yes", "no" },
defaultChoice: "no",
requireAnswer: true,
allowShortAnswer: true,
shortPrompt: true,
timeoutInSeconds: timeout
);
if (selection.is_equal_to("yes")) skipUninstaller = false;


if (skipUninstaller)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static IConsole Console
get { return _console.Value; }
}

public static string prompt_for_confirmation(string prompt, IEnumerable<string> choices, string defaultChoice, bool requireAnswer, bool allowShortAnswer = true, bool shortPrompt = false, int repeat = 10)
public static string prompt_for_confirmation(string prompt, IEnumerable<string> choices, string defaultChoice, bool requireAnswer, bool allowShortAnswer = true, bool shortPrompt = false, int repeat = 10, int timeoutInSeconds = 0)
{
if (repeat < 0) throw new ApplicationException("Too many bad attempts. Stopping before application crash.");
Ensure.that(() => prompt).is_not_null();
Expand Down Expand Up @@ -109,7 +109,7 @@ public static string prompt_for_confirmation(string prompt, IEnumerable<string>

Console.Write(shortPrompt ? "): " : "> ");

var selection = Console.ReadLine();
var selection = timeoutInSeconds == 0 ? Console.ReadLine() : Console.ReadLine(timeoutInSeconds * 1000);
if (shortPrompt) Console.WriteLine();

if (string.IsNullOrWhiteSpace(selection) && defaultChoice != null)
Expand Down

0 comments on commit 0e9b775

Please sign in to comment.