From 236830d73c7856f35fc449f97b1dfc90e59d7aa9 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Mon, 28 Oct 2019 17:10:33 +0100 Subject: [PATCH] Separation of install wizard and answer input --- .../Get-IcingaAgentInstallerAnswerInput.psm1 | 44 +++++++++++++++++ .../misc/Start-IcingaAgentInstallWizard.psm1 | 47 ------------------- 2 files changed, 44 insertions(+), 47 deletions(-) create mode 100644 lib/core/icingaagent/getters/Get-IcingaAgentInstallerAnswerInput.psm1 diff --git a/lib/core/icingaagent/getters/Get-IcingaAgentInstallerAnswerInput.psm1 b/lib/core/icingaagent/getters/Get-IcingaAgentInstallerAnswerInput.psm1 new file mode 100644 index 0000000..9dfe228 --- /dev/null +++ b/lib/core/icingaagent/getters/Get-IcingaAgentInstallerAnswerInput.psm1 @@ -0,0 +1,44 @@ +function Get-IcingaAgentInstallerAnswerInput() +{ + param( + $Prompt, + [ValidateSet("y","n","v")] + $Default, + [switch]$Secure + ); + + $DefaultAnswer = ''; + + if ($Default -eq 'y') { + $DefaultAnswer = ' (Y/n)'; + } elseif ($Default -eq 'n') { + $DefaultAnswer = ' (y/N)'; + } + + if (-Not $Secure) { + $answer = Read-Host -Prompt ([string]::Format('{0}{1}', $Prompt, $DefaultAnswer)); + } else { + $answer = Read-Host -Prompt ([string]::Format('{0}{1}', $Prompt, $DefaultAnswer)) -AsSecureString; + } + + if ($Default -ne 'v') { + $answer = $answer.ToLower(); + + $returnValue = 0; + if ([string]::IsNullOrEmpty($answer) -Or $answer -eq $Default) { + $returnValue = 1; + } else { + $returnValue = 0; + } + + return @{ + 'result' = $returnValue; + 'answer' = ''; + } + } + + return @{ + 'result' = 2; + 'answer' = $answer; + } +} diff --git a/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 b/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 index 0722083..60a5551 100644 --- a/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 +++ b/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 @@ -300,50 +300,3 @@ function Get-IcingaAgentInstallCommand() return $Installer; } } - -function Get-IcingaAgentInstallerAnswerInput() -{ - param( - $Prompt, - [ValidateSet("y","n","v")] - $Default, - [switch]$Secure - ); - - $DefaultAnswer = ''; - - if ($Default -eq 'y') { - $DefaultAnswer = ' (Y/n)'; - } elseif ($Default -eq 'n') { - $DefaultAnswer = ' (y/N)'; - } - - if (-Not $Secure) { - $answer = Read-Host -Prompt ([string]::Format('{0}{1}', $Prompt, $DefaultAnswer)); - } else { - $answer = Read-Host -Prompt ([string]::Format('{0}{1}', $Prompt, $DefaultAnswer)) -AsSecureString; - } - - if ($Default -ne 'v') { - $answer = $answer.ToLower(); - - $returnValue = 0; - if ([string]::IsNullOrEmpty($answer) -Or $answer -eq $Default) { - $returnValue = 1; - } else { - $returnValue = 0; - } - - return @{ - 'result' = $returnValue; - 'answer' = ''; - } - } - - return @{ - 'result' = 2; - 'answer' = $answer; - } -} - -Export-ModuleMember -Function @( 'Start-IcingaAgentInstallWizard' );