<commit_before>
=head1 NAME

VRPipe::Interface::CmdLine - shared methods of all cmd-line frontend scripts

=head1 SYNOPSIS

*** more documentation to come

=head1 DESCRIPTION

The various B<vrpipe-*> scripts use this module which provides methods that
they all need to function.

*** more documentation to come

=head1 AUTHOR

<NAME> <<EMAIL>>.

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2011-2012 Genome Research Limited.

This file is part of VRPipe.

VRPipe is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program. If not, see L<http://www.gnu.org/licenses/>.

=cut

use VRPipe::Base;

class VRPipe::Interface::CmdLine {
    use Getopt::Long qw(GetOptions GetOptionsFromString);
    use Perl6::Form;
    use LWP::UserAgent;
    use Sys::Hostname::Long;
    use VRPipe::Config;
    use VRPipe::Persistent::SchemaBase;
    use Config;
    
    has 'description' => (
        is       => 'rw',
        isa      => 'Str',
        required => 1
    );
    
    has 'extra_args' => (
        is  => 'rw',
        isa => 'Str'
    );
    
    has 'opt_spec' => (
        is      => 'rw',
        isa     => 'ArrayRef[ArrayRef]',
        lazy    => 1,
        builder => '_default_opt_spec'
    );
    
    has '_opts_hash' => (
        is      => 'ro',
        isa     => 'HashRef',
        default => sub { {} },
        writer  => '_set_opts',
        traits  => ['Hash'],
        handles => {
            opts           => 'get',
            option_was_set => 'defined',
            '_set_opt'     => 'set'
        }
    );
    
    has 'usage' => (
        is     => 'ro',
        isa    => 'Str',
        writer => '_set_usage'
    );
    
    has '_multiple_setups' => (
        is  => 'rw',
        isa => 'Bool'
    );
    
    has 'no_user_option' => (
        is      => 'ro',
        isa     => 'Bool',
        default => 0
    );
    
    has '_ua' => (
        is      => 'ro',
        isa     => 'LWP::UserAgent',
        lazy    => 1,
        builder => '_build_ua'
    );
    
    has 'port' => (
        is     => 'ro',
        isa    => PositiveInt,
        writer => '_set_port'
    );
    
    has 'dsn' => (
        is     => 'ro',
        isa    => 'Str',
        writer => '_set_dsn'
    );
    
    has 'server_ok' => (
        is      => 'ro',
        isa     => 'Bool',
        lazy    => 1,
        builder => 'check_server'
    );
    
    has '_ua_port_baseurl' => (
        is      => 'ro',
        isa     => 'ArrayRef',
        lazy    => 1,
        builder => '_build_ua_port_baseurl'
    );
    
    method _default_opt_spec {
        return [['deployment=s', 'Use the production or testing database', { default => 'production' }], ['env|e=s', 'Use options stored in an environment variable'], ['help|h', 'Print this usage message and exit']];
    }
    
    method _build_ua {
        my $ua = LWP::UserAgent->new(timeout => 20, agent => 'VRPipe-Client');
        return $ua;
    }
    
    sub BUILD {
        my $self = shift;
        
        # we initially used Getopt::Long::Descriptive, but because it does not
        # show what kind of arg each option takes, we implement here a similar
        # interface, but do not use the actual GLD code.
        
        my $opt_spec = $self->opt_spec;
        unless (@$opt_spec <= 4 && @$opt_spec >= 3 && $opt_spec->[-1]->[0] eq 'help|h') {
            my $default = $self->_default_opt_spec;
            
            foreach my $opt_spec (@$opt_spec) {
                my ($def, $help, $extra) = @$opt_spec;
                if ($help) {
                    my ($name, $req_or_opt, $type) = split(/([=:])/, $def);
                    if ($name eq 'setup') {
                        if ($type eq 's@') {
                            unless ($self->no_user_option) {
                                $default->[4] = $default->[2];
                                $default->[2] = ['user|u=s', 'Only show entries for PipelineSetups created by this user; use "all" to show entries for all users', { default => getlogin || getpwuid($<) || 'vrpipe' }];
                                $default->[3] = ['deactivated', 'Also show deactivated PipelineSetups', { default => 0 }];
                            }
                            $self->_multiple_setups(1);
                        }
                    }
                }
            }
            push(@$opt_spec, [], ['General options:'], @$default);<commit_msg>bumped timeout for the cmdline interfaces, since some requests are going to be slow<commit_after>
=head1 NAME

VRPipe::Interface::CmdLine - shared methods of all cmd-line frontend scripts

=head1 SYNOPSIS

*** more documentation to come

=head1 DESCRIPTION

The various B<vrpipe-*> scripts use this module which provides methods that
they all need to function.

*** more documentation to come

=head1 AUTHOR

<NAME> <<EMAIL>>.

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2011-2012 Genome Research Limited.

This file is part of VRPipe.

VRPipe is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program. If not, see L<http://www.gnu.org/licenses/>.

=cut

use VRPipe::Base;

class VRPipe::Interface::CmdLine {
    use Getopt::Long qw(GetOptions GetOptionsFromString);
    use Perl6::Form;
    use LWP::UserAgent;
    use Sys::Hostname::Long;
    use VRPipe::Config;
    use VRPipe::Persistent::SchemaBase;
    use Config;
    
    has 'description' => (
        is       => 'rw',
        isa      => 'Str',
        required => 1
    );
    
    has 'extra_args' => (
        is  => 'rw',
        isa => 'Str'
    );
    
    has 'opt_spec' => (
        is      => 'rw',
        isa     => 'ArrayRef[ArrayRef]',
        lazy    => 1,
        builder => '_default_opt_spec'
    );
    
    has '_opts_hash' => (
        is      => 'ro',
        isa     => 'HashRef',
        default => sub { {} },
        writer  => '_set_opts',
        traits  => ['Hash'],
        handles => {
            opts           => 'get',
            option_was_set => 'defined',
            '_set_opt'     => 'set'
        }
    );
    
    has 'usage' => (
        is     => 'ro',
        isa    => 'Str',
        writer => '_set_usage'
    );
    
    has '_multiple_setups' => (
        is  => 'rw',
        isa => 'Bool'
    );
    
    has 'no_user_option' => (
        is      => 'ro',
        isa     => 'Bool',
        default => 0
    );
    
    has '_ua' => (
        is      => 'ro',
        isa     => 'LWP::UserAgent',
        lazy    => 1,
        builder => '_build_ua'
    );
    
    has 'port' => (
        is     => 'ro',
        isa    => PositiveInt,
        writer => '_set_port'
    );
    
    has 'dsn' => (
        is     => 'ro',
        isa    => 'Str',
        writer => '_set_dsn'
    );
    
    has 'server_ok' => (
        is      => 'ro',
        isa     => 'Bool',
        lazy    => 1,
        builder => 'check_server'
    );
    
    has '_ua_port_baseurl' => (
        is      => 'ro',
        isa     => 'ArrayRef',
        lazy    => 1,
        builder => '_build_ua_port_baseurl'
    );
    
    method _default_opt_spec {
        return [['deployment=s', 'Use the production or testing database', { default => 'production' }], ['env|e=s', 'Use options stored in an environment variable'], ['help|h', 'Print this usage message and exit']];
    }
    
    method _build_ua {
        my $ua = LWP::UserAgent->new(timeout => 200, agent => 'VRPipe-Client');
        return $ua;
    }
    
    sub BUILD {
        my $self = shift;
        
        # we initially used Getopt::Long::Descriptive, but because it does not
        # show what kind of arg each option takes, we implement here a similar
        # interface, but do not use the actual GLD code.
        
        my $opt_spec = $self->opt_spec;
        unless (@$opt_spec <= 4 && @$opt_spec >= 3 && $opt_spec->[-1]->[0] eq 'help|h') {
            my $default = $self->_default_opt_spec;
            
            foreach my $opt_spec (@$opt_spec) {
                my ($def, $help, $extra) = @$opt_spec;
                if ($help) {
                    my ($name, $req_or_opt, $type) = split(/([=:])/, $def);
                    if ($name eq 'setup') {
                        if ($type eq 's@') {
                            unless ($self->no_user_option) {
                                $default->[4] = $default->[2];
                                $default->[2] = ['user|u=s', 'Only show entries for PipelineSetups created by this user; use "all" to show entries for all users', { default => getlogin || getpwuid($<) || 'vrpipe' }];
                                $default->[3] = ['deactivated', 'Also show deactivated PipelineSetups', { default => 0 }];
                            }
                            $self->_multiple_setups(1);
                        }
                    }
                }
            }
            push(@$opt_spec, [], ['General options:'], @$default);
{'fraction_non_alphanumeric': 0.13204100274028216, 'fraction_numerical': 0.006799959403227443, 'mean_word_length': 1.6938217605248769, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 159, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1767994', 'n_tokens_mistral': 3013, 'n_tokens_neox': 2908, 'n_words': 894}