From 094b6db1c01f8796abb1037af48e3bdffb5bdaaa Mon Sep 17 00:00:00 2001 From: Flavio Poletti Date: Tue, 17 Apr 2018 09:59:43 +0200 Subject: [PATCH] Cope with absence of IO::Prompt --- deploy | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/deploy b/deploy index 4f24315..11c92d1 100755 --- a/deploy +++ b/deploy @@ -8,7 +8,6 @@ use Getopt::Long qw( :config gnu_getopt ); use English qw( -no_match_vars ); use Net::SSH::Perl; use Net::SSH::Perl::Auth; -use IO::Prompt; use Data::Dumper; use File::Spec::Functions qw( catfile ); @@ -46,9 +45,13 @@ pod2usage(-verbose => 99, -sections => 'USAGE|EXAMPLES|OPTIONS', -noperldoc => 1 pod2usage(-verbose => 2, -noperldoc => 1) if $config{man}; pod2usage(-verbose => 99, -sections => 'USAGE', -noperldoc => 1, - message => 'Only one allowed between --stdout and --stderr') + message => "Only one allowed between --stdout and --stderr\n") if $config{stdout} && $config{stderr}; +pod2usage(-verbose => 99, -sections => 'USAGE', -noperldoc => 1, + message => "IO::Prompt not available, re-run with --no-prompt\n") + if $config{prompt} && ! eval { require IO::Prompt; 1 }; + # Script implementation here my @hostnames = @ARGV; @ARGV = (); @@ -56,8 +59,12 @@ my @hostnames = @ARGV; if (exists $config{password}) { $config{interactive} = 1; $config{identity_files} = []; - $config{password} = prompt 'password: ', -e => '*' - unless $config{password}; + if (! $config{password}) { + pod2usage(-verbose => 99, -sections => 'USAGE', -noperldoc => 1, + message => "IO::Prompt not available, set password :(\n") + unless eval { require IO::Prompt; 1 }; + $config{password} = IO::Prompt::prompt('password: ', -e => '*'); + } } if ($config{commandline}) { @@ -89,8 +96,8 @@ sub operate_on_host { if ($config{prompt}) { print {$ffh} "*** OPERATING ON $hostname ***\n"; - my $choice = lc(prompt "$hostname - continue? (Yes | Skip | Quit) ", - -while => qr/\A[qsy]\z/mxs); + my $choice = lc(IO::Prompt::prompt("$hostname - continue? (Yes | Skip | Quit) ", + -while => qr/\A[qsy]\z/mxs)); return if $choice eq 's'; exit 0 if $choice eq 'q'; } ## end if ($config{prompt}) -- 2.11.4.GIT