diff options
Diffstat (limited to 'SBO-Lib/lib/SBO/Lib/Readme.pm')
-rw-r--r-- | SBO-Lib/lib/SBO/Lib/Readme.pm | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/SBO-Lib/lib/SBO/Lib/Readme.pm b/SBO-Lib/lib/SBO/Lib/Readme.pm index b29558b..e46c557 100644 --- a/SBO-Lib/lib/SBO/Lib/Readme.pm +++ b/SBO-Lib/lib/SBO/Lib/Readme.pm @@ -4,7 +4,7 @@ use 5.016; use strict; use warnings; -our $VERSION = '2.1'; +our $VERSION = '2.5'; use SBO::Lib::Util qw/ prompt script_error slurp open_read _ERR_OPENFH usage_error /; use SBO::Lib::Tree qw/ is_local /; @@ -13,6 +13,7 @@ use Exporter 'import'; our @EXPORT_OK = qw{ ask_opts + ask_other_readmes ask_user_group get_opts get_readme_contents @@ -77,6 +78,31 @@ sub ask_opts { return(); } +=head2 ask_other_readmes + + ask_other_readmes($sbo, $location); + +C<ask_other_readmes()> checks if there are other readmes for the C<$sbo> in +C<$location>, and if so, asks the user if they should be displayed, and then +displays them if the user didn't decline. + +=cut + +sub ask_other_readmes { + my ($sbo, $location) = @_; + my @readmes = sort grep { ! m!/README$! } glob "$location/README*"; + + return unless @readmes; + + return unless prompt("\nIt looks like $sbo has additional README files. Would you like to see those too?", default => 'yes'); + + for my $fn (@readmes) { + my ($display_fn) = $fn =~ m!/(README.*)$!; + say "\n$display_fn:"; + say slurp $fn; + } +} + =head2 ask_user_group my $bool = ask_user_group($cmds, $readme); @@ -144,7 +170,7 @@ C<groupadd> commands, and returns them in an array reference. sub get_user_group { script_error('get_user_group requires an argument') unless @_ == 1; my $readme = shift; - my @cmds = $readme =~ /^\s*#*\s*(useradd.*|groupadd.*)/mg; + my @cmds = $readme =~ /^\s*#*\s*(useradd.*?|groupadd.*?)(?<!\\)\n/msg; return \@cmds; } @@ -183,6 +209,7 @@ sub user_prompt { my $opts = 0; $opts = ask_opts($sbo, $readme) if get_opts($readme); print "\n". $readme unless $opts; + ask_other_readmes($sbo, $location); # 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. @@ -200,7 +227,7 @@ Guldstrand <andreas.guldstrand@gmail.com>. The sbotools are licensed under the WTFPL <http://sam.zoy.org/wtfpl/COPYING>. -Copyright (C) 2012-2016, Jacob Pipkin, Luke Williams, Andreas Guldstrand. +Copyright (C) 2012-2017, Jacob Pipkin, Luke Williams, Andreas Guldstrand. =cut |