diff options
author | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-09-07 00:26:22 +0200 |
---|---|---|
committer | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-09-07 00:26:22 +0200 |
commit | da1b7f300ad26b9410c11ef0e5c49b783cc29c67 (patch) | |
tree | 95fe851682cfd3305c3d5551f41e9a0017dd7a9a /sboremove | |
parent | 50f048b798478ba98c6e8043b7e518815f9f8c3a (diff) | |
download | sbotools-da1b7f300ad26b9410c11ef0e5c49b783cc29c67.tar.xz |
sbo*, SBO::Lib::*: make use of prompt() for getting user input
Diffstat (limited to 'sboremove')
-rwxr-xr-x | sboremove | 19 |
1 files changed, 5 insertions, 14 deletions
@@ -13,7 +13,7 @@ use 5.16.0; use strict; use warnings FATAL => 'all'; -use SBO::Lib qw/ get_inst_names get_installed_packages get_sbo_location get_build_queue merge_queues get_requires get_readme_contents show_version in /; +use SBO::Lib qw/ get_inst_names get_installed_packages get_sbo_location get_build_queue merge_queues get_requires get_readme_contents prompt show_version in /; use Getopt::Long qw(:config bundling); use File::Basename; @@ -145,8 +145,7 @@ FIRST: for my $remove (@$remove_queue) { # Check for %README% value and inform user. if ( $warnings{$remove} ) { say "It is recommended that you view the README before continuing."; - print "Display README now? [y]: "; - if (<STDIN> =~ /^[Yy\n]/) { + if (prompt("Display README now?", default => 'yes')) { my $readme = get_readme_contents(get_sbo_location($remove)); if (not defined $readme) { warn "Unable to open README for $remove.\n"; @@ -156,16 +155,9 @@ FIRST: for my $remove (@$remove_queue) { } } - # Determine default behavior for prompt - my $default = 'y'; - my $regex = "[Yy\n]"; - if ($needed) { - $default = 'n'; - $regex = "[Yy]"; - } + # Determine default behavior for prompt using $needed # Ask user to confirm removal - print "Remove $remove? [$default]: "; - if (<STDIN> =~ /^$regex/) { + if (prompt("Remove $remove?", default => $needed ? 'no' : 'yes')) { confirm_remove($remove); say " * Added to remove queue\n"; } else { @@ -186,8 +178,7 @@ if ($remove_count) { # Final confirmation unless ($non_int) { - print "\nAre you sure you want to continue? [n] : "; - unless (<STDIN> =~ /^[Yy]/) { + unless (prompt("\nAre you sure you want to continue?", default => 'no')) { say 'Exiting.'; exit 0; } |