CXC-Form-Tiny-Plugin-OptArgs2
view release on metacpan or search on metacpan
use Test::Lib;
use My::Test::AutoCleanHash;
use Data::Dumper;
use OptArgs2;
use experimental 'signatures', 'postderef';
package My::SubForm {
use Form::Tiny plugins => ['+CXC::Form::Tiny::Plugin::OptArgs2'];
use Types::Standard qw( ArrayRef Bool Enum HashRef Str );
use Types::Common::String qw( NonEmptyStr );
form_field 'upload' => ( type => HashRef [Str], );
option(
isa => 'HashRef',
comment => 'table name/filename pairs to upload',
);
form_field 'vars' => (
type => HashRef [Str],
default => sub { { a => 1 } },
);
option(
isa => 'HashRef',
comment => 'variables to interpolate into query template',
);
}
package My::Form {
use Form::Tiny plugins => ['+CXC::Form::Tiny::Plugin::OptArgs2'];
use Types::Standard qw( ArrayRef Bool Enum HashRef Str );
use Types::Common::String qw( NonEmptyStr );
form_field 'file' => ( type => Str, );
option(
isa => 'Str',
comment => 'Query in a file',
isa_name => 'ADQL in a file',
);
form_field 'adql' => ( type => NonEmptyStr, );
option(
isa => 'Str',
comment => 'Query on the command line',
isa_name => 'ADQL',
);
form_field 'url' => (
type => Str,
default => sub { 'https://cda.cfa.harvard.edu/csc2tap' },
);
option(
isa => 'Str',
comment => 'CSC TAP endpoint',
isa_name => 'URL',
show_default => 1,
);
form_field 'output.file' => ( type => Str, );
option(
name => 'output',
isa => 'Str',
comment => 'File to store parsed results',
isa_name => 'filename',
);
form_field 'output.encoding' => ( type => Enum [ 'json', 'yaml' ], );
option(
name => 'encoding',
isa => 'Str',
comment => sprintf( 'encoding format for --output [%s]', join( ' | ', qw( json yaml ) ) ),
);
form_field 'raw.encoding' => ( type => Enum [ 'foo', 'bar' ], );
option(
name => 'raw-format',
isa => 'Str',
comment => sprintf( 'requested VO format [%s]', join( ' | ', qw( foo bar ) ) ),
);
form_field 'raw.file' => ( type => Str, );
option(
name => 'raw-output',
isa => 'Str',
comment => 'store raw results from CSC server in this file',
isa_name => 'filename',
);
form_field 'use_db' => (
type => Bool,
default => sub { 0 },
);
option(
name => 'db',
isa => 'Flag',
comment => 'output to database instead of a file',
);
form_field 'stuff' => ( type => My::SubForm->new, );
# add some arguments, in reverse order
form_field 'arg2' => ( type => ArrayRef, );
argument(
isa => 'ArrayRef',
comment => 'every thing else',
greedy => 1,
order => 2,
);
form_field 'arg1' => ( type => NonEmptyStr, );
argument(
isa => 'Str',
comment => 'first argument',
( run in 0.749 second using v1.01-cache-2.11-cpan-5a3173703d6 )