#!/usr/bin/env perl
use 5.010;
use open qw< :encoding(utf8) :std >;
use Dir::Self;
use Any::Moose;
use Encode qw(decode);
use Hailo::Command;
use namespace::clean -except => 'meta';

# Nothing to see here
__PACKAGE__->meta->make_immutable;

# use utf8 everywhere
$_ = decode('utf8', $_) for @ARGV;

# Set programname
$0 = 'hailo';

if ($] < 5.013000 and $^O eq 'linux') {
    local $@;
    eval {
        require Sys::Prctl;
        Sys::Prctl::prctl_name('hailo');
    };
}

# I want my mommy!
$Hailo::Command::HERE_MOMMY = __DIR__;

# Show help if run without arguments
@ARGV = qw(--help) unless @ARGV;

# Hailing frequencies open
Hailo::Command->new_with_options->run;

=encoding utf8

=head1 NAME

hailo - Command-line interface to the L<Hailo|Hailo> Markov bot

=head1 USAGE

    usage: hailo [-abEhLlopRrSsTtuv] [long options...]
	-v --version           Print version and exit
	-u --ui                Use UI CLASS
	-t --train             Learn from all the lines in FILE, use - for STDIN
	-s --stats             Print statistics about the brain
	-r --reply             Reply to STRING
	-p --progress          Display progress during the import
	-o --order             Markov order; How deep the rabbit hole goes
	-l --learn             Learn from STRING
	-h --help              You're soaking it in
	-b --brain             Load/save brain to/from FILE
	-a --autosave          Save the brain on exit (on by default)
	-T --tokenizer         Use tokenizer CLASS
	-S --storage           Use storage CLASS
	-R --random-reply      Like --reply but takes no STRING; Babble at random
	-L --learn-reply       Learn from STRING and reply to it
	-E --engine            Use engine CLASS
	--ui-args              Arguments for the UI class
	--tokenizer-args       Arguments for the Tokenizer class
	--storage-args         Arguments for the Storage class
	--examples             Print examples along with the help message
	--engine-args          Arguments for the Engine class
	--brain-resource       Alias for `brain' for backwards compatibility

	Note: All input/output and files are assumed to be UTF-8 encoded.

=head1 SYNOPSIS

Train in-memory from fortune files and reply:

    for i in {1..1000}; do fortune >> /tmp/fortune.trn; done
    hailo --brain :memory: --train /tmp/fortune.trn --reply art
    # ==> He hath eaten me out of an art deeper than we ourselves.

Create an on-disk brain for later use:

    hailo --brain hailo.brn --train /tmp/fortune.trn
    hailo --brain hailo.brn --reply "is"
    # ==> Earth is ballasted with bones of millions of dollars.

Interact with the brain using readline:

    hailo --brain hailo.brn
    hailo> hello there
    # ==> Wife asked "what have you got there?" replied he, "just my cup of fur".

=head1 DESCRIPTION

See the documentation for L<Hailo|Hailo> for more information.

=head1 AUTHOR

E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org>

=head1 LICENSE AND COPYRIGHT

Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org>

This program is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut
