ray names validModes] {|}])"
    }
    
    # Is it a required or an optional option
    if {$argsLen} {
	# optional option
	set optional 1
	set _default [lindex $args 0] 
	set optionName [lindex $args 1]
	
	set optionHelpStr "\[-$optionName <fileName>\]"
	
	# Set up the default value
	lappend dstruct($cn,returnVals) $optionName $_default
	
	lappend dstruct($cn,optionalOptions) $optionName [list cli::checkFile $mode]
	
    } else {
	# required option
	set optional 0
	set optionName $dstruct($cn,reqdOptionsLen)
	set optionHelpStr "<fileName>"
	
	lappend dstruct($cn,reqdOptions) [cli::postincr dstruct($cn,reqdOptionsLen)] [list [list cli::checkFile $mode] $optionType]
    }
    
    lappend dstruct($cn,optionOrder) [cli::postincr dstruct($cn,optionOrderLen)] [list $optional $optionName "fileName"]
    
    # return the help section here
    return $optionHelpStr    
}

##################################################################################################
# These are the various check routines
##################################################################################################
proc cli::checkEnum {possibleVals commandName optional optionName argsName indexName} {
    
    # Link to the args list from the calling procedure
    upvar $argsName args
    upvar $indexName i
    
    # Is it an optional option or a required one
    if {$optional} {
	# optional option
	
	#extract the value of the option from the args 
	set val [lindex $args [cli::postincr i]]		
	
    } else {
	# required option
	# optionName is actually the value 
	set val $optionName
    }
    
    # do a findabbr on optionVal against possibleVals
    if {[catch {cli::findabbr $possibleVals $val 1} ret]} {
	error "Muliple matches detected for \"$val\". Please qualify further"
    }
    
    if {$ret eq ""} {
	error "\"$val\" is not one of possible values $possibleVals"
    } else {
	set val $ret
    }
    
    return $val
}

proc cli::checkFile {mode commandName optional optionName argsName indexName} {
    
    #puts [info level 0]
    
    # Link to the args list from the calling procedure
    upvar $argsName args
    upvar $indexName i
    
    # Is it an optional option or a required one
    if {$optional} {
	# optional option
	
	#extract the value of the option from the args 
	set val [lindex $args [cli::postincr i]]			
	
    } else {
	# required option
	# optionName is actually the value 
	set val $optionName
    }
    
    # Try to open the file with the mode specified
    if {[catch {open $val $mode} fileId]} {
	error "Error \[open $val $mode\]: $fileId"
    }
    
    return $fileId
}

proc cli::checkboolean {commandName optional optionName argsName indexName} {
    
    # Link to the args list from the calling procedure
    upvar $argsName args
    upvar $indexName i
    
    # Is it an optional option or a required one
    if {$optional} {
	
	# check the next arg to see if it is a valid bool value
	set possibleval [lindex $args $i]
	if {[catch {cli::findabbr {false true} $possibleval 1} ret]} {
	    # that is ok, we will a