The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!perl

our $DATE = '2015-01-11'; # DATE
our $VERSION = '1.44'; # VERSION

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

use Perinci::CmdLine;

our %SPEC;

$SPEC{generate_usage} = {
    v => 1.1,
    summary => 'Display command-line usage of a Riap function',
    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 => 0,
        program_name => $progname,
        url => $url,
    );
    $cmd->run_help;
    [200, "OK", ''];
}

my $cmd = Perinci::CmdLine->new(
    log => 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.44 of peri-func-usage (from Perl distribution Perinci-CmdLine), released on 2015-01-11.

=head1 SYNOPSIS

From command-line:

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

=head1 DESCRIPTION

=head1 OPTIONS

C<*> marks required options.

=over

=item B<--config-path>=I<s>

{en_US Set path to configuration file}.

Can be specified multiple times.

=item B<--config-profile>=I<s>

{en_US Set configuration profile to use}.

=item B<--help>, B<-h>, B<-?>

{en_US Display this help message}.

=item B<--no-config>

{en_US Do not use any configuration file}.

=item B<--url>=I<s>*

{en_US Riap URL to function, e.g. /Git/Bunch/backup_bunch}.

=item B<--version>, B<-v>

=back

=head1 COMPLETION

This script has shell tab completion capability with support for several shells.

=head2 bash

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.

It is recommended, however, that you install L<shcompgen> which allows you to activate completion scripts for several kinds of scripts on multiple shells. Some CPAN distributions (those that are built with L<Dist::Zilla::Plugin::GenShellCompletion>) will even automatically enable shell completion for their included scripts (using C<shcompgen>) at installation time, so you can immadiately have tab completion.

=head2 tcsh

To activate tcsh completion for this script, put:

 complete peri-func-usage 'p/*/`peri-func-usage`/'

in your tcsh startup (e.g. C<~/.tcshrc>). 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.

It is also recommended to install C<shcompgen> (see above).

=head2 other shells

For fish and zsh, install C<shcompgen> as described above.

=head1 ENVIRONMENT

PERI_FUNC_USAGE_OPT

=head1 FILES

~/peri-func-usage.conf

/etc/peri-func-usage.conf

=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) 2015 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