# -*-perl-*-

# $Id$

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

# $Log$
# Revision 1.4  2002/09/10 20:42:57  thomas
# sushi-0.3.1
#
# 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:35  thomas
# sushi - backup to disk
#

package Sushi::Command::NoDump;

use strict;
use Getopt::Long;


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

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

  my %args;

  Getopt::Long::Configure ("bundling");
  my $res;
  if (!($res = GetOptions (
			   'atom_type|t=s',     \$args{atom_type},
			   'match_item|i=s',    \$args{match_item},
			   'match_type|m=s',    \$args{match_type},
			   'pattern|p=s',       \$args{pattern},
			   'reminder_name|n=s', \$args{reminder_name},
			   'req_number|r=s',    \$args{req_number},
			   'help|h',            \$args{help},
			   'name=s',            \$args{name},
			   'type=s',            \$args{type},
			   'server=s',          \$args{server},
			   'servpart=s',        \$args{serv_part}
			  ))) {
    $main::log->error (&help);
    return 0;
  }

  if (defined $args{help} || (defined ($cmd) && $cmd eq "help")) {
    print &help;
    return 1;
  }

  defined ($ARGV[0]) and $args{atom_type} = shift @ARGV;
  defined ($ARGV[0]) and $args{match_item} = shift @ARGV;
  defined ($ARGV[0]) and $args{match_type} = shift @ARGV;
  defined ($ARGV[0]) and $args{pattern} = shift @ARGV;
  defined ($ARGV[0]) and $args{reminder_name} = shift @ARGV;
  defined ($ARGV[0]) and $args{req_number} = shift @ARGV;

  if ($cmd eq 'list') {
    my $limits = &Sushi::NoDumps::getNodumps (%args);
    print <<__Eof__

            Match       Match                                      Reminder         Req
Atom Type   Item        Type     Pattern                           Name             Number
----------  ----------  -------  --------------------------------  ---------------  --------
__Eof__
;
    foreach (@$limits) {
      defined ($_->{reminder_name}) or $_->{reminder_name} = "";
      defined ($_->{req_number})    or $_->{req_number}    = "";
      printf "%-10s  %-10s  %-8s %-32s  %-15s  %8s\n", $_->{atom_type}, $_->{match_item},
	$_->{match_type}, $_->{pattern}, $_->{reminder_name}, 
	  $_->{req_number};
    }
    print "\nEnd of List\n\n";
  } elsif ($cmd eq 'add') {
    &Sushi::NoDumps::addNodump (%args);
  } elsif ($cmd eq 'del') {
    &Sushi::NoDumps::delNodump (%args);
  } elsif ($cmd eq 'test') {
    if (&Sushi::NoDumps::skipDump (%args)) {
      print "The atom would be skipped\n";
    } else {
      print "The atom would not be skipped\n";
    }
  } else {
    $main::log->error("Bad nodump sub-command specified\n");
  }
  return;
}

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

sub aliases {
  return ();
}

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

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

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

sub help {
  my $help = <<__Eof__

nodump\tadd <options>
\tdel <options>
\tlist <options>

options:\t[(--atom_type|-t) <atom type>] [(--match_item|-i) <item to match>] \\
\t[(--match_type|-m) <match type>] [(--pattern|-p) <pattern to match>] \\
\t[(--reminder_name|-n) <folks to remind>] [(--req_number|-r) <req number>] \\
\t[<atom type> [<item to match> [<match type> [<pattern to match> [<reminder> [<req #>]]]]]]

atom_type     -- type of atom to match (Afs, Linux, etc.)
match_item    -- parameter to match (atom, server, etc.)
match_type    -- match type (one of 'exact' or 'perlre')
pattern       -- pattern to match against
reminder_name -- comma-separated list of email addresses to send reminders to
req_number    -- reference the req that generated this nodump entry

The match items are supplied by the group types.  The items available for
matching vary based on the dump type.  See the libraries in
.../sushi/lib/Sushi/Group/*.pm  for specifics.

__Eof__
;
}

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

1;
