#!/usr/bin/perl
use strict;
use warnings;

use English qw( -no_match_vars ); 
use Data::Dumper;
use MySQL::Sandbox;

my $DEBUG = $MySQL::Sandbox::DEBUG;

#my $install_dir;
#$install_dir = $PROGRAM_NAME;
#$install_dir =~ s{/\w+(\.pl)?$}{};

my $msb = MySQL::Sandbox->new();

my @apps = (
        { 
            name => 'make_sandbox',
            description  => 'the easiest way of creating a sandbox',
        },
        {
            name => 'low_level_make_sandbox', 
            description => q{create a single sandbox, with fine tuning options (don't use directly)},
        },
        {
            name    => 'make_replication_sandbox',
            description  => 'creates a sandbox with replicated master and slaves or circular',
        },
        {
            name    => 'make_multiple_sandbox',
            description => 'creates a group of sandboxes with the same version',
        },
        {
            name => 'make_multiple_custom_sandbox',
            description  => 'create a group of sandboxes with different versions',
        }
);

my $choice = shift
    or help();
if (grep {$choice eq $_->{name} } @apps ) { 
    my $application = "$choice";
    if ( -x $application) {    
        exec $application, @ARGV;
    }
    else {
        die "application $application not found\n";
    }
}
else {
    exec "perldoc MySQL::Sandbox";
    #die "'$choice' is not an application in MySQL Sandbox\n";
}

sub help {
    print $msb->credits(); 
    print "available applications:\n";
    for my $app (@apps) {
        printf " %-30s: %s\n", $app->{'name'}, $app->{'description'};
    }
    exit(1);
}

__END__

