<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    Perinci::Sub::Complete - Shell completion routines using Rinci metadata

VERSION
    This document describes version 0.53 of Perinci::Sub::Complete (from
    Perl distribution Perinci-Sub-Complete), released on 2014-07-02.

SYNOPSIS
DESCRIPTION
    This module provides functionality for doing shell completion. It is
    meant to be used by Perinci::CmdLine and other Rinci/Riap-based CLI
    shell like App::riap.

FUNCTIONS
  complete_arg_elem(%args) -&gt; array
    Given argument name and function metadata, complete array element.

    Arguments ('*' denotes required arguments):

    *   arg* =&gt; *str*

        Argument name.

    *   args =&gt; *hash*

        Collected arguments so far, will be passed to completion routines.

    *   ci =&gt; *bool* (default: 0)

        Whether to be case-insensitive.

    *   index =&gt; *int*

        Index of element to complete.

    *   meta* =&gt; *hash*

        Rinci function metadata, must be normalized.

    *   parent_args =&gt; *hash*

        To pass parent arguments to completion routines.

    *   riap_client =&gt; *obj*

        Optional, to perform complete_arg_val to the server.

        When the argument spec in the Rinci metadata contains "completion"
        key, this means there is custom completion code for that argument.
        However, if retrieved from a remote server, sometimes the
        "completion" key no longer contains the code (it has been cleansed
        into a string). Moreover, the completion code needs to run on the
        server.

        If supplied this argument and te "riap_server_url" argument, the
        function will try to request to the server (via Riap request
        "complete_arg_val"). Otherwise, the function will just give
        up/decline completing.

    *   riap_server_url =&gt; *str*

        Optional, to perform complete_arg_val to the server.

        See the "riap_client" argument.

    *   riap_uri =&gt; *str*

        Optional, to perform complete_arg_val to the server.

        See the "riap_client" argument.

    *   word =&gt; *str* (default: "")

        Word to be completed.

    Return value:

  complete_arg_val(%args) -&gt; array
    Given argument name and function metadata, complete value.

    Arguments ('*' denotes required arguments):

    *   arg* =&gt; *str*

        Argument name.

    *   args =&gt; *hash*

        Collected arguments so far, will be passed to completion routines.

    *   ci =&gt; *bool* (default: 0)

        Whether to be case-insensitive.

    *   meta* =&gt; *hash*

        Rinci function metadata, must be normalized.

    *   parent_args =&gt; *hash*

        To pass parent arguments to completion routines.

    *   riap_client =&gt; *obj*

        Optional, to perform complete_arg_val to the server.

        When the argument spec in the Rinci metadata contains "completion"
        key, this means there is custom completion code for that argument.
        However, if retrieved from a remote server, sometimes the
        "completion" key no longer contains the code (it has been cleansed
        into a string). Moreover, the completion code needs to run on the
        server.

        If supplied this argument and te "riap_server_url" argument, the
        function will try to request to the server (via Riap request
        "complete_arg_val"). Otherwise, the function will just give
        up/decline completing.

    *   riap_server_url =&gt; *str*

        Optional, to perform complete_arg_val to the server.

        See the "riap_client" argument.

    *   riap_uri =&gt; *str*

        Optional, to perform complete_arg_val to the server.

        See the "riap_client" argument.

    *   word =&gt; *str* (default: "")

        Word to be completed.

    Return value:

  complete_cli_arg(%args) -&gt; hash
    Complete command-line argument using Rinci function metadata.

    Assuming that command-line like:

        foo a b c

    is executing some function, and the command-line arguments will be
    parsed using "Perinci::Sub::GetArgs::Argv", then try to complete
    command-line arguments using information from Rinci metadata.

    Algorithm:

    1.  If word begins with "$", we complete from environment variables and
        are done.

    2.  Call "get_args_from_argv()" to extract hash arguments from the given
        "words".

    3.  Determine whether we need to complete argument name (e.g.
        "--arg&lt;tab"&gt;) or argument value (e.g. "--arg1 &lt;tab"&gt; or "&lt;tab"&gt; at
        1st word where there is an argument specified at pos=0) or an
        element for an array argument (e.g. "a &lt;tab"&gt; where there is an
        argument with spec pos=0 and greedy=1, which means we are trying to
        complete the value of the second element (index=1) of that
        argument).

    4.  Call "custom_completer" if defined. If a list of words is returned,
        we're done. This can be used for, e.g. nested function call, e.g.:

        somecmd --opt-for-cmd ... subcmd --opt-for-subcmd ...

    5a. If we are completing argument name, then supply a list of possible
    argument names, or fallback to completing filenames.

    5b. If we are completing argument value, first check if
    "custom_arg_completer" is defined. If yes, call that routine. If a list
    of words is returned, we're done. Fallback to completing argument values
    from information in Rinci metadata (using "complete_arg_val()"
    function).

    5c. If we are completing value for an element, first check if
    "custom_arg_element_completer" is defined. If yes, call that routine. If
    a list of words is returned, we're done. Fallback to completing argument
    values from information in Rinci metadata (using "complete_arg_val()"
    function).

    Arguments ('*' denotes required arguments):

    *   common_opts =&gt; *array* (default: [["--help", "-?", "-h"]])

        Common options.

        When completing argument name, this list will be added.

    *   custom_arg_completer =&gt; *code|hash*

        Supply custom argument value completion routines.

        Either code or a hash of argument names and codes.

        If supplied, instead of the default completion routine, this code
        will be called instead when trying to complete argument value. Refer
        to function description to see when this routine is called.

        Code will be called with hash arguments containing these keys:
        "word" (string, the word to be completed), "arg" (string, the
        argument name that we are completing the value of), "args" (hash,
        the arguments that have been collected so far), "parent_args".

        A use-case for using this option: getting argument value from Riap
        client using the "complete_arg_val" action. This allows getting
        completion from remote server.

    *   custom_arg_element_completer =&gt; *code|hash*

        Supply custom argument element completion routines.

        Either code or a hash of argument names and codes.

        If supplied, instead of the default completion routine, this code
        will be called instead when trying to complete argument element.
        Refer to function description to see when this routine is called.

        Code will be called with hash arguments containing these keys:
        "word" (string, the word to be completed), "arg" (string, the
        argument name that we are completing the value of), "args" (hash,
        the arguments that have been collected so far), "parent_args", "idx"
        (the element index that we are are trying to complete, starts from
        0).

    *   custom_completer =&gt; *code*

        Supply custom completion routine.

        If supplied, instead of the default completion routine, this code
        will be called instead. Refer to function description to see when
        this routine is called.

        Code will be called with a hash argument, with these keys: "which"
        (a string with value "name" or "value" depending on whether we
        should complete argument name or value), "words" (an array, the
        command line split into words), "cword" (int, position of word in
        "words"), "word" (the word to be completed), "parent_args" (hash,
        arguments given to "complete_cli_arg()"), "args" (hash, parsed
        function arguments from "words") "remaining_words" (array, slice of
        "words" after "cword"), "meta" (the Rinci function metadata).

        Code should return an arrayref of completion, or a hashref
        containing completion in "completion" key and other hints in other
        keys, or "undef" to declare declination, on which case completion
        will resume using the standard builtin routine.

        A use-case of using this option: XXX.

    *   cword =&gt; *int*

        On which word cursor is located (zero-based).

        If unset, will be taken from COMP*LINE and COMP*POINT.

    *   extra_completer_args =&gt; *hash*

        Arguments to pass to custom completion routines.

        Completion routines will get this from their "parent_args" argument.

    *   meta* =&gt; *hash*

        Rinci function metadata, must be normalized.

    *   riap_client =&gt; *obj*

        Optional, to perform complete_arg_val to the server.

        When the argument spec in the Rinci metadata contains "completion"
        key, this means there is custom completion code for that argument.
        However, if retrieved from a remote server, sometimes the
        "completion" key no longer contains the code (it has been cleansed
        into a string). Moreover, the completion code needs to run on the
        server.

        If supplied this argument and te "riap_server_url" argument, the
        function will try to request to the server (via Riap request
        "complete_arg_val"). Otherwise, the function will just give
        up/decline completing.

    *   riap_server_url =&gt; *str*

        Optional, to perform complete_arg_val to the server.

        See the "riap_client" argument.

    *   riap_uri =&gt; *str*

        Optional, to perform complete_arg_val to the server.

        See the "riap_client" argument.

    *   words =&gt; *array*

        Command-line, broken as words.

        If unset, will be taken from COMP*LINE and COMP*POINT.

    Return value:

  complete_from_schema(%args) -&gt; [status, msg, result, meta]
    Complete a value from schema.

    Employ some heuristics to complete a value from Sah schema. For example,
    if schema is "[str =" in =&gt; [qw/new open resolved rejected/]]&gt;, then we
    can complete from the "in" clause. Or for something like "[int ="
    between =&gt; [1, 20]]&gt; we can complete using values from 1 to 20.

    Arguments ('*' denotes required arguments):

    *   ci =&gt; *bool*

    *   schema* =&gt; *any*

        Must be normalized.

    *   word* =&gt; *str* (default: "")

    Return value:

    Returns an enveloped result (an array).

    First element (status) is an integer containing HTTP status code (200
    means OK, 4xx caller error, 5xx function error). Second element (msg) is
    a string containing error message, or 'OK' if status is 200. Third
    element (result) is optional, the actual result. Fourth element (meta)
    is called result metadata and is optional, a hash that contains extra
    information.

BUGS/LIMITATIONS/TODOS
  Completing "--foo=X" not yet supported
  Unclosed quoted
    Due to parsing limitation (invokes subshell), can't complete unclosed
    quotes, e.g.

     foo "bar &lt;tab&gt;

    while shell function can complete this because they are provided
    "COMP_WORDS" and "COMP_CWORD" by bash.

SEE ALSO
    Complete

    Perinci::CmdLine

HOMEPAGE
    Please visit the project's homepage at
    &lt;https://metacpan.org/release/Perinci-Sub-Complete&gt;.

SOURCE
    Source repository is at
    &lt;https://github.com/sharyanto/perl-Perinci-Sub-Complete&gt;.

BUGS
    Please report any bugs or feature requests on the bugtracker website
    &lt;https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Sub-Complete&gt;

    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.

AUTHOR
    Steven Haryanto &lt;stevenharyanto@gmail.com&gt;

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.

</pre></body></html>