#!/usr/bin/perl -w

# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id: run-periodic-tasks 2380 2008-05-17 22:41:18Z bchoate $

use strict;

use lib 'lib', '../lib';

require MT::Bootstrap;
require MT;

my $mt = MT->new() or die MT->errstr;

$mt->{vtbl} = { };
$mt->{is_admin} = 0;
$mt->{template_dir} = 'cms';
$mt->{user_class} = 'MT::Author';
$mt->{plugin_template_path} = 'tmpl';
$mt->run_callbacks('init_app', $mt);


my $status = 0;

require Getopt::Long;
#Getopt::Long::GetOptions();

require PluginManager::Command;

my $cmd = shift || 'help';
my $obj = PluginManager::Command->instance_for($cmd);

my %opts = ();
my %opt_def = map({
	$_ => \$opts{$_}
} $obj->options);
Getopt::Long::GetOptions(%opt_def);

my $result = $obj->process(\%opts, @ARGV);

if (eval{ $result->isa('PluginManager::Command::Error') }) {
	print STDERR $result->{message};
	$status = $result->{status};
}

exit $status;
