#!perl

our $DATE = '2015-08-17'; # DATE
our $VERSION = '0.13'; # VERSION

use 5.010;
use strict;
use warnings;

use Perinci::CmdLine::Any;

Perinci::CmdLine::Any->new(
    url => '/App/GenPericmdScript/gen_perinci_cmdline_script',
    log => 1,
)->run;

# ABSTRACT: Generate Perinci::CmdLine CLI script
# PODNAME: gen-pericmd-script

__END__

=pod

=encoding UTF-8

=head1 NAME

gen-pericmd-script - Generate Perinci::CmdLine CLI script

=head1 VERSION

This document describes version 0.13 of gen-pericmd-script (from Perl distribution App-GenPericmdScript), released on 2015-08-17.

=head1 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 L<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

=head1 DESCRIPTION

=head1 OPTIONS

C<*> marks required options.

=head2 Configuration options

=over

=item B<--config-path>=I<filename>

{en_US Set path to configuration file}.

Can be specified multiple times.

=item B<--config-profile>=I<s>

{en_US Set configuration profile to use}.

=item B<--no-config>

{en_US Do not use any configuration file}.

=back

=head2 Environment options

=over

=item B<--no-env>

{en_US Do not read environment for default options}.

=back

=head2 Logging options

=over

=item B<--debug>

{en_US Set log level to debug}.

=item B<--log-level>=I<s>

{en_US Set log level}.

=item B<--quiet>

{en_US Set log level to quiet}.

=item B<--trace>

{en_US Set log level to trace}.

=item B<--verbose>

{en_US Set log level to info}.

=back

=head2 Output options

=over

=item B<--format>=I<s>

{en_US Choose output format, e.g. json, text}.

Default value:

 undef

=item B<--json>

{en_US Set output format to json}.

=item B<--naked-res>

{en_US When outputing as JSON, strip result envelope}.

Default value:

 0

{en_US 
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]
}


=item B<--output-file>=I<filename>, B<-o>

{en_US Path to output file}.

Default value:

 "-"

=item B<--overwrite>

{en_US Whether to overwrite output if previously exists}.

=back

=head2 Other options

=over

=item B<--cmdline>=I<modulename>

{en_US Specify module to use}.

Default value:

 "Perinci::CmdLine::Any"

=item B<--config-filename>=I<s>

{en_US Will be passed to Perinci::CmdLine constructor}.

=item B<--default-log-level>=I<s>

Valid values:

 ["trace","debug","info","warn","error","fatal","none"]

=item B<--exclude-package-functions-match>=I<s>

{en_US Exclude package functions matching this pattern}.

=item B<--extra-urls-for-version-json>=I<s>

{en_US Will be passed to Perinci::CmdLine constructor} (JSON-encoded).

See C<--extra-urls-for-version>.

=item B<--extra-urls-for-version>=I<s@>

{en_US Will be passed to Perinci::CmdLine constructor}.

Can be specified multiple times.

=item B<--help>, B<-h>, B<-?>

{en_US Display help message and exit}.

=item B<--include-package-functions-match>=I<s>

{en_US Only include package functions matching this pattern}.

=item B<--interpreter-path>=I<s>

{en_US What to put on shebang line}.

=item B<--load-module-json>=I<modulename>

{en_US Load extra modules} (JSON-encoded).

See C<--load-module>.

=item B<--load-module>=I<modulename>

{en_US Load extra modules}.

Can be specified multiple times.

=item B<--log>

{en_US Will be passed to Perinci::CmdLine constructor}.

=item B<--no-prefer-lite>

{en_US Prefer Perinci::CmdLine::Classic backend}.

=item B<--no-ssl-verify-hostname>

=item B<--script-name>=I<s>

=item B<--script-version>=I<s>

{en_US Use this for version number instead}.

=item B<--skip-format>

{en_US Assume that function returns raw text which needs no formatting}.

=item B<--snippet-before-instantiate-cmdline>=I<s>

=item B<--subcommand-json>=I<s>, B<-s>

{en_US Subcommand name followed by colon and function URL} (JSON-encoded).

See C<--subcommand>.

=item B<--subcommand>=I<s@>

{en_US Subcommand name followed by colon and function URL}.

{en_US 
Optionally, it can be additionally followed by a summary, so:

    NAME:URL[:SUMMARY]

Example (on CLI):

    --subcommand "delete:/My/App/delete_item:Delete an item"
}


Can be specified multiple times.

=item B<--subcommands-from-package-functions>

{en_US Form subcommands from functions under package's URL}.

{en_US 
This is an alternative to the `subcommand` 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
}


=item B<--url>=I<riap_url>*

{en_US URL to function (or package, if you have subcommands)}.

=item B<--version>, B<-v>

{en_US Display program's version and exit}.

=back

=head1 SEE ALSO

L<Perinci::CmdLine::Manual>

L<Dist::Zilla::Plugin::Rinci::ScriptFromFunc>

=head1 COMPLETION

This script has shell tab completion capability with support for several
shells.

=head2 bash

To activate bash completion for this script, put:

 complete -C gen-pericmd-script gen-pericmd-script

in your bash startup (e.g. C<~/.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 L<shcompgen> which allows you to
activate completion scripts for several kinds of scripts on multiple shells.
Some CPAN distributions (those that are built with
L<Dist::Zilla::Plugin::GenShellCompletion>) will even automatically enable shell
completion for their included scripts (using C<shcompgen>) at installation time,
so you can immadiately have tab completion.

=head2 tcsh

To activate tcsh completion for this script, put:

 complete gen-pericmd-script 'p/*/`gen-pericmd-script`/'

in your tcsh startup (e.g. C<~/.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 C<shcompgen> (see above).

=head2 other shells

For fish and zsh, install C<shcompgen> as described above.

=head1 ENVIRONMENT

=head2 GEN_PERICMD_SCRIPT_OPT => str

Specify additional command-line options

=head1 CONFIGURATION FILE

This script can read configuration file, which by default is searched at C<~/.config/gen-pericmd-script.conf>, C<~/gen-pericmd-script.conf> or C</etc/gen-pericmd-script.conf> (can be changed by specifying C<--config-path>). All found files will be read and merged.

To disable searching for configuration files, pass C<--no-config>.

Configuration file is in the format of L<IOD>, which is basically INI with some extra features. 

You can put multiple profiles in a single file by using section names like C<[profile=SOMENAME]>. Those sections will only be read if you specify the matching C<--config-profile SOMENAME>.

List of available configuration parameters:

 cmdline (see --cmdline)
 config_filename (see --config-filename)
 default_log_level (see --default-log-level)
 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)
 prefer_lite (see --no-prefer-lite)
 script_name (see --script-name)
 script_version (see --script-version)
 skip_format (see --skip-format)
 snippet_before_instantiate_cmdline (see --snippet-before-instantiate-cmdline)
 ssl_verify_hostname (see --no-ssl-verify-hostname)
 subcommand (see --subcommand)
 subcommands_from_package_functions (see --subcommands-from-package-functions)
 url (see --url)

=head1 FILES

~/.config/gen-pericmd-script.conf

~/gen-pericmd-script.conf

/etc/gen-pericmd-script.conf

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-GenPericmdScript>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-GenPericmdScript>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<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.

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

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

=cut
