# -*-perl-*-

# $Id: Limit.plm,v 1.4 2003/06/09 14:45:11 thomas Exp $

# Front-end to add, remove, or list limits in the db.

# $Log: Limit.plm,v $
# Revision 1.4  2003/06/09 14:45:11  thomas
# schema version of database
#
# Revision 1.3  2002/08/20 21:59:56  thomas
# installed 0.3.0
#
# Revision 1.2  2002/07/08 15:56:35  thomas
# 0.2.3 release
#
# Revision 1.1.1.1  2002/05/21 14:13:34  thomas
# sushi - backup to disk
#

package Sushi::Command::Limit;

use strict;
use Getopt::Long;

my %subs = (
	    add      => \&Sushi::GenDB::add,
	    list     => \&Sushi::GenDB::display,
	    del      => \&Sushi::GenDB::del,
	    help     => \&printhelp,
	    '--help' => \&printhelp
	   );

###############################################################################

sub main {
  my ($class) = shift;
  my $cmd = shift @ARGV;

  my $args;

  Getopt::Long::Configure ("bundling");
  my $res;
  if (!($res = GetOptions (
			'resource_type|t=s',  \$args->{resource_type},
			'resource_name|n=s',  \$args->{resource_name},
			'starttime|s=s',      \$args->{start_time},
			'endtime|e=s',        \$args->{end_time},
			'resource_limit|l=s', \$args->{resource_limit},
			  ))) {
    $main::log->error (&help);
    return 0;
  }

  defined ($ARGV[0]) and $args->{resource_type} = shift @ARGV;
  defined ($ARGV[0]) and $args->{resource_name} = shift @ARGV;
  defined ($ARGV[0]) and $args->{start_time} = shift @ARGV;
  defined ($ARGV[0]) and $args->{end_time} = shift @ARGV;
  defined ($ARGV[0]) and $args->{resource_limit} = shift @ARGV;

  if (defined $subs{$cmd}) {
    return $subs{$cmd}(
		       $args,
		       {
			print_headings => 1,
			print_results => 1
		       },
		       $::table_defs->{limits}
		      );
  }
  $main::log->error("Bad limit sub-command specified\n");
  return;
}

###############################################################################

sub aliases {
  return ();
}

###############################################################################

sub printhelp {
  print help();
  return 1;
}

sub shortHelp {
  return "Add, delete or remove limits";
}

sub help {
  my $help = <<__Eof__

limit\tadd <options>
\tdel <options>
\tlist <options>
options: [(--resource-type|-t) <resource type>]
\t[(--resource_name|-n) <resource name>]
\t[(--starttime|-s) <start-time>] [(--endtime|-e) <end-time>]
\t[(--resource_limit|-l) <resource limit>]
\t[<type> [<name> [<start-time> [<end-time> [<limit>]]]]]

__Eof__
;
}

###############################################################################

1;
