#!/usr/bin/perl -w
#
# NOTE: This tool is considered experimental and is thus undocumented to
# discourage use.  We are using it internally as a temporary solution,
# but are expecting to revamp and replace this tool with something more
# substantial in the future. --2004-11-23
#
# Copyright (C) 2003-2004 Open Source Development Network, Inc. ("OSDN")
# Copyright (C) 2004 OSTG, Inc. ("OSTG")
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the license details found
# in the included code section marked "$LICENSE_TEXT".
#
# $Id: atracker,v 1.2 2005/03/01 11:51:49 moorman Exp $
#
# Written by Jacob Moorman <moorman@sourceforge.net>
###########################################################################

use Alexandria::Client;
use Alexandria::Tracker;

use Getopt::Long;               # for command-line option processing
package main;

# Command-line option handling: enabled bundling of short options and
# case sensitivity
Getopt::Long::Configure ("bundling");
Getopt::Long::Configure ("no_ignore_case");

@downloaddirfilelist = qw(crid body title);

sub client_specific_getoptions {
	return GetOptions(\%config,
			"atid=s",
			"cannedresponse=s",
			"configfile=s",
			"cookiefile=s",
			"crid=s",
			"debug",
			"directoryname=s",
			"groupid=s",
			"help|?",
			"hosturl=s",
			"hostname=s",
			"interactive",
			"list=s",
			"login",
			"logout",
			"password=s",
			"quiet|q",
			"username=s",
			"verbose|v",
			"version|V",
		);
	}

###########################################################################
# Main program block

#perform any non-operative commands
#this includes usage, version, debug, etc
if (exists($config{help})) {
	atracker_usage("");
	exit;
} elsif (exists($config{version})) {
	atracker_version("");
	exit;
}

#perform any operations which do not require a login
#this might include simple text filtering
if (exists($config{prepare})) {
	atracker_prepare("");
	exit;
}

my $CLIENT = new Alexandria::Client;
util_verifyvariables("groupid");
util_verifyvariables("atid");
my $DOCMAN = new Alexandria::Tracker ($CLIENT, $config{groupid}, $config{atid});

# Perform the selected action
if (exists($config{list})) {

	util_output("verbose", "Performing a list operation.");

	if ($config{list} eq "cannedresponses") {
		sfnet_tracker_list_cannedresponses("");
	} else {
		util_output("die", "Invalid --list mode specified: ".
				"$config{list}", "4");
	}

	util_output("verbose", "Completed list operation.");

} elsif (exists($config{cannedresponse})) {
	sfnet_tracker_cannedresponse("");
} else {
	atracker_usage("error");
}


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

__END__
