The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

peri-eg-demo-cli-opts-any - Summary for `demo_cli_opts`

VERSION

This document describes version 0.072 of peri-eg-demo-cli-opts-any (from Perl distribution Perinci-Examples-Bin-Any), released on 2022-03-08.

SYNOPSIS

Usage:

% peri-eg-demo-cli-opts-any [--are-baz|--arent-baz] [--bool1|-z|--no-bool1|--nobool1] [--config-path=path|-c|--no-config|-C] [--config-profile=profile|-P] [--flag1|-f] [--format=name|--json] [--full|--no-full|--nofull] [--full2|--no-full2|--nofull2] [--gender=str] [--hash1=s] [--input-base64=buf] [--input=buf] [--int1=int] [--int2=int] [--is-bar|--isnt-bar] [--(no)naked-res] [--no-env] [--output=filename] [--page-result[=program]|--view-result[=program]] [--pass=str] [--with-foo|--wf|--without-foo] [--hash1-json=json] [-F|-M|--female|--male] [-i=int] [-p=str] -- <str1> <array1> ...

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.

Can also be specified as the 2nd command-line argument and onwards.

--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 also be specified as the 2nd command-line argument and onwards.

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.

Can also be specified as the 1st command-line 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

--no-env

Do not read environment for default 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.

--view-result

View output using a viewer.

Other options

--help, -h, -?

Display help message and exit.

--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 peri-eg-demo-cli-opts-any peri-eg-demo-cli-opts-any

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-any 'p/*/`peri-eg-demo-cli-opts-any`/'

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): /home/u1/.config/peri-eg-demo-cli-opts-any.conf, /home/u1/peri-eg-demo-cli-opts-any.conf, or /etc/peri-eg-demo-cli-opts-any.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.

You can also 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 equals some string: [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 some string: [env=HOSTNAME!=blink ...] or [SOMESECTION env=HOSTNAME!=blink ...]. If you only want a section to be read when the value of an environment variable includes some string: [env=HOSTNAME*=server ...] or [SOMESECTION env=HOSTNAME*=server ...]. If you only want a section to be read when the value of an environment variable does not include some string: [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.

To load and configure plugins, you can use either the -plugins parameter (e.g. -plugins=DumpArgs or -plugins=DumpArgs@before_validate_args), or use the [plugin=NAME ...] sections, for example:

 [plugin=DumpArgs]
 -event=before_validate_args
 -prio=99
 
 [plugin=Foo]
 -event=after_validate_args
 arg1=val1
 arg2=val2

 

which is equivalent to setting -plugins=-DumpArgs@before_validate_args@99,-Foo@after_validate_args,arg1,val1,arg2,val2.

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_ANY_OPT => str

Specify additional command-line options.

FILES

/home/u1/.config/peri-eg-demo-cli-opts-any.conf

/home/u1/peri-eg-demo-cli-opts-any.conf

/etc/peri-eg-demo-cli-opts-any.conf

EXAMPLES

Summary for an example:

 % peri-eg-demo-cli-opts-any --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-any --int1 20 --str1 x --array1-json '[1,2]'
 ERROR 400: Can't parse argv (500: GetOptions failed)

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Perinci-Examples-Bin-Any.

SOURCE

Source repository is at https://github.com/perlancar/perl-Perinci-Examples-Bin-Any.

AUTHOR

perlancar <perlancar@cpan.org>

CONTRIBUTING

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, and sometimes one or two other Dist::Zilla plugin and/or Pod::Weaver::Plugin. Any additional steps required beyond that are considered a bug and can be reported to me.

COPYRIGHT AND LICENSE

This software is copyright (c) 2022, 2020, 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.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Examples-Bin-Any

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.