NAME
gen-pericmd-script - Generate Perinci::CmdLine CLI script
VERSION
This document describes version 0.230 of gen-pericmd-script (from Perl distribution App-GenPericmdScript), released on 2020-04-30.
SYNOPSIS
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
DESCRIPTION
OPTIONS
*
marks required options.
Main options
- --allow-unknown-opts
-
Will be passed to Perinci::CmdLine constructor.
- --classic
-
Shortcut for --cmdline=classic.
See
--cmdline
. - --cmdline=s
-
Specify module to use.
Default value:
"Perinci::CmdLine::Any"
- --code-after-end=s
- --code-before-instantiate-cmdline=s
- --config-dir=s@
-
Will be passed to Perinci::CmdLine constructor.
Can be specified multiple times.
- --config-dirs-json=s
-
Will be passed to Perinci::CmdLine constructor (JSON-encoded).
See
--config-dir
. - --config-filename-json=s
-
Will be passed to Perinci::CmdLine constructor (JSON-encoded).
See
--config-filename
. - --config-filename=s
-
Will be passed to Perinci::CmdLine constructor.
- --copt-help-getopt=s
- --copt-version-getopt=s
- --default-dry-run
-
Whether to set default_dry_run, will be passed to Perinci::CmdLine constructor.
- --default-format=s
-
Set default format.
- --default-log-level=s
-
Valid values:
["trace","debug","info","warn","error","fatal","none"]
- --default-subcommand=s
-
Will be passed to Perinci::CmdLine constructor.
- --env-name=s
-
Will be passed to Perinci::CmdLine constructor.
- --exclude-package-functions-match=s
-
Exclude package functions matching this pattern.
- --extra-urls-for-version-json=s
-
Will be passed to Perinci::CmdLine constructor (JSON-encoded).
See
--extra-urls-for-version
. - --extra-urls-for-version=s@
-
Will be passed to Perinci::CmdLine constructor.
Can be specified multiple times.
- --include-package-functions-match=s
-
Only include package functions matching this pattern.
- --inline
-
Shortcut for --cmdline=inline.
See
--cmdline
. - --interpreter-path=s
-
What to put on shebang line.
- --lite
-
Shortcut for --cmdline=lite.
See
--cmdline
. - --load-module-json=s
-
Load extra modules (JSON-encoded).
See
--load-module
. - --load-module=s@
-
Load extra modules.
Can be specified multiple times.
- --log
-
Will be passed to Perinci::CmdLine constructor.
- --no-copt-help-enable
- --no-copt-version-enable
- --no-pod
-
Currently only Perinci::CmdLine::Inline generates POD.
- --no-prefer-lite
-
Prefer Perinci::CmdLine::Classic backend.
- --no-ssl-verify-hostname
- --pass-cmdline-object
-
Will be passed to Perinci::CmdLine constructor.
Currently irrelevant when generating with Perinci::CmdLine::Inline.
- --per-arg-json
-
Will be passed to Perinci::CmdLine constructor.
- --per-arg-yaml
-
Will be passed to Perinci::CmdLine constructor.
- --read-config
-
Will be passed to Perinci::CmdLine constructor.
- --read-env
-
Will be passed to Perinci::CmdLine constructor.
- --script-name=s
- --script-summary=s
- --script-version=s
-
Use this for version number instead.
- --skip-format
-
Assume that function returns raw text which needs no formatting.
- --subcommand=s%, -s
-
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.
- --subcommands-from-package-functions
-
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
- --subcommands-json=s
-
Hash of subcommand entries, where each entry is "url[:summary]" (JSON-encoded).
See
--subcommand
. - --url-json=s
-
URL to function (or package, if you have subcommands) (JSON-encoded).
See
--url
. - --url=s*
-
URL to function (or package, if you have subcommands).
- --use-cleanser
-
Whether to use data cleansing before outputting to JSON.
- --use-utf8
-
Whether to set utf8 flag on output, will be passed to Perinci::CmdLine constructor.
- --validate-args
-
Will be passed to Perinci::CmdLine constructor.
Configuration options
- --config-path=s, -c
-
Set path to configuration file.
- --config-profile=s, -P
-
Set configuration profile to use.
- --no-config, -C
-
Do not use any configuration file.
Environment options
Logging options
- --debug
-
Shortcut for --log-level=debug.
- --log-level=s
-
Set log level.
- --quiet
-
Shortcut for --log-level=error.
- --trace
-
Shortcut for --log-level=trace.
- --verbose
-
Shortcut for --log-level=info.
Output options
- --format=s
-
Choose output format, e.g. json, text.
Default value:
undef
- --json
-
Set output format to json.
- --naked-res
-
When outputing as JSON, strip result envelope.
Default value:
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]
- --output-file=s, -o
-
Path to output file.
Default value:
"-"
- --overwrite
-
Whether to overwrite output if previously exists.
- --page-result
-
Filter output through a pager.
Other options
- --allow-prereq-json=s
-
Allow script to depend on these modules (JSON-encoded).
See
--allow-prereq
. - --allow-prereq=s@
-
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.
Can be specified multiple times.
- --help, -h, -?
-
Display help message and exit.
- --pack-deps
-
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.
- --version, -v
-
Display program's version and exit.
COMPLETION
This script has shell tab completion capability with support for several shells.
bash
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.
tcsh
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).
other shells
For fish and zsh, install shcompgen as described above.
CONFIGURATION FILE
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.
All found files will be read and merged.
To disable searching for configuration files, pass --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
.
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.
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.
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)
ENVIRONMENT
GEN_PERICMD_SCRIPT_OPT => str
Specify additional command-line options.
FILES
~/.config/gen-pericmd-script.conf
~/gen-pericmd-script.conf
/etc/gen-pericmd-script.conf
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-GenPericmdScript.
SOURCE
Source repository is at https://github.com/perlancar/perl-App-GenPericmdScript.
BUGS
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.
SEE ALSO
Dist::Zilla::Plugin::GenPericmdScript
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
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.