Perinci::Sub::Complete - Complete command-line argument using Rinci metadata
This document describes version 0.63 of Perinci::Sub::Complete (from Perl distribution Perinci-Sub-Complete), released on 2014-09-03.
See Perinci::CmdLine or Perinci::CmdLine::Lite or App::riap which use this module.
Given argument name and function metadata, complete array element.
Will attempt to complete using the completion routine specified in the argument specification, or if that is not specified, from argument's schema using complete_from_schema.
complete_from_schema
Arguments ('*' denotes required arguments):
arg* => str
Argument name.
args => hash
Collected arguments so far, will be passed to completion routines.
ci => bool (default: 0)
Whether to be case-insensitive.
extras => hash
To pass extra arguments to completion routines.
index => int
Index of element to complete.
meta* => hash
Rinci function metadata, must be normalized.
riap_client => 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.
completion
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
complete_arg_val
riap_server_url => str
See the riap_client argument.
riap_client
riap_uri => str
word => str (default: "")
Word to be completed.
Return value:
(array)
Given argument name and function metadata, complete value.
Complete command-line argument using Rinci function metadata.
This routine uses Perinci::Sub::GetArgs::Argv to generate Getopt::Long specification from arguments list in Rinci function metadata and common options. Then, it will use Complete::Getopt::Long to complete option names, option values, as well as arguments.
Perinci::Sub::GetArgs::Argv
Getopt::Long
Complete::Getopt::Long
common_opts => hash
Common options.
A hash where the values are hashes containing these keys: getopt (Getopt::Long option specification), handler (Getopt::Long handler). Will be passed to get_args_from_argv(). Example:
getopt
handler
get_args_from_argv()
{ help =E<gt> { getopt =E<gt> 'help|h|?', handler =E<gt> sub { ... }, summary =E<gt> 'Display help and exit', }, version =E<gt> { getopt =E<gt> 'version|v', handler =E<gt> sub { ... }, summary =E<gt> 'Display version and exit', }, }
completion => code
Supply custom completion routine.
If supplied, instead of the default completion routine, this code will be called instead. Will receive all arguments that Complete::Getopt::Long will pass, and additionally:
extras (hash)
extras
arg (str)
arg
index (int, if completing argument element value)
index
cword* => int
On which argument cursor is located (zero-based).
A hash that contains extra stuffs.
Usually used to let completion routine get extra stuffs.
Rinci function metadata.
per_arg_json => bool
Will be passed to Perinci::Sub::GetArgs::Argv.
per_arg_yaml => bool
words* => array
Command-line arguments.
(hash)
You can use `format_completion` function in `Complete::Bash` module to format the result of this function for bash.
Complete a value from schema.
Employ some heuristics to complete a value from Sah schema. For example, if schema is [str => in => [qw/new open resolved rejected/]], then we can complete from the in clause. Or for something like [int => between => [1, 20]] we can complete using values from 1 to 20.
[str => in => [qw/new open resolved rejected/]]
in
[int => between => [1, 20]]
ci => bool
schema* => any
Must be normalized.
word* => str (default: "")
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.
(any)
Complete, Complete::Getopt::Long
Perinci::CmdLine, Perinci::CmdLine::Lite, App::riap
Please visit the project's homepage at https://metacpan.org/release/Perinci-Sub-Complete.
Source repository is at https://github.com/perlancar/perl-Perinci-Sub-Complete.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Sub-Complete
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.
perlancar <perlancar@cpan.org>
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.
To install Perinci::Sub::Complete, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perinci::Sub::Complete
CPAN shell
perl -MCPAN -e shell install Perinci::Sub::Complete
For more information on module installation, please visit the detailed CPAN module installation guide.