#!/usr/bin/env perl

##**************************************************************
##
## Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
## 
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License.  You may
## obtain a copy of the License at
## 
##    http://www.apache.org/licenses/LICENSE-2.0
## 
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##**************************************************************



# Configuration variables
$file = "requirements.txt";

# Check args
$type = $ARGV[0];
$name = $ARGV[1];
$comp = $ARGV[2];
$value = $ARGV[3];
if( ! ($type && $name && $comp && $value) ) {
    usage();
}
# Build the proper requirement clause
if( $type eq "string" ) {
    $req = "$name $comp \"$value\"";
} elsif ( $type =~ /(int|float|bool)/ ) {
    $req = "$name $comp $value";
} else { 
    fprintf STDERR "ERROR: The type \"$type\" is not recognized.\n", 
    "You must use one of \"string\", \"bool\", \"int\", or \"float\"\n";
    usage();
}

if( -f $file ) {
    # Harder, have to append the new requirements...
    # TODO
    die "Error: $file already exists.  I don't know how to ", 
    "deal with that.\n";
} else {
    # Easy, just create the new filel
    open( OUT, ">$file" ) || die "Can't open $file: $!\n";
    print OUT "Requirements\t= $req\n";
    close OUT;
}

sub usage {
    print STDERR "Usage: $0 [type] [name] [comparison] [value]\n";
    exit(1);
}
