NAME
peri-eg-demo-cli-opts-lite - Summary for `demo_cli_opts`
VERSION
This document describes version 0.062 of peri-eg-demo-cli-opts-lite (from Perl distribution Perinci-Examples-Bin-Lite), released on 2020-04-29.
SYNOPSIS
Usage:
% peri-eg-demo-cli-opts-lite [-F] [-M] [--are-baz] [--arent-baz] [--bool1]
[--config-path=path | -c] [--config-profile=profile | -P] [-f]
[--female] [--flag1] [--format=name] [--full] [--full2] [--gender=s]
[--hash1-json=s] [--hash1=s] [-i=s] [--input-base64=s] [--input=s]
[--int1=s] [--int2=s] [--is-bar] [--isnt-bar] [--json] [--male]
[--(no)naked-res] [--no-bool1] [--no-config | -C] [--no-env]
[--no-full] [--no-full2] [--nobool1] [--nofull] [--nofull2]
[--output=s] [-p=s] [--page-result[=program]] [--pass=s] [--wf]
[--with-foo] [--without-foo] [-z] <str1> <array1> ...
Examples:
Summary for an example:
% peri-eg-demo-cli-opts-lite --int1 10 'a value' elem1 elem2
[
200,
"OK",
{
"array1" : [
"elem1",
"elem2"
],
"full" : 1,
"full2" : 1,
"hash1" : {
"default" : 1
},
"int1" : 10,
"int2" : 10,
"str1" : "a value"
},
{}
]
A second example:
% peri-eg-demo-cli-opts-lite --int1 20 --str1 x --array1-json '[1,2]'
ERROR 400: Can't parse argv (500: GetOptions failed)
DESCRIPTION
Description for demo_cli_opts
.
This is another paragraph from the description. Description by default is assumed to be marked up in Markdown (currently referring to CommonMark).
This paragraph should be set in verbatim.
OPTIONS
*
marks required options.
Main options
- --array1-json=s
-
Positional, slurpy, and plural (JSON-encoded).
See
--array1
. - --array1=s@*
-
Positional, slurpy, and singular.
Argument with non-scalar types (like array or hash) can be specified in the CLI using `--ARG-json` or `--ARG-yaml`. Arguments with type of array of string can also be specified using multiple `--ARG` options.
This option also links to another option.
Can be specified multiple times.
- --female
-
Alias for `--gender=F`.
See
--gender
. - --gender=s
-
A string option.
Valid values:
["M","F"]
This option contains flag aliases that have code.
- --hash1-json=s
-
Demonstrate hash argument with default value from schema (JSON-encoded).
See
--hash1
. - --hash1=s
-
Demonstrate hash argument with default value from schema.
Default value:
{default=>1}
- --input-base64=s
-
Specify input (base64-encoded).
See
--input
. - --input=s
-
Specify input.
This option demonstrates the `cmdline_src` property. Also, since schema type is `buf`, we know that the value is binary data. CLI framework will provide `--input-base64` to allow specifying binary data encoded in base64.
- --int1=s*, -i
-
Demonstrate an option with no summary. And a required option.
- --int2=s
-
Another int option.
Default value:
10
Demonstrate a scalar/simple default value.
- --male
-
Alias for `--gender=M`.
See
--gender
. - --output=s
-
Specify output filename.
This option demonstrates how the option would be displayed in the help/usage. Due to the `schema` being `filename` instead of just `str`, CLI framework can show:
--output=filename
instead of the less informative:
--output=str
- --pass=s, -p
- --str1=s*
-
A required option as well as positional argument.
- -F
-
Alias for `--female`.
See
--gender
. - -M
-
Alias for `--male`.
See
--gender
.
Cat1 options
- --bool1
-
A bool option.
CLI framework should generate `--nobool1` (and `--nobool1`) automatically.
This option has an alias, `-z`. Because the alias has its own summary/description, it will be displayed separately.
- --flag1, -f
-
A flag option.
A flag option is a bool option with the value of 1 (true). It is meant to activate something if specified and there is no notion of disabling by specifying the opposite. Thus the CLI framework should not generate a `--noflag1` option.
This flag has an alias `-f` with no summary/description nor code. So the CLI framework should display the alias along with the option. Note that short (single-letter) options/aliases do not get `--noX`.
- --no-full
-
Turn off full processing.
Another bool option with on default.
CLI framework should perhaps show `--nobool2` instead of `--bool2` because `--bool2` is active by default. And if it does so, it should also show the negative summary in the `summary.alt.bool.not` attribute instead of the normal `summary` property.
- -z
-
This is summary for option `-z`.
See
--bool1
.
Cat2 options
- --no-full2
-
Another bool option with on default. Because this option does not have `summary.alt.bool.not`, CLI framework should not show any summary, despite the existence of `summary`.
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
Negation options
- --are-baz
-
This demonstrate negation of --are-foo to --arent-foo.
- --is-bar
-
This demonstrate negation of --is-foo to --isnt-foo.
- --with-foo, --wf
-
This demonstrate negation of --with-foo to --without-foo.
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]
- --page-result
-
Filter output through a pager.
Other options
COMPLETION
This script has shell tab completion capability with support for several shells.
bash
To activate bash completion for this script, put:
complete -C peri-eg-demo-cli-opts-lite peri-eg-demo-cli-opts-lite
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 peri-eg-demo-cli-opts-lite 'p/*/`peri-eg-demo-cli-opts-lite`/'
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/peri-eg-demo-cli-opts-lite.conf, ~/peri-eg-demo-cli-opts-lite.conf, or /etc/peri-eg-demo-cli-opts-lite.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:
are_baz (see --are-baz)
array1 (see --array1)
bool1 (see --bool1)
flag1 (see --flag1)
format (see --format)
full (see --no-full)
full2 (see --no-full2)
gender (see --gender)
hash1 (see --hash1)
input (see --input)
int1 (see --int1)
int2 (see --int2)
is_bar (see --is-bar)
naked_res (see --naked-res)
output (see --output)
pass (see --pass)
str1 (see --str1)
with_foo (see --with-foo)
ENVIRONMENT
PERI_EG_DEMO_CLI_OPTS_LITE_OPT => str
Specify additional command-line options.
FILES
~/.config/peri-eg-demo-cli-opts-lite.conf
~/peri-eg-demo-cli-opts-lite.conf
/etc/peri-eg-demo-cli-opts-lite.conf
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Perinci-Examples-Bin-Lite.
SOURCE
Source repository is at https://github.com/perlancar/perl-Perinci-Examples-Bin-Lite.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Examples-Bin-Lite
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.
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2020, 2018, 2015, 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.