Skip to content
Snippets Groups Projects
Commit 4c291ef6 authored by Patrick Meidl's avatar Patrick Meidl
Browse files

added default value support to user_proceed()

parent d2ce116f
No related branches found
No related tags found
No related merge requests found
......@@ -265,7 +265,7 @@ sub confirm_params {
print $self->list_param_values;
# ask user if he wants to proceed
exit unless user_proceed("Continue?");
exit unless user_proceed("Continue?", 1, 'n');
}
return(1);
......
......@@ -67,18 +67,28 @@ our @EXPORT_OK = qw(
=cut
sub user_proceed {
my $text = shift;
my ($text, $interactive, $default) = @_;
print "$text\n" if $text;
print "[y/N] ";
unless (defined($default)) {
die("Need a default answer for non-interactive runs.");
}
my $input;
if ($interactive) {
print "$text\n" if $text;
print "[y/N] ";
my $input = lc(<>);
chomp $input;
$input = lc(<>);
chomp $input;
} else {
$input = $default;
}
if ($input eq 'y') {
return(1);
} else {
print "Skipping.\n";
print "Skipping.\n" if ($interactive);
return(0);
}
}
......@@ -204,7 +214,7 @@ sub path_append {
unless (-d $return_path) {
system("mkdir -p $return_path") == 0 or
throw("Unable to create directory $return_path: $!\n");
die("Unable to create directory $return_path: $!\n");
}
return $return_path;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment