#!perl

use 5.010;
use strict;
use warnings;
use Log::Any '$log';

use Perinci::CmdLine;

our $VERSION = '1.37'; # VERSION

our %SPEC;

$SPEC{generate_usage} = {
    v => 1.1,
    args => {
        url => {
            summary => 'Riap URL to function, e.g. /Git/Bunch/backup_bunch',
            req => 1,
            pos => 0,
            schema => 'str*',
        },
    },
};
sub generate_usage {
    my %args = @_;
    # XXX schema
    my $url = $args{url} or return [400, "Please specify url"];
    #$log->errorf("TMP: url=%s", $url);

    my $progname = $url; $progname =~ s!.+/!!;
    my $cmd = Perinci::CmdLine->new(
        log_any_app => 0,
        program_name => $progname,
        url => $url,
    );
    $cmd->run_help;
    [200, "OK", ''];
}

my $cmd = Perinci::CmdLine->new(
    log_any_app => 0, # speed up start-up
    url => '/main/generate_usage',
);
delete $cmd->common_opts->{format};
delete $cmd->common_opts->{format_options};
$cmd->run;

# ABSTRACT: Display command-line usage of a Riap function
# PODNAME: peri-func-usage

__END__

=pod

=encoding UTF-8

=head1 NAME

peri-func-usage - Display command-line usage of a Riap function

=head1 VERSION

This document describes version 1.37 of peri-func-usage (from Perl distribution Perinci-CmdLine), released on 2014-11-09.

=head1 SYNOPSIS

From command-line:

 % peri-func-usage /Some/Module/somefunc
 % peri-func-usage --help

=head1 DESCRIPTION

=head1 BASH COMPLETION

This script has bash completion capability.

To activate bash completion for this script, put:

 complete -C peri-func-usage peri-func-usage

in your bash startup (e.g. C<~/.bashrc>). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.

You can also install L<App::BashCompletionProg> which makes it easy to add completion for Perinci::CmdLine-based scripts. Just execute C<bash-completion-prog> and the C<complete> command will be added in your C<~/.bash-completion-prog>. Your next shell session will then recognize tab completion for the command.

=head1 HOMEPAGE

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

=head1 SOURCE

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

=head1 BUGS

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

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
