#!/usr/bin/python

import sys
from subprocess import call
import argparse

def runContainer(containerName, databaseName):
	''' Runs the command to create the database given using the container given
	'''
	call("docker run -it --link="+containerName+":mysql --rm mysql sh -c 'exec mysqladmin -h$MYSQL_PORT_3306_TCP_ADDR -P$MYSQL_PORT_3306_TCP_PORT -uroot -p create "+ databaseName +" '", shell=True)
	return

def main():
	''' Parse the options from the command line and run the function runContainer
	'''
	parser = argparse.ArgumentParser(
		description="Import a .sql file into a database", 
		prog="dmysql-import-database")

	# Create the options
	parser.add_argument("container", help="The mysql container to use")
	parser.add_argument("database", help="Database to create")

	args = parser.parse_args()

	runContainer(containerName=args.container, databaseName=args.database)

	return

# Execute the main function
main()