The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl
# sandbox
#    The MySQL Sandbox
#    Copyright (C) 2006-2018 Giuseppe Maxia
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

use strict;
use warnings;

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

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

runs_as_root();

#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',
        },
        {
            name => 'make_sandbox_from_source',
            description  => 'create a sandbox from a build directory',
        },
        {
            name => 'make_sandbox_from_installed',
            description  => 'create a sandbox from already installed binaries',
        },
        {
            name => 'sbtool',
            description  => 'performs auxiliary actions with existing sandboxes',
        },
);

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__