#!/usr/bin/env perl

package Bio::VertRes::Config::Main::SetupGlobalConfigs;

# ABSTRACT: Create config scripts and overall strucutre for the global configs
# PODNAME: setup_global_configs


BEGIN { unshift( @INC, '../lib' ) }
BEGIN { unshift( @INC, './lib' ) }
BEGIN { unshift( @INC, '/software/pathogen/internal/prod/lib/' ) }
use Moose;
use Getopt::Long;
use Bio::VertRes::Config::CommandLine::LogParameters;
use Bio::VertRes::Config::Recipes::Global;

my $log_params = Bio::VertRes::Config::CommandLine::LogParameters->new( args => \@ARGV, script_name => $0 );

my ( $database, $database_connect_file, $config_base, $root_base, $log_base, $overwrite_existing_config_file,$regeneration_log_file, $help );

GetOptions(
    'd|database=s'                     => \$database,
    'db_file:s'                        => \$database_connect_file,
    'c|config_base=s'                  => \$config_base,
    'root_base=s'                      => \$root_base,
    'log_base=s'                       => \$log_base,
    'o|overwrite_existing_config_file' => \$overwrite_existing_config_file,
    'b|regeneration_log_file=s' => \$regeneration_log_file,
    'h|help'                           => \$help,
);

$config_base           ||= '/nfs/pathnfs05/conf';
$root_base             ||= '/lustre/scratch108/pathogen/pathpipe';
$log_base              ||= '/nfs/pathnfs05/log';
$overwrite_existing_config_file ||= 0;
$regeneration_log_file ||= join('/',($config_base,'command_line.log'));
$database_connect_file = '/software/pathogen/config/database_connection_details' unless defined $database_connect_file;

$log_params->log_file($regeneration_log_file);
$log_params->create();

( defined($database) && !$help ) or die <<USAGE;
Usage: setup_global_configs [options]
Setup global config files and directory structure for a database.

# Setup global configs
setup_global_configs -d pathogen_abc_track

# Setup global configs specifying location of configs
setup_global_configs -d pathogen_abc_track -c /path/to/my/configs

# Setup global configs specifying root and log base directories
setup_global_configs -d pathogen_abc_track -root /path/to/root -log /path/to/log

# Setup global configs specifying a file with database connection details
setup_global_configs -d pathogen_abc_track-db_file -db_file /path/to/connect/file

# This help message
setup_global_configs -h

USAGE

my %parameters = (
    database                       => $database,
    database_connect_file          => $database_connect_file,
    config_base                    => $config_base,
    root_base                      => $root_base,
    log_base                       => $log_base,
    overwrite_existing_config_file => $overwrite_existing_config_file
);

Bio::VertRes::Config::Recipes::Global->new( \%parameters )->create();

__PACKAGE__->meta->make_immutable;
no Moose;
1;

__END__

=pod

=head1 NAME

setup_global_configs - Create config scripts and overall strucutre for the global configs

=head1 VERSION

version 1.133090

=head1 SYNOPSIS

Create config scripts and overall strucutre for the global configs

=head1 AUTHOR

Andrew J. Page <ap13@sanger.ac.uk>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007

=cut
