#!perl

our $DATE = '2014-07-22'; # DATE
our $VERSION = '0.02'; # VERSION

use 5.010001;
use strict;
use warnings;
use Perinci::CmdLine::Any;

our %SPEC;

$SPEC{smtpstatus} = {
    v => 1.1,
    summary => 'List SMTP statuses',
    args => {
        query => {
            summary     => 'Search query',
            schema      => ['str*'],
            description => <<'_',

To search for a specific code: `4.` or `x.1` or `.1.4`.

To search in summary or description: `bad` or `bad dest`.

_
            pos         => 0,
        },
        description => {
            summary     => 'Whether to show description',
            schema      => [bool => default => 0],
        },
    },
};
sub smtpstatus {
    require App::smtpstatus;

    my %args = @_;
    my $q = $args{query};

    my %fa;
    $fa{with_field_names} = 1;
    $fa{fields} = ['code', 'summary'];
    push @{ $fa{fields} }, 'description' if $args{description};
    if (defined $q) {
        if ($q =~ /^\.?(\d+|x)(?:\.(\d+|x))*$/i) {
            $fa{'code.contains'} = uc($q);
        } else {
            $fa{q} = $q;
        }
    }
    #use Data::Dump; dd \%fa;
    App::smtpstatus::list_smtp_statuses(%fa);
}

Perinci::CmdLine::Any->new(url => '/main/smtpstatus')->run;

1;
# ABSTRACT: List SMTP statuses
# PODNAME: smtpstatus

__END__

=pod

=encoding UTF-8

=head1 NAME

smtpstatus - List SMTP statuses

=head1 VERSION

This document describes version 0.02 of smtpstatus (from Perl distribution App-smtpstatus), released on 2014-07-22.

=head1 SYNOPSIS

 # Show all statuses
 % smtpstatus

 # Show all X.1.X statuses
 % smtpstatus x.1

 # Show all statuses containing 'bad destination' in summary/description
 % smtpstatus 'bad dest'

 # Show longer description
 % smptatus 'search string' --desc

=head1 TODO

=over

=item * Add implementation-specific codes (from Sendmail, qmail, Postfix, Exim, Spanel)

=item * Format

Use --format=text-pretty by default for interactive, set description's
table_column_orders (after summary, not before) and table_column_formats ([[wrap
=> {columns=>40}]]).

=back

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-smtpstatus>.

=head1 SOURCE

Source repository is at L<https://github.com/sharyanto/perl-App-smtpstatus>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-smtpstatus>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
