#!/usr/bin/perl
use strict;

my $pkg    = "andrewcrmartin/profit";
my $mntDir = "/h";
my $params = '';
my $mounts = "";
my %dirs   = {};

foreach my $param (@ARGV)
{
    if(substr($param,0,1) eq '-')
    {
        $params .= " $param";
    }
    else
    {
        if($param =~ /(.*)\/(.*?)/)
        {
            my $dir  = $1;
            my $file = $2;
            if(!defined($dirs{$dir}))
            {
                $dirs{$dir}=1;
                $mounts .= " -v $1:$1";
            }
            $params .= " $param";
        }
        else
        {
            $params .= " $mntDir/$param";
        }
    }
}

my $pwd = `pwd`;
chomp $pwd;
my $exe="docker run --rm -it -v $pwd/:$mntDir $mounts $pkg /opt/profit/profit $params";
#print "$exe\n";
print <<__EOF;

========================================================================

    ProFit Docker Wrapper
    ---------------------

    N.B. When writing a file, you must provide the path "/h/" in
         front of the filename.

========================================================================

__EOF
system($exe);

