Commits

Shlomi Fish committed d675569

Add --man, --help, and --version flags.

Comments (0)

Files changed (3)

App-Countdown/Changes

 Revision history for App-Countdown
 
+        Add --version, --help, and --man flags.
+            - Thanks to Steven Haryanto from
+            http://blogs.perl.org/users/shlomi_fish/2012/11/three-command-line-utilities.html#comments
+
 0.0.4   Tue 13 Nov 19:10:14 IST 2012
         URL to the repo changed to fix a typo. Updated Build.PL.
 

App-Countdown/bin/countdown

 
 =head1 OPTIONS
 
-    None so far.
+    --man - displays the man page.
+    --help - displays the help.
+    --version - displays the version.
 
 =head1 DESCRIPTION
 

App-Countdown/lib/App/Countdown.pm

 use Time::HiRes qw(sleep time);
 use POSIX qw();
 use IO::Handle;
-
+use Getopt::Long qw(GetOptionsFromArray);
+use Pod::Usage;
 use Carp;
 
 =head1 NAME
 
     my $argv = [@{$args->{argv}}];
 
+    my $help = 0;
+    my $man = 0;
+    my $version = 0;
+    if (! (my $ret = GetOptionsFromArray(
+        $argv,
+        'help|h' => \$help,
+        man => \$man,
+        version => \$version,
+    )))
+    {
+        die "GetOptions failed!";
+    }
+
+    if ($help)
+    {
+        pod2usage(1);
+    }
+
+    if ($man)
+    {
+        pod2usage(-verbose => 2);
+    }
+
+    if ($version)
+    {
+        print "countdown version $VERSION .\n";
+        exit(0);
+    }
+
     my $delay = shift(@$argv);
 
     if (!defined $delay)