#! /usr/bin/env perl
# p4submit
########################################################################

########################################################################
# ALLOW COMMAND LINE SUBMITTING OF PERFORCE CHANGELISTS
#
# Programmed by David Weintraub
# Date: 09-Jun-2006
# Purpose:
#     This program allows users to submit Perforce changelists by
#     simply giving the changelist number and description on the
#     command line.
#
########################################################################

########################################################################
# PERL PRAGMAS
#
use lib qw(/home/merbld/etc/perl);
use strict;
use warnings;
#
########################################################################

########################################################################
# PERL MODULES
#
use File::Basename;
use Getopt::Long;
use FormInfo;
#
########################################################################

########################################################################
# CONSTANTS
#

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

########################################################################
# USAGE
#
my $USAGE=<<USAGE;
@{[basename($0)]} -d <desc> [-c <change>]

Where
    <desc>:   Description Flag
    <change>: Changelist Number
    -help:    Displays this screen

    NOTICE: The "-r" flag is NOT supported
USAGE
#
########################################################################

########################################################################
# GETOPTS
#
my ($description, $raw, $changeList, $help);
GetOptions (
    "d=s" => \$description,
    "r=s" => \$raw,
    "c=s" => \$changeList,
    "help" => \$help
);
#
########################################################################

########################################################################
# CHECK OPTIONS
#
if ($help) {
    print "$USAGE\n";
    exit 0;
}

unless ($description) {
    print "Error: Description Required!\n\n";
    print "$USAGE\n";
    exit 2;
}

if ($raw) {
    print "Error: We do not support the \"-r\" flag on submits.\n";
    print "       use the regular \"p4 submit\" command\n";
}
#
########################################################################

########################################################################
# READ IN ALL FIELDS
#
my %changeHash;
if ($changeList) {
    formRead("change", "$changeList", \%changeHash);
} else {
    formRead("change", "", \%changeHash);
}

#
#   ####Check to Make Sure it Worked
#

unless ($changeHash{"Description"}) {
    print "Could not open changelist $changeList\n";
}
#
########################################################################

########################################################################
# Change Description and Resubmit
#
$changeHash{"Description"} = "$description";
formWrite("submit", \%changeHash);
#
########################################################################