From f6235f3365decadd339ad654fc000ed5852c7b3b Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Sun, 3 May 2015 23:18:41 +0200 Subject: Added help_requested (checked from command line) --- lib/ManaTools/Shared.pm | 30 ++++++++++++++++++++++++++++++ t/08-Shared.t | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/ManaTools/Shared.pm b/lib/ManaTools/Shared.pm index feb2ebc7..20597890 100644 --- a/lib/ManaTools/Shared.pm +++ b/lib/ManaTools/Shared.pm @@ -46,6 +46,7 @@ This module collects all the routines shared between ManaTools and its modules. custom_locale_dir devel_mode command_line + help_requested =head1 SUPPORT @@ -102,6 +103,7 @@ our @EXPORT_OK = qw( custom_locale_dir devel_mode command_line + help_requested ); @@ -450,5 +452,33 @@ sub devel_mode() { return ($pos > 0) ? 1 : 0; } +#============================================================= + +=head2 help_requested + +=head3 OUTPUT + + boolean: 1 if "--help" or "-h" is passed to command line, 0 + otherwhise + +=head3 DESCRIPTION + + returns 1 if "--help" or "-h" is passed to command line, + modules should check this value to work accordingly + +=cut + +#============================================================= +sub help_requested() { + my $cmdline = ManaTools::Shared::command_line(); + my $pos = $cmdline->find("--help"); + return 1 if $pos > 0; + + $pos = $cmdline->find("--help"); + return 1 if $pos > 0; + + return 0; +} + 1; # End of ManaTools::Shared diff --git a/t/08-Shared.t b/t/08-Shared.t index 3489a4a0..a1c81ef3 100644 --- a/t/08-Shared.t +++ b/t/08-Shared.t @@ -10,6 +10,6 @@ BEGIN { ok ( ManaTools::Shared::command_line(), 'command_line'); is ( ManaTools::Shared::custom_locale_dir(), undef, 'custom_locale_dir'); is ( ManaTools::Shared::devel_mode(), 0, 'devel_mode'); - +is ( ManaTools::Shared::help_requested(), 0, 'help_requested'); done_testing; -- cgit v1.2.1