#!/usr/bin/env perl

use strict;
use warnings;

BEGIN {
	use Mojo::File qw(curfile);
	use YAML::XS qw(LoadFile);
	use Env qw(WEBWORK_ROOT PG_ROOT);

	$WEBWORK_ROOT = curfile->dirname->dirname->to_string;

	# Load the configuration file to obtain the PG root directory.
	my $config_file = "$WEBWORK_ROOT/conf/webwork2.mojolicious.yml";
	$config_file = "$WEBWORK_ROOT/conf/webwork2.mojolicious.dist.yml" unless -e $config_file;
	my $config = LoadFile($config_file);

	$PG_ROOT = $config->{pg_dir};

	$WeBWorK::SeedCE{webwork_dir} = $ENV{WEBWORK_ROOT};
	$WeBWorK::SeedCE{pg_dir}      = $ENV{PG_ROOT};
}

use Mojolicious::Commands;

use lib "$WEBWORK_ROOT/lib";
use lib "$PG_ROOT/lib";

# Start command line interface for application
Mojolicious::Commands->start_app('Mojolicious::WeBWorK');
