.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Perinci::CmdLine::Manual::FAQ 3pm" .TH Perinci::CmdLine::Manual::FAQ 3pm "2018-04-01" "perl v5.26.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Perinci::CmdLine::Manual::FAQ \- FAQs .SH "VERSION" .IX Header "VERSION" This document describes version 1.811.0 of Perinci::CmdLine::Manual::FAQ (from Perl distribution Perinci-CmdLine), released on 2018\-03\-17. .SH "NOMENCLATURE" .IX Header "NOMENCLATURE" \&\f(CW\*(C`[PC::Classic]\*(C'\fR denotes that the answer applies to Perinci::CmdLine::Classic only and not Perinci::CmdLine::Lite. \f(CW\*(C`[PC::Lite]\*(C'\fR denotes that the answer is specific to Perinci::CmdLine::Lite. \f(CW\*(C`[PC::Any]\*(C'\fR denotes that the answer is specific to Perinci::CmdLine::Any. .SH "GENERAL" .IX Header "GENERAL" .SS "Why are there multiple frameworks/flavors for Perinci::CmdLine?" .IX Subsection "Why are there multiple frameworks/flavors for Perinci::CmdLine?" There are currently 3 (three) flavors of the framework: Perinci::CmdLine::Classic, Perinci::CmdLine::Lite, and Perinci::CmdLine::Inline. Which one you should use depends on your needs, because sadly, there is no one-size-fits-all. .PP \&\fBPerinci::CmdLine::Classic.\fR Perinci::CmdLine::Classic (hereby called PC:Classic) is the first flavor which I developed (and it used to be called just Perinci::CmdLine). It has the most complete features as well as the prettiest output, but as it grows in features, other things like startup overhead and dependencies also grow. .PP \&\fBPerinci::CmdLine::Lite.\fR So another project is started, Perinci::CmdLine::Lite (hereby called PC::Lite) that focuses on keeping startup overhead low to avoid making tab completion delay noticeable. PC:Lite aims to make \s-1CLI\s0 scripts typically start below 0.05s, while PC:Classic\-based scripts currently start in about 0.2\-0.5s which causes a noticeable delay when doing tab completion. PC:Lite also tries to reduce the number of dependencies (from 100+ down to 30+ or so). Some PC:Classic features are still missing in PC:Lite (see next question). .PP PC:Lite stays more lightweight by avoiding the use of libraries that have large dependencies or add too much to startup overhead. This includes replacing Perinci::Access with Perinci::Access::Lite for metadata access and avoiding Text::ANSITable for formatting results. .PP Implementation-wise, the two share a lot of common code in the form of their base class, Perinci::CmdLine::Base. The interface is also 99% the same. .PP It is possible that in the future the two versions will merge. .PP \&\fBPerinci::CmdLine::Inline.\fR There is another flavor called PC:Inline. The goal of this flavor is to make your \s-1CLI\s0 scripts depend on nothing but Perl and the core modules. (It is also possible to make PC:Classic\- or PC:Lite\-based \s-1CLI\s0 script to also be freestanding by techniques like fatpacking or datapacking, but the resulting packed script will be much larger.) It has the lowest number of dependencies and the fastest startup overhead (around 0.01s). But currently it also has the least features. .PP It reduces startup overhead further by skipping the Riap layer and prefetching the Rinci metadata, precomputing the command-line options, and embedding all these in the scripts. .PP See Perinci::CmdLine::Inline for more details of the features it currently supports. This flavor is suitable for simple \s-1CLI\s0 scripts that need to be as lean and fast as possible, for example: hr (in App::hr) or gen-uuids (in App::UuidUtils). .PP All the flavors share the basic concept: running your Rinci\-described functions on the command-line. .PP So which one should you choose? PC:Lite is the sane default choice, unless you need features that are currently not supported by PC:Lite, in which case you can consider using PC:Classic. If you really need fast startup, you can opt for PC:Inline. But note that when the backend function's Rinci metadata changes, you will need to rebuild the script because the metadata is embedded in the script (while in PC:Lite and PC:Classic, the script simply request the Rinci metadata during runtime). .SS "What Classic features are currently still missing in Lite?" .IX Subsection "What Classic features are currently still missing in Lite?" .IP "\(bu" 4 More sophisticated formatting .Sp Instead of Perinci::Result::Format (especially for 'text*' formats which use Data::Format::Pretty::Console and Text::ANSITable), to keep dependencies minimal and formatting quick, PC::Lite uses the following simple rules that work for a significant portion of common data structures: .Sp 1) if result is undef, print nothing. .Sp 2) if result is scalar, print it (with newline automatically added). .Sp 3) if result is an array of scalars (check at most 5 first rows), print it one line for each element. .Sp 4) if result is a hash of scalars (check at most 5 keys), print a two column table, first column is key and second column is value. Keys will be sorted. .Sp 5) if result is an array of hashes of scalars (check at most 5 elements), print as table. .Sp 6) if result is an array of arrays of scalars (check at most 5 elements), print as table. .Sp 7) otherwise print as \s-1JSON\s0 (after cleaning it with Data::Clean::JSON). .Sp \&\s-1YAML\s0 and the other formats are not supported. .Sp Table is printed using the more lightweight and much faster Text::Table::Tiny. .Sp PC::Classic supports more sophisticated formatting, can keep colored and full-width Unicode characters stay aligned in a table. .IP "\(bu" 4 Support for extra protocols .Sp Instead of Perinci::Access, PC::Lite uses the more lightweight alternative Perinci::Access::Lite which does not support some \s-1URL\s0 schemes (riap+tcp, riap+unix, riap+pipe). http/https and local are supported though. .IP "\(bu" 4 Extra stuffs that Perinci::Sub::Wrapper adds .Sp PC::Classic uses function wrapper to automatically adds argument validation, dependency checking, and so on. However, this adds too much overhead so PC:Lite avoids it and do some of the stuffs by itself to avoid the overhead. .Sp PC:Lite does argument validation, as well as dependency checking. But there are other stuffs that Perinci::Sub::Wrapper adds that are not available, including: result validation, validation of input stream (streaming argument) as well as output stream (streaming result). .IP "\(bu" 4 Color themes .IP "\(bu" 4 Undo .IP "\(bu" 4 I18N .IP "\(bu" 4 The following environment variables .Sp .Vb 4 \& PERINCI_CMDLINE_COLOR_THEME \& PERINCI_CMDLINE_SERVER \& COLOR \& UTF8 .Ve .SS "What is Perinci::CmdLine::Any then?" .IX Subsection "What is Perinci::CmdLine::Any then?" This is a module that allows you to select PC::Classic or PC::Lite. So your scripts do not need to be modified when user wants to switch between the two. .SS "How does Perinci::CmdLine compare with other CLI-app frameworks?" .IX Subsection "How does Perinci::CmdLine compare with other CLI-app frameworks?" The main difference is that Perinci::CmdLine accesses your code through Riap protocol, not directly. This means that aside from local Perl code, Perinci::CmdLine can also provide \s-1CLI\s0 for code in remote hosts/languages. For a very rough demo, download and run this \s-1PHP\s0 Riap::TCP server https://github.com/sharyanto/php\-Phinci/blob/master/demo/phi\-tcpserve\-terbilang.php on your system. After that, try running: .PP .Vb 2 \& % peri\-run riap+tcp://localhost:9090/terbilang \-\-help \& % peri\-run riap+tcp://localhost:9090/terbilang 1234 .Ve .PP Everything from help message, calling, argument checking, tab completion works for remote code as well as local Perl code. .SS "But my application is \s-1OO\s0? But I want an \s-1OO\s0 framework?" .IX Subsection "But my application is OO? But I want an OO framework?" This framework is currently function-centric. There are already several OO-based command-line frameworks on \s-1CPAN.\s0 .SH "GENERATING DOCUMENTATION" .IX Header "GENERATING DOCUMENTATION" .SS "How do I add examples using Rinci metadata?" .IX Subsection "How do I add examples using Rinci metadata?" In your Rinci function metadata, add the \f(CW\*(C`examples\*(C'\fR property, e.g.: .PP .Vb 10 \& # myapp script \& use Perinci::CmdLine::Any; \& our %SPEC; \& $SPEC{myadd} = { \& v => 1.1, \& args => { \& num1 => {summary=>\*(AqFirst number\*(Aq , schema=\*(Aqfloat*\*(Aq, req=>1, pos=>0}, \& num2 => {summary=>\*(AqSecond number\*(Aq, schema=\*(Aqfloat*\*(Aq, req=>1, pos=>1}, \& round => { \& summary=>\*(AqRound to nearest integer\*(Aq, \& schema =>\*(Aqbool*\*(Aq, \& cmdline_aliases=>{r=>{}}, \& }, \& }, \& examples => [ \& { \& summary => \*(AqAdd two integers\*(Aq, \& args => {num1=>7, num2=>5}, \& }, \& { \& summary => \*(AqAdd two floats, round to nearest integer\*(Aq, \& args => {num1=>7.1, num2=>5.5, round=>1}, \& result => 13, \& }, \& ], \& } \& sub myadd { ... } \& Perinci::CmdLine::Any\->new(url => \*(Aq/main/myadd\*(Aq)\->run; .Ve .PP If you run \f(CW\*(C`myapp \-\-help\*(C'\fR, you'll see the examples shown as: .PP .Vb 3 \& Examples: \& Add two integers: \& % myadd 7 5 \& \& Add two floats, round to the nearest integer: \& % myadd 7.1 5.5 \-\-round .Ve .PP If you use Dist::Zilla and Pod::Weaver and Pod::Weaver::Plugin::Rinci to generate your \s-1POD,\s0 you'll also have the Synopsis section filled with the above. .SH "DEBUGGING" .IX Header "DEBUGGING" .SS "How do I enable/view log messages?" .IX Subsection "How do I enable/view log messages?" The framework produces log messages using Log::ger. You can display them on the screen, e.g. using Log::ger::App like: .PP .Vb 1 \& % TRACE=1 perl \-MLog::ger::App /path/to/yourscript.pl .Ve .PP or: .PP .Vb 1 \& % TRACE=1 PERL5OPT=\-MLog::ger::App yourscript.pl .Ve .SS "How do I debug my \s-1CLI\s0 script?" .IX Subsection "How do I debug my CLI script?" To see stack trace on error, you can use Devel::Confess. Perinci::CmdLine::Base detects if Devel::Confess is loaded and will return the stack trace for you: .PP .Vb 1 \& % perl \-d:Confess /path/to/yourscript.pl .Ve .PP or: .PP .Vb 1 \& % PERL5OPT=\*(Aq\-d:Confess\*(Aq yourscript.pl .Ve .SH "PROGRESS INDICATOR" .IX Header "PROGRESS INDICATOR" .SS "How do I show progress indicator?" .IX Subsection "How do I show progress indicator?" Perinci::CmdLine can work together with the Progress::Any framework. Either you setup progress output module manually: .PP .Vb 3 \& use Perinci::CmdLine::Any; \& use Progress::Any \*(Aq$progress\*(Aq; \& use Progress::Any::Output \*(AqTermProgressBarColor\*(Aq; \& \& $SPEC{app} = { \& v => 1.1, \& ... \& }; \& sub app { \& $progress\->target(5); \& for (1..5) { \& $progress\->update(message => "Item $_"); \& sleep 1; \& } \& [200]; \& } \& \& Perinci::CmdLine::Any\->new(url => "/main/app")\->run; .Ve .PP or you can set \f(CW\*(C`progress\*(C'\fR feature in your function metadata, in which case Perinci::CmdLine::Lite will setup Progress::Any::Output::TermProgressBarColor for you automatically: .PP .Vb 2 \& use Perinci::CmdLine::Any; \& use Progress::Any \*(Aq$progress\*(Aq; \& \& $SPEC{app} = { \& v => 1.1, \& ... \& features => { progress=>1 }, \& }; \& sub app { \& $progress\->target(5); \& for (1..5) { \& $progress\->update(message => "Item $_"); \& sleep 1; \& } \& [200]; \& } \& \& Perinci::CmdLine::Any\->new(url => "/main/app")\->run; .Ve .PP The former way gives you flexibility to choose/customize your progress output module. .SH "HOMEPAGE" .IX Header "HOMEPAGE" Please visit the project's homepage at . .SH "SOURCE" .IX Header "SOURCE" Source repository is at . .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests on the bugtracker website .PP 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. .SH "SEE ALSO" .IX Header "SEE ALSO" Perinci::CmdLine::Manual .PP For the Generating Documentation section: Rinci::function, Rinci::FAQ (the Documentation section) .SH "AUTHOR" .IX Header "AUTHOR" perlancar .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2018, 2017, 2016, 2015 by perlancar@cpan.org. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.