#!/bin/sh  
# \
exec oagtclsh "$0" "$@"

set auto_path [linsert $auto_path 0  /usr/local/oag/apps/lib/$env(HOST_ARCH)]
set auto_path [linsert $auto_path 0 /usr/local/oag/lib_patch/$env(HOST_ARCH)]

APSStandardSetup

set usage "usage: SubmitTechReportToICMS -filename <filename> -title <title> -author <names> \[-date <date>\] \[-revision <integer>\] \[-comments <comments>\] \[-techNoteID <AOP-TN-????-???>\]"

if {![llength $argv]} {
    puts stderr $usage
    exit
}

set args $argv
set author ""
set category ""
set comments ""
set filename ""
set date ""
set division ""
set group ""
set icmsPassword ""
set icmsUsername ""
set revision 0
set securityAccount ""
set securityGroup ""
set subcategory ""
set title ""
set techNoteID ""

APSStrictParseArguments {author category comments filename date division group icmsPassword icmsUsername revision securityAccount securityGroup subcategory title techNoteID}

if {![file exists $filename]} {
    puts stderr "error: $filename does not exist"
    exit
}

set title [string trim $title]
if {![llength $title]} {
    puts stderr "error: missing -title value"
    exit
}
#Do not allow titles that end in ", Rev. 1"
set i [string last ", Rev." $title]
if {$i != -1} {
    set title [string range $title 0 [expr $i - 1]]
}

set author [string trim $author]
if {![llength $author]} {
    puts stderr "error: missing -author value"
    exit
}

if {[llength $techNoteID]} {
    set comments "TechReport:$techNoteID $comments"
} else {
    set comments "TechReport: $comments"
}

set dSecurityGroup $securityGroup
set dDocAccount $securityAccount
set xDivision $division
set xGroup $group
set xTopicLevel3 $category
set xTopicLevel4 $subcategory
#Prompt the user for values for various arguments that we will send to APSSubmitFileToICMS
set args [APSPromptSTDINforICMSinfo]
APSStrictParseArguments {dSecurityGroup dDocAccount icmsUsername icmsPassword xDivision xGroup xTopicLevel3 xTopicLevel4}

if {[catch {APSSubmitFileToICMS \
              -primaryFile $filename \
              -dDocTitle $title \
              -xDocAuthor $author \
              -xComments $comments \
              -dRevLabel $revision \
              -xDocDate $date \
              -dSecurityGroup $dSecurityGroup \
              -dDocAccount $dDocAccount \
              -icmsUsername $env(USER) \
              -icmsPassword $icmsPassword \
              -xDivision $xDivision \
              -xGroup $xGroup \
              -xTopicLevel1 "Technical Documentation" \
              -xTopicLevel2 "Technical Notes" \
              -xTopicLevel3 $xTopicLevel3 \
              -xTopicLevel4 $xTopicLevel4} results]} {
    puts stderr "Error: $results"
}



