Commits

Shlomi Fish  committed cbad283

Add the documentation for abc-path-gen.

  • Participants
  • Parent commits a78fc8f

Comments (0)

Files changed (4)

File abc-path/Games-ABC_Path-Generator/Changes

 Revision history for Games-ABC_Path-Generator
 
+0.2.0   2014-03-06
+    - Add command line usage documentation and --help and --man flags.
+
 0.1.1   2013-05-21
     - Fix the documentation of FinalLayoutObj - it had some remnants of
     the RiddleObj documentation.

File abc-path/Games-ABC_Path-Generator/lib/Games/ABC_Path/Generator/App.pm

 use strict;
 use warnings;
 
+use Pod::Usage qw(pod2usage);
+
 use base 'Games::ABC_Path::Generator::Base';
 
 use Getopt::Long qw(GetOptionsFromArray);
 
     my $seed;
     my $mode = 'riddle';
+    my $man = 0;
+    my $help = 0;
     if (!GetOptionsFromArray(
             $self->_argv(),
             'seed=i' => \$seed,
             'mode=s' => \$mode,
+            'help|h' => \$help,
+            man => \$man,
         ))
     {
-        die "Could not get options for program!";
+        pod2usage(2);
     }
 
-    if (!defined($seed))
+    if ($help)
     {
-        die "Seed not specified!";
+        pod2usage(1);
     }
+    elsif ($man)
+    {
+        pod2usage(-verbose => 2);
+    }
+    elsif (!defined($seed))
+    {
+        die "Seed not specified! See --help.";
+    }
+    else
+    {
+        my $gen = Games::ABC_Path::Generator->new({ seed => $seed, });
 
-    my $gen = Games::ABC_Path::Generator->new({ seed => $seed, });
+        if ($mode eq 'final')
+        {
+            print $gen->calc_final_layout()->as_string({});
+        }
+        elsif ($mode eq 'riddle')
+        {
+            my $riddle = $gen->calc_riddle();
 
-    if ($mode eq 'final')
-    {
-        print $gen->calc_final_layout()->as_string({});
+            my $layout_string = $riddle->get_final_layout_as_string({});
+
+            my $riddle_string = $riddle->get_riddle_v1_string;
+
+            print sprintf(
+                "ABC Path Solver Layout Version 1:\n%s",
+                $riddle_string,
+            );
+        }
+
     }
-    elsif ($mode eq 'riddle')
-    {
-        my $riddle = $gen->calc_riddle();
-
-        my $layout_string = $riddle->get_final_layout_as_string({});
-
-        my $riddle_string = $riddle->get_riddle_v1_string;
-
-        print sprintf(
-            "ABC Path Solver Layout Version 1:\n%s",
-            $riddle_string,
-        );
-    }
-
     return;
 }
 

File abc-path/Games-ABC_Path-Generator/scripts/abc-path-gen

 use Games::ABC_Path::Generator::App;
 
 Games::ABC_Path::Generator::App->new({argv => [@ARGV]})->run();
+
+=head1 NAME
+
+abc-path-gen - Generate a random (and uniquely solvable) ABC Path layout
+
+=head1 SYNOPSIS
+
+B<abc-path-gen> --seed=1
+
+B<abc-path-gen> --help
+
+=head1 DESCRIPTION
+
+This is a generator for ABC Path ( L<http://www.brainbashers.com/abcpath.asp> ).
+
+=head1 FLAGS
+
+=head2 --help -h
+
+Display the help.
+
+=head2 --man
+
+Display the man page.
+
+=head2 --seed=[num seed]
+
+Seed the random number generator with B<num seed>. Different seeds should give
+different layouts.
+
+=head1 SEE ALSO
+
+L<http://www.brainbashers.com/abcpath.asp>
+
+L<Games::Solitaire::BlackHole::Solver::App>
+
+L<Games::Solitaire::BlackHole::Solver::Board>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (c) 2011 Shlomi Fish
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+=head1 AUTHOR
+
+Shlomi Fish, L<http://www.shlomifish.org/>
+
+=cut
+

File abc-path/Games-ABC_Path-Generator/t/cmd-line-test.t

 use strict;
 use warnings;
 
-use Test::More tests => 3;
+use Test::More tests => 4;
 
 use Test::Differences;
 
         'Default is riddle mode (for seed #1)',
     );
 }
+
+{
+    my $got_output = `$^X -Mblib $prog_path --help`;
+
+    # TEST
+    like ($got_output,
+        qr/--help/,
+        "Help output is relatively sane.",
+    );
+}