#!/usr/bin/env perl

use warnings;
use strict;

use Getopt::Long;
use Word::Rhymes;

my (%args, $help);

GetOptions(
    "help|h"        => \$help,
    "limit|l=i"     => \$args{limit},
    "multi|m=i"     => \$args{multi_word},
    "results|r=i"   => \$args{max_results},
    "score|S=i"     => \$args{min_score},
    "sort|b=s"      => \$args{sort_by},
    "syllables|s=i" => \$args{min_syllables},
);

if ($help) {
    help();
    exit;
}

if (! @ARGV) {
    print "\nIncorrect usage! Word parameter is mandatory.\n";
    help();
    exit;
}

my ($word, $context) = @ARGV;

my $wr = Word::Rhymes->new(%args);

$wr->print($word, $context);

sub help {
    print <<EOF;

Usage: rhyme [OPTIONS] <word> [context]

Options:

-h | --help         Print this help message
-b | --sort_by      Sort by: score_desc (default), score_asc, alpha_desc, alpha_asc
-s | --syllables    Minimum number of syllables in the rhyming words (1-100)
-S | --score        We only return words with a score equal to or higher than this (1-1000000)
-l | --limit        Limit the amount of sorted words returned under each syllable section (default 1000) (1-1000)
-r | --results      Maximum number of results to fetch (default 1000) (1-1000)
-m | --multi        Include "words" that are multi-word phrases (flag)

EOF

    return 1;
}

__END__

=head1 NAME

rhyme - Binary application for L<Word::Rhymes>.

=head1 Usage

    rhyme [OPTIONS] <word> [context]

For B<OPTIONS>, see L</Options>. B<word> is the word we'll find rhyming words
for. B<context> is optional, and if sent in, we'll return only rhyming words
that match in that context. Eg. Find rhyming words that rhyme with 'word', but
only if they relate to say 'breakfast'.

=head1 Options

=head2 -h|--help

Display the usage screen.

=head2 -b|--sort_by

Sorts the output prior to displaying it.

I<Valid values>:

    score_desc

Sorts by score, in descending order (eg. 100-1). This is the default.

    score_asc

Sorts by score, in ascending order (eg. 1-100).

    alpha_desc

Sorts the words alphabetically, descending (eg. a-z).

    alpha_asc

Sorts the words alphabetically, ascending (eg. z-a).

I<Default>: score_desc

=head2 -s|--syllables

We will only display words that have this many or more syllables.

I<Valid values>:

    1-100

I<Default>: 1

=head2 -S|--score

We will only display rhyming words with a score equal to or greater than this.

I<Valid values>:

    0-1000000

I<Default>: 0

=head2 -l|--limit

Limits the number of rhyming words displayed under each syllable section.

I<Valid values>:

    1-1000

I<Default>: 1000

=head2 -r|--results

How many rhyming word objects we'll fetch over the Internet.

I<Valid values>:

    1-1000

I<Default>: 1000

=head2 -m|--multi

Some rhyming words are actually multi-word phrases. Set this flag to have us
display them. By default we don't.

I<Valid values>: None, this is only a flag.

I<Default>: False/Disabled

=head1 AUTHOR

Steve Bertrand, C<< <steveb at cpan.org> >>

=head1 LICENSE AND COPYRIGHT

Copyright 2020 Steve Bertrand.

This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:

L<http://www.perlfoundation.org/artistic_license_2_0>
