App-SahUtils

 view release on metacpan or  search on metacpan

script/sah-to-human  view on Meta::CPAN

#!perl

use 5.010;
use strict;
use warnings;

use Perinci::CmdLine::Any;

our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2024-08-06'; # DATE
our $DIST = 'App-SahUtils'; # DIST
our $VERSION = '0.485'; # VERSION

our %SPEC;

$SPEC{sah_to_human} = {
    v => 1.1,
    summary => 'Convert Sah to human text',
    args_rels => {
        'choose_one&' => [
            [qw/show_schema show_raw_compile/],
        ],
        'req_one&' => [
            [qw/schema schema_file/],
        ],
        # doesn't work yet?
        #'dep_any&' => [
        #    ['schema_file_type', [qw/schema_file/]],
        #],
    },
    args => {
        schema => {
            schema=>'any*',
            pos=>0,
            tags => ['category:schema-specification'],
        },
        schema_file => {
            schema=>'str*',
            summary => 'Retrieve schema from file',
            description => <<'_',

JSON and YAML formats are supported. File type will be guessed from filename,
defaults to JSON.

_
            cmdline_aliases => {f=>{}},
            'x.schema.entity' => 'filename',
            tags => ['category:schema-specification'],
        },
        schema_file_type => {
            schema=>['str*', in=>[qw/json yaml/]],
            summary => 'Give hint for schema file type',
            cmdline_aliases => {t=>{}},
            tags => ['category:schema-specification'],
        },

        format => {
            schema=>['str*', in=>[qw/inline_text inline_err_text markdown msg_catalog/]],
            default=>'inline_text',
            cmdline_aliases => {F=>{}},
            tags => ['category:compilation'],
        },
        hash_values => {
            summary => "To be passed during compilation",
            schema=>['hash*'],
            #cmdline_aliases => {H=>{}},
            tags => ['category:compilation'],
        },

        show_schema => {
            summary => "Don't convert schema, show normalized schema only",
            schema=>['bool', is=>1],
            cmdline_aliases => {s=>{}},
            tags => ['category:action-selection'],
        },
        show_raw_compile => {
            summary => "Don't format compilation result to final text, show raw result only",
            schema=>['bool', is=>1],
            tags => ['category:action-selection'],
        },
#        with_debug => {
#            summary => 'Convert with debug on',
#            description => <<'_',
#
#This means e.g. to pepper the validator code with logging statements.
#
#_
#            schema => ['bool', is=>1],
#            tags => ['category:validator-specification'],
#        },
    },
    examples => [
        {
            args => {schema=>"int"},
        },
        {
            args => {schema=>["int" => min=>1, max=>10]},
        },
    ],
};
sub sah_to_human {
    my %args = @_;

script/sah-to-human  view on Meta::CPAN

interactive terminal (i.e. whether output is piped). This option specifically
chooses an output format.


=item B<--json>

Set output format to json.

=item B<--no-naked-res>

When outputing as JSON, add result envelope.

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
C<--naked-res> so you just get:

 [1,2,3]


=item B<--page-result>

Filter output through a pager.

This option will pipe the output to a specified pager program. If pager program
is not specified, a suitable default e.g. C<less> is chosen.


=item B<--view-result>

View output using a viewer.

This option will first save the output to a temporary file, then open a viewer
program to view the temporary file. If a viewer program is not chosen, a
suitable default, e.g. the browser, is chosen.


=back

=head2 Schema specification options

=over

=item B<--schema-file-type>=I<s>, B<-t>

Give hint for schema file type.

Valid values:

 ["json","yaml"]

=item B<--schema-file>=I<filename>, B<-f>

Retrieve schema from file.

JSON and YAML formats are supported. File type will be guessed from filename,
defaults to JSON.


=item B<--schema-json>=I<s>

See C<--schema>.

Can also be specified as the 1st command-line argument.

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

(No description)


Can also be specified as the 1st command-line argument.

=back

=head2 Other options

=over

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

Display help message and exit.

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

Display program's version and exit.

=back

=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 sah-to-human sah-to-human

in your bash startup (e.g. F<~/.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 L<cpanm-shcompgen>
which can activate shell completion for scripts immediately.

=head2 tcsh

To activate tcsh completion for this script, put:

 complete sah-to-human 'p/*/`sah-to-human`/'

in your tcsh startup (e.g. F<~/.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.



( run in 1.568 second using v1.01-cache-2.11-cpan-39bf76dae61 )