gen-pericmd-script - Generate Perinci::CmdLine CLI script
This document describes version 0.230 of gen-pericmd-script (from Perl distribution App-GenPericmdScript), released on 2020-04-30.
Create a Perinci::CmdLine script:
% gen-pericmd-script /App/MyApp/myfunc > mycli
Some more options (turn on debugging, output to file, overwrite existing output, will automatically chmod +x the file and run shcompgen if it's available on the system and output dir is in PATH, pick Perinci::CmdLine::Any backend):
% gen-pericmd-script --debug \ -o /path/to/mycli --overwrite \ --cmdline Perinci::CmdLine::Classic \ /App/MyApp/myfunc
With subcommands:
% gen-pericmd-script /App/MyApp/ \ -s update:/App/MyApp/update -s delete:/App/MyApp/delete \ > mycli
* marks required options.
*
Will be passed to Perinci::CmdLine constructor.
Shortcut for --cmdline=classic.
See --cmdline.
--cmdline
Specify module to use.
Default value:
"Perinci::CmdLine::Any"
Can be specified multiple times.
Will be passed to Perinci::CmdLine constructor (JSON-encoded).
See --config-dir.
--config-dir
See --config-filename.
--config-filename
Whether to set default_dry_run, will be passed to Perinci::CmdLine constructor.
Set default format.
Valid values:
["trace","debug","info","warn","error","fatal","none"]
Exclude package functions matching this pattern.
See --extra-urls-for-version.
--extra-urls-for-version
Only include package functions matching this pattern.
Shortcut for --cmdline=inline.
What to put on shebang line.
Shortcut for --cmdline=lite.
Load extra modules (JSON-encoded).
See --load-module.
--load-module
Load extra modules.
Currently only Perinci::CmdLine::Inline generates POD.
Prefer Perinci::CmdLine::Classic backend.
Currently irrelevant when generating with Perinci::CmdLine::Inline.
Use this for version number instead.
Assume that function returns raw text which needs no formatting.
Hash of subcommand entries, where each entry is "url[:summary]".
An optional summary can follow the URL, e.g.:
URL[:SUMMARY]
Example (on CLI):
--subcommand add=/My/App/add_item --subcommand bin='/My/App/bin_item:Delete an item'
Each value is a name-value pair, use key=value syntax. Can be specified multiple times.
Form subcommands from functions under package's URL.
This is an alternative to the `subcommands` 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
Hash of subcommand entries, where each entry is "url[:summary]" (JSON-encoded).
See --subcommand.
--subcommand
URL to function (or package, if you have subcommands) (JSON-encoded).
See --url.
--url
URL to function (or package, if you have subcommands).
Whether to use data cleansing before outputting to JSON.
Whether to set utf8 flag on output, will be passed to Perinci::CmdLine constructor.
Set path to configuration file.
Set configuration profile to use.
Do not use any configuration file.
Do not read environment for default options.
Shortcut for --log-level=debug.
Set log level.
Shortcut for --log-level=error.
Shortcut for --log-level=trace.
Shortcut for --log-level=info.
Choose output format, e.g. json, text.
undef
Set output format to json.
When outputing as JSON, strip result envelope.
0
By default, when outputing as JSON, the full enveloped result is returned, e.g.:
[200,"OK",[1,2,3],{"func.extra"=>4}]
The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use `--naked-res` so you just get:
[1,2,3]
Path to output file.
"-"
Whether to overwrite output if previously exists.
Filter output through a pager.
Allow script to depend on these modules (JSON-encoded).
See --allow-prereq.
--allow-prereq
Allow script to depend on these modules.
Sometimes, as in the case of using `Perinci::CmdLine::Inline`, dependency to some modules (e.g. non-core XS modules) are prohibited because the goal is to have a free-standing script. This option allows whitelisting some extra modules.
If you use `Perinci::CmdLine::Inline`, this option will be passed to it.
Display help message and exit.
Whether to pack dependencies in Perinci::CmdLine::Inline script.
Will be passed to <pm:Perinci::CmdLine>'s `gen_inline_pericmd_script`'s `pack_deps` option.
Display program's version and exit.
This script has shell tab completion capability with support for several shells.
To activate bash completion for this script, put:
complete -C gen-pericmd-script gen-pericmd-script
in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is recommended, however, that you install modules using cpanm-shcompgen which can activate shell completion for scripts immediately.
To activate tcsh completion for this script, put:
complete gen-pericmd-script 'p/*/`gen-pericmd-script`/'
in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is also recommended to install shcompgen (see above).
For fish and zsh, install shcompgen as described above.
This script can read configuration files. Configuration files are in the format of IOD, which is basically INI with some extra features.
By default, these names are searched for configuration filenames (can be changed using --config-path): ~/.config/gen-pericmd-script.conf, ~/gen-pericmd-script.conf, or /etc/gen-pericmd-script.conf.
--config-path
All found files will be read and merged.
To disable searching for configuration files, pass --no-config.
--no-config
You can put multiple profiles in a single file by using section names like [profile=SOMENAME] or [SOMESECTION profile=SOMENAME]. Those sections will only be read if you specify the matching --config-profile SOMENAME.
[profile=SOMENAME]
[SOMESECTION profile=SOMENAME]
--config-profile SOMENAME
You can also put configuration for multiple programs inside a single file, and use filter program=NAME in section names, e.g. [program=NAME ...] or [SOMESECTION program=NAME]. The section will then only be used when the reading program matches.
program=NAME
[program=NAME ...]
[SOMESECTION program=NAME]
Finally, you can filter a section by environment variable using the filter env=CONDITION in section names. For example if you only want a section to be read if a certain environment variable is true: [env=SOMEVAR ...] or [SOMESECTION env=SOMEVAR ...]. If you only want a section to be read when the value of an environment variable has value equals something: [env=HOSTNAME=blink ...] or [SOMESECTION env=HOSTNAME=blink ...]. If you only want a section to be read when the value of an environment variable does not equal something: [env=HOSTNAME!=blink ...] or [SOMESECTION env=HOSTNAME!=blink ...]. If you only want a section to be read when an environment variable contains something: [env=HOSTNAME*=server ...] or [SOMESECTION env=HOSTNAME*=server ...]. Note that currently due to simplistic parsing, there must not be any whitespace in the value being compared because it marks the beginning of a new section filter or section name.
env=CONDITION
[env=SOMEVAR ...]
[SOMESECTION env=SOMEVAR ...]
[env=HOSTNAME=blink ...]
[SOMESECTION env=HOSTNAME=blink ...]
[env=HOSTNAME!=blink ...]
[SOMESECTION env=HOSTNAME!=blink ...]
[env=HOSTNAME*=server ...]
[SOMESECTION env=HOSTNAME*=server ...]
List of available configuration parameters:
allow_prereq (see --allow-prereq) allow_unknown_opts (see --allow-unknown-opts) cmdline (see --cmdline) code_after_end (see --code-after-end) code_before_instantiate_cmdline (see --code-before-instantiate-cmdline) config_dirs (see --config-dir) config_filename (see --config-filename) copt_help_enable (see --no-copt-help-enable) copt_help_getopt (see --copt-help-getopt) copt_version_enable (see --no-copt-version-enable) copt_version_getopt (see --copt-version-getopt) default_dry_run (see --default-dry-run) default_format (see --default-format) default_log_level (see --default-log-level) default_subcommand (see --default-subcommand) env_name (see --env-name) exclude_package_functions_match (see --exclude-package-functions-match) extra_urls_for_version (see --extra-urls-for-version) format (see --format) include_package_functions_match (see --include-package-functions-match) interpreter_path (see --interpreter-path) load_module (see --load-module) log (see --log) log_level (see --log-level) naked_res (see --naked-res) output_file (see --output-file) overwrite (see --overwrite) pack_deps (see --pack-deps) pass_cmdline_object (see --pass-cmdline-object) per_arg_json (see --per-arg-json) per_arg_yaml (see --per-arg-yaml) pod (see --no-pod) prefer_lite (see --no-prefer-lite) read_config (see --read-config) read_env (see --read-env) script_name (see --script-name) script_summary (see --script-summary) script_version (see --script-version) skip_format (see --skip-format) ssl_verify_hostname (see --no-ssl-verify-hostname) subcommands (see --subcommand) subcommands_from_package_functions (see --subcommands-from-package-functions) url (see --url) use_cleanser (see --use-cleanser) use_utf8 (see --use-utf8) validate_args (see --validate-args)
Specify additional command-line options.
~/.config/gen-pericmd-script.conf
~/gen-pericmd-script.conf
/etc/gen-pericmd-script.conf
Please visit the project's homepage at https://metacpan.org/release/App-GenPericmdScript.
Source repository is at https://github.com/perlancar/perl-App-GenPericmdScript.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-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.
Perinci::CmdLine::Manual
Dist::Zilla::Plugin::GenPericmdScript
perlancar <perlancar@cpan.org>
This software is copyright (c) 2020, 2015 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 App::GenPericmdScript, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::GenPericmdScript
CPAN shell
perl -MCPAN -e shell install App::GenPericmdScript
For more information on module installation, please visit the detailed CPAN module installation guide.