aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SBO-Lib/lib/SBO/Lib/Build.pm8
-rw-r--r--SBO-Lib/lib/SBO/Lib/Readme.pm16
-rw-r--r--SBO-Lib/lib/SBO/Lib/Repo.pm5
-rwxr-xr-xsboclean8
-rwxr-xr-xsboinstall5
-rwxr-xr-xsboremove19
-rwxr-xr-xsboupgrade5
7 files changed, 22 insertions, 44 deletions
diff --git a/SBO-Lib/lib/SBO/Lib/Build.pm b/SBO-Lib/lib/SBO/Lib/Build.pm
index a0ff814..fced993 100644
--- a/SBO-Lib/lib/SBO/Lib/Build.pm
+++ b/SBO-Lib/lib/SBO/Lib/Build.pm
@@ -6,7 +6,7 @@ use warnings;
our $VERSION = '2.0';
-use SBO::Lib::Util qw/ :const script_error get_sbo_from_loc get_arch check_multilib uniq %config in /;
+use SBO::Lib::Util qw/ :const prompt script_error get_sbo_from_loc get_arch check_multilib uniq %config in /;
use SBO::Lib::Tree qw/ get_sbo_location /;
use SBO::Lib::Info qw/ get_sbo_version check_x32 get_requires /;
use SBO::Lib::Download qw/ get_sbo_downloads get_dl_fns get_filename_from_link check_distfiles /;
@@ -535,8 +535,7 @@ sub process_sbos {
return \@failures, $exit if $args{NON_INT};
say "Unable to download/verify source file(s) for $sbo:";
say " $fail";
- print 'Do you want to proceed? [n] ';
- if (<STDIN> =~ /^[yY]/) {
+ if (prompt('Do you want to proceed?' , default => 'no')) {
next FIRST;
} else {
unlink for @symlinks;
@@ -572,8 +571,7 @@ sub process_sbos {
return \@failures, $exit if $count == @$todo;
say "Failure encountered while building $sbo:";
say " $fail";
- print 'Do you want to proceed [n] ';
- if (<STDIN> =~ /^[yY]/) {
+ if (prompt('Do you want to proceed?', default => 'no')) {
next FIRST;
} else {
unlink for @symlinks;
diff --git a/SBO-Lib/lib/SBO/Lib/Readme.pm b/SBO-Lib/lib/SBO/Lib/Readme.pm
index c5fb95c..dddeb8d 100644
--- a/SBO-Lib/lib/SBO/Lib/Readme.pm
+++ b/SBO-Lib/lib/SBO/Lib/Readme.pm
@@ -6,7 +6,7 @@ use warnings;
our $VERSION = '2.0';
-use SBO::Lib::Util qw/ script_error slurp open_read _ERR_OPENFH usage_error /;
+use SBO::Lib::Util qw/ prompt script_error slurp open_read _ERR_OPENFH usage_error /;
use SBO::Lib::Tree qw/ is_local /;
use Exporter 'import';
@@ -55,13 +55,9 @@ sub ask_opts {
script_error('ask_opts requires an argument') unless @_;
my ($sbo, $readme) = @_;
say "\n". $readme;
- print "\nIt looks like $sbo has options; would you like to set any";
- print ' when the slackbuild is run? [n] ';
- if (<STDIN> =~ /^[Yy]/) {
+ if (prompt("\nIt looks like $sbo has options; would you like to set any when the slackbuild is run?", default => 'no')) {
my $ask = sub {
- print "\nPlease supply any options here, or enter to skip: ";
- chomp(my $opts = <STDIN>);
- return() if $opts =~ /^\n/;
+ chomp(my $opts = prompt("\nPlease supply any options here, or enter to skip: "));
return $opts;
};
my $kv_regex = qr/[A-Z0-9]+=[^\s]+(|\s([A-Z]+=[^\s]+){0,})/;
@@ -96,8 +92,7 @@ sub ask_user_group {
print "\nIt looks like this slackbuild requires the following";
say ' command(s) to be run first:';
say " # $_" for @$cmds;
- print 'Shall I run them prior to building? [y] ';
- return <STDIN> =~ /^[Yy\n]/ ? $cmds : undef;
+ return prompt('Shall I run them prior to building?', default => 'yes') ? $cmds : undef;
}
=head2 get_opts
@@ -184,11 +179,10 @@ sub user_prompt {
my $opts = 0;
$opts = ask_opts($sbo, $readme) if get_opts($readme);
print "\n". $readme unless $opts;
- print "\nProceed with $sbo? [y]: ";
# we have to return something substantial if the user says no so that we
# can check the value of $cmds on the calling side. we should be able to
# assume that 'N' will never be a valid command to run.
- return 'N' unless <STDIN> =~ /^[Yy\n]/;
+ return 'N' unless prompt("\nProceed with $sbo?", default => 'yes');
return $cmds, $opts;
}
diff --git a/SBO-Lib/lib/SBO/Lib/Repo.pm b/SBO-Lib/lib/SBO/Lib/Repo.pm
index b4205a6..e8e7c2e 100644
--- a/SBO-Lib/lib/SBO/Lib/Repo.pm
+++ b/SBO-Lib/lib/SBO/Lib/Repo.pm
@@ -6,7 +6,7 @@ use warnings;
our $VERSION = '2.0';
-use SBO::Lib::Util qw/ %config usage_error get_slack_version script_error open_fh open_read in /;
+use SBO::Lib::Util qw/ %config prompt usage_error get_slack_version script_error open_fh open_read in /;
use Cwd;
use File::Copy;
@@ -338,8 +338,7 @@ C<$repo_path>, and if not, offer to run C<sbosnap fetch> for you.
sub slackbuilds_or_fetch {
unless (chk_slackbuilds_txt()) {
say 'It looks like you haven\'t run "sbosnap fetch" yet.';
- print 'Would you like me to do this now? [y] ';
- if (<STDIN> =~ /^[Yy\n]/) {
+ if (prompt("Would you like me to do this now?", default => 'yes')) {
fetch_tree();
} else {
say 'Please run "sbosnap fetch"';
diff --git a/sboclean b/sboclean
index 6e080b9..5551333 100755
--- a/sboclean
+++ b/sboclean
@@ -13,7 +13,7 @@
use 5.16.0;
use strict;
use warnings FATAL => 'all';
-use SBO::Lib qw/ usage_error script_error in show_version %config /;
+use SBO::Lib qw/ prompt usage_error script_error in show_version %config /;
use File::Basename;
use Getopt::Long qw(:config bundling);
use File::Path qw(remove_tree);
@@ -60,8 +60,7 @@ sub rm_full {
script_error('rm_full requires an argument.') unless @_ == 1;
my $full = shift;
if ($interactive) {
- print "Remove $full? [n] ";
- return() unless <STDIN> =~ /^[Yy]/;
+ return() unless prompt("Remove $full?", default => 'no');
}
unlink $full if -f $full;
remove_tree($full) if -d $full;
@@ -100,8 +99,7 @@ if ($clean_work) {
my $tsbo = $SBO::Lib::tmpd;
if ($env_tmp && !$interactive) {
warn "This will remove the entire contents of $env_tmp\n";
- print "Proceed? [y] ";
- remove_stuff($tsbo) if <STDIN> =~ /^[yY\n]/;
+ remove_stuff($tsbo) if prompt("Proceed?", default => 'yes');
} else {
remove_stuff($tsbo);
}
diff --git a/sboinstall b/sboinstall
index 6cb2d0d..05b493d 100755
--- a/sboinstall
+++ b/sboinstall
@@ -13,7 +13,7 @@
use 5.16.0;
use strict;
use warnings FATAL => 'all';
-use SBO::Lib qw/ %config _ERR_OPENFH get_arch get_build_queue get_installed_cpans get_installed_packages get_sbo_location get_sbo_locations merge_queues open_fh print_failures process_sbos show_version slackbuilds_or_fetch slurp usage_error user_prompt /;
+use SBO::Lib qw/ %config _ERR_OPENFH get_arch get_build_queue get_installed_cpans get_installed_packages get_sbo_location get_sbo_locations merge_queues open_fh print_failures process_sbos prompt show_version slackbuilds_or_fetch slurp usage_error user_prompt /;
use Getopt::Long qw(:config bundling);
use File::Basename;
use JSON::PP;
@@ -207,8 +207,7 @@ FIRST: for my $sbo (@$build_queue) {
exit 0 if @{ $build_queue } == 0;
say "\nInstall queue: " . join(' ', @$build_queue);
unless ($non_int) {
- print "\nAre you sure you wish to continue? [y]: ";
- exit 0 unless <STDIN> =~ /^[Yy\n]/;
+ exit 0 unless prompt("\nAre you sure you wish to continue?", default => 'yes');
}
if (defined $ctemp) {
diff --git a/sboremove b/sboremove
index 96de68e..d1d78ee 100755
--- a/sboremove
+++ b/sboremove
@@ -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;
}
diff --git a/sboupgrade b/sboupgrade
index dd4f097..043c567 100755
--- a/sboupgrade
+++ b/sboupgrade
@@ -13,7 +13,7 @@
use 5.16.0;
use strict;
use warnings FATAL => 'all';
-use SBO::Lib qw/ get_available_updates usage_error slackbuilds_or_fetch uniq get_sbo_location get_inst_names get_installed_packages get_build_queue get_sbo_locations merge_queues user_prompt process_sbos print_failures %config show_version /;
+use SBO::Lib qw/ get_available_updates prompt usage_error slackbuilds_or_fetch uniq get_sbo_location get_inst_names get_installed_packages get_build_queue get_sbo_locations merge_queues user_prompt process_sbos print_failures %config show_version /;
use Getopt::Long qw(:config bundling);
use File::Basename;
use File::Copy;
@@ -200,8 +200,7 @@ FIRST: for my $sbo (@$upgrade_queue) {
exit 0 unless exists $$upgrade_queue[0];
say "\nUpgrade queue: ". join(' ', @$upgrade_queue);
unless ($non_int) {
- print "\nAre you sure you wish to continue? [y]: ";
- exit 0 unless <STDIN> =~ /^[Yy\n]/;
+ exit 0 unless prompt("\nAre you sure you wish to continue?", default => 'yes');
}
my ($failures, $exit) = process_sbos(