From 732e4c20394701a1c254296f5e9282ac7f26a6c6 Mon Sep 17 00:00:00 2001 From: Christian Rondeau Date: Tue, 31 Mar 2015 22:45:21 -0400 Subject: [PATCH] (GH-182) Ask before printing ps1 scripts --- .../services/PowershellService.cs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs index ef4f79aa9d..aa60a83f1e 100644 --- a/src/chocolatey/infrastructure.app/services/PowershellService.cs +++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs @@ -217,16 +217,19 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack if (!shouldRun) { - this.Log().Info(ChocolateyLoggers.Important, () => " Found '{0}':".format_with(_fileSystem.get_file_name(chocoPowerShellScript))); - this.Log().Info(() => "{0}{1}{0}".format_with(Environment.NewLine, chocoPowerShellScriptContents.escape_curly_braces())); - var selection = InteractivePrompt - .prompt_for_confirmation(@" -Do you want to run the script? - NOTE: If you choose not to run the script, the installation will - fail. - Skip is an advanced option and most likely will never be wanted. -" - , new[] {"yes", "no", "skip"}, "no", requireAnswer: true); + this.Log().Info(ChocolateyLoggers.Important, () => "The package {0} wants to run '{1}'.".format_with(package.Id, _fileSystem.get_file_name(chocoPowerShellScript))); + this.Log().Info(ChocolateyLoggers.Important, () => "Note: If you don't run this script, the installation will fail."); + + var selection = InteractivePrompt.prompt_for_confirmation(@"Do you want to run the script?", new[] {"yes", "no", "print"}, "no", requireAnswer: true); + + if (selection.is_equal_to("print")) + { + this.Log().Info(ChocolateyLoggers.Important, "------ BEGIN SCRIPT ------"); + this.Log().Info(() => "{0}{1}{0}".format_with(Environment.NewLine, chocoPowerShellScriptContents.escape_curly_braces())); + this.Log().Info(ChocolateyLoggers.Important, "------- END SCRIPT -------"); + selection = InteractivePrompt.prompt_for_confirmation(@"Do you want to run this script?", new[] { "yes", "no" }, "no", requireAnswer: true); + } + if (selection.is_equal_to("yes")) shouldRun = true; if (selection.is_equal_to("no")) {