Dist::Zilla::Plugin::GenPericmdScript - Generate Perinci::CmdLine script
This document describes version 0.425 of Dist::Zilla::Plugin::GenPericmdScript (from Perl distribution Dist-Zilla-Plugin-GenPericmdScript), released on 2023-07-11.
In dist.ini:
; generate a script, by default called script/check-palindrome [GenPericmdScript] url=/My/Palindrome/check_palindrome ; generate another script, called script/lssrv [GenPericmdScript / Gen_lssrv] url=/My/App/list_servers name=lssrv
After build, script/check-palindrome and script/lssrv will be created.
script/check-palindrome
script/lssrv
After you add Rinci metadata to your function, e.g.:
package My::Palindrome; $SPEC{check_palindrome} = { v => 1.1, args => { text => { schema=>'str*', req=>1, pos=>0 }, ci => { schema=>'bool*', cmdline_aliases=>{i=>{}} }, }, result_naked => 1, }; sub check_palindrome { my %args = @_; my $text = $args{ci} ? lc($args{text}) : $args{text}; $text eq reverse($text); }
you can create a command-line script for that function that basically is not much more than:
#!perl use Perinci::CmdLine::Any; Perinci::CmdLine::Any->new(url => '/My/Palindrome/check_palindrome');
This Dist::Zilla plugin lets you automate the creation of such scripts.
Creating scripts. To create a single script, put this in dist.ini:
dist.ini
[GenPericmdScript] ;required url=/My/Palindrome/check_palindrome ;optional abstract=Check if a text is a palindrome ; ...
To create more scripts, load the plugin again using the [Plugin/Name] syntax, e.g.:
[Plugin/Name]
[GenPericmdScript / GenAnotherScript] ...
Boolean. Will be passed to Perinci::CmdLine::Gen backend.
Boolean, default false. Will be passed to Perinci::CmdLine object construction code.
String. Select module to use. Default is Perinci::CmdLine::Any, but you can set this to classic (equals to Perinci::CmdLine::Classic), any (Perinci::CmdLine::Any), or lite (Perinci::CmdLine::Lite) or module name.
classic
any
lite
String.
Array of strings. Will be passed to Perinci::CmdLine object construction code.
String or array of strings. Will be passed to Perinci::CmdLine object construction code.
Boolean, default true. Will be passed to Perinci::CmdLine::Gen backend. Can be used to disable `--help` in generated CLI.
String. Will be passed to Perinci::CmdLine::Gen backend. Can be used to change `--help` in generated CLI to some other option name.
Boolean, default true. Will be passed to Perinci::CmdLine::Gen backend. Can be used to disable `--version in generated CLI`.
String. Will be passed to Perinci::CmdLine::Gen backend. Can be used to change the `--version` in generated CLI to some other option name.
String. Passed to Perinci::CmdLine object construction code.
String. If set, will add this code to the generated script:
BEGIN { no warnings; $main::Log_Level = "..." }
This can be used if you want your script to be verbose by default, for example.
Boolean, default false. Will be passed to Perinci::CmdLine object construction code (as log).
log
Regex. Will be passed to Perinci::CmdLine::Gen backend.
Comma-separated string, will be passed to Perinci::CmdLine object construction code (as array).
Array of strings. Extra modules to load in the generated script.
String. Name of script to create. Default will be taken from function (or package) name, with _ replaced to -.
_
-
Boolean, default true. If set to 0 and you are using Perinci::CmdLine::Any, -prefer_lite option will be passed in the code.
Perinci::CmdLine::Any
-prefer_lite
Boolean, default true. Will be passed to Perinci::CmdLine::Gen backend. Can be used to prevent the generated CLI from reading from config files.
Bool, default true. Will be passed to Perinci::CmdLine::Gen backend. Can be used to prevent the genreated CLI from reading from environment variable.
Boolean. Passed to Perinci::CmdLine object construction code.
Boolean, default true. If set to 0, will add this code to the generated script:
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
This can be used if the Riap function URL is https and you don't want to verify.
String. For creating a CLI script with subcommands. Value is a whitespace-separated entries of subcommand specification. Each subcommand specification must be in the form of SUBCOMMAND_NAME=URL[:SUMMARY]. Example:
delete=/My/App/delete_item add=/My/App/add_item refresh=/My/App/refresh_item:Refetch an item from source
String. Will be passed to Perinci::CmdLine::Gen backend (as script_summary).
script_summary
String, required. Riap URL. If the script does not contain subcommand, this should refer to a function URL. If the script contains subcommands, this should usually refer to a package URL.
Perinci::CmdLine::Inline-generated scripts currently cannot do shell completion on its own, but relies on a separate completer script (e.g. if the script is script/foo then the completer will be generated at script/_foo). This option can be used to suppress the generation of completer script.
script/foo
script/_foo
Load modules during build process.
Please visit the project's homepage at https://metacpan.org/release/Dist-Zilla-Plugin-GenPericmdScript.
Source repository is at https://github.com/perlancar/perl-Dist-Zilla-Plugin-GenPericmdScript.
Perinci::CmdLine, the kind of CLI script this plugin is generating.
Perinci and Rinci, for the background information.
Dist::Zilla::Plugin::Perinci::CmdLine, if you are building Perinci::CmdLine::* distribution.
Perinci::CmdLine::*
perlancar <perlancar@cpan.org>
Steven Haryanto <stevenharyanto@gmail.com>
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
This software is copyright (c) 2023, 2022, 2020, 2018, 2017, 2016, 2015, 2014 by perlancar <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.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-GenPericmdScript
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.
To install Dist::Zilla::Plugin::GenPericmdScript, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dist::Zilla::Plugin::GenPericmdScript
CPAN shell
perl -MCPAN -e shell install Dist::Zilla::Plugin::GenPericmdScript
For more information on module installation, please visit the detailed CPAN module installation guide.