#!perl

use 5.010;
use strict;
use warnings;

use App::ProgUtils;
use Perinci::CmdLine::Any -prefer_lite=>1;

our $DATE = '2014-10-27'; # DATE
our $VERSION = '0.13'; # VERSION

our %SPEC;
$SPEC{progpath} = {
    v => 1.1,
    summary => 'Locate a command',
    description => <<'_',

Basically

    % progpath PROG

is roughly the same as:

    % which PROG

except that it's written in Perl and offers (a case-insensitive) tab completion.

_
    args => {
        program => {
            schema => 'str*',
            req => 1,
            pos => 0,
            completion => $App::ProgUtils::_complete_program,
        },
        all => {
            schema => 'bool',
            cmdline_aliases => {a=>{}},
        },
    },
    "cmdline.default_format" => "text-simple",
};
sub progpath {
    require File::Which;

    my %args = @_;

    my $match;
    if ($args{all}) {
        $match = [File::Which::which($args{program})];
    } else {
        $match = File::Which::which($args{program});
        $match = defined($match) ? [$match] : [];
    }
    [200, "OK", $match];
}

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

# ABSTRACT: Locate a command
# PODNAME: progpath

__END__

=pod

=encoding UTF-8

=head1 NAME

progpath - Locate a command

=head1 VERSION

This document describes version 0.13 of progpath (from Perl distribution App-ProgUtils), released on 2014-10-27.

=head1 SYNOPSIS

Basic usage:

 % progpath mpath
 % progpath -a mpath

To activate bash completion:

 % complete -C progpath progpath; # can be put in bash startup file e.g. .bashrc
 % progpath mplay<tab>

=head1 HOMEPAGE

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

=head1 SOURCE

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

=head1 BUGS

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

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

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by perlancar@cpan.org.

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
