App-GenPericmdCompleterScript

 view release on metacpan or  search on metacpan

lib/App/GenPericmdCompleterScript.pm  view on Meta::CPAN

package App::GenPericmdCompleterScript;

use 5.010001;
use strict;
use warnings;
use Log::ger;

use Data::Dmp;

use Exporter qw(import);

our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2023-07-11'; # DATE
our $DIST = 'App-GenPericmdCompleterScript'; # DIST
our $VERSION = '0.126'; # VERSION

our @EXPORT_OK = qw(gen_pericmd_completer_script);

our %SPEC;

sub _pa {
    state $pa = do {
        require Perinci::Access::Lite;
        my $pa = Perinci::Access::Lite->new;
        $pa;
    };
    $pa;
}

sub _riap_request {
    my ($action, $url, $extras, $main_args) = @_;

    local $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0
        unless $main_args->{ssl_verify_hostname};

    _pa()->request($action => $url, %{$extras // {}});
}

$SPEC{gen_pericmd_completer_script} = {
    v => 1.1,
    summary => 'Generate Perinci::CmdLine completer script',
    args => {
        program_name => {
            summary => 'Program name that is being completed',
            schema  => 'str*',
            req     => 1,
            pos     => 0,
        },
        url => {
            summary => 'URL to function (or package, if you have subcommands)',
            schema => 'riap::url*',
            req => 1,
            pos => 1,
            tags => ['category:pericmd-attribute'],
        },
        subcommands => {
            summary => 'Hash of subcommand names and function URLs',
            description => <<'_',

Optionally, it can be additionally followed by a summary, so:

    URL[:SUMMARY]

Example (on CLI):

    --subcommand "delete=/My/App/delete_item:Delete an item"

_
            schema => ['hash*', of=>['any*', of=>['hash*', 'str*']]],
            cmdline_aliases => { s=>{} },
            tags => ['category:pericmd-attribute'],
        },
        subcommands_from_package_functions => {
            summary => "Form subcommands from functions under package's URL",
            schema => ['bool', is=>1],
            description => <<'_',

This is an alternative to the `subcommand` option. Instead of specifying each
subcommand's name and URL, you can also specify that subcommand names are from
functions under the package URL in `url`. So for example if `url` is `/My/App/`,
hen all functions under `/My/App` are listed first. If the functions are:

    foo
    bar
    baz_qux

then the subcommands become:

    foo => /My/App/foo
    bar => /My/App/bar
    "baz-qux" => /My/App/baz_qux

_
        },



( run in 0.650 second using v1.01-cache-2.11-cpan-39bf76dae61 )