TABLE OF CONTENTS


::pwtk::parseOpt_

SYNOPSIS

proc ::pwtk::parseOpt_ {} {    

DESCRIPTION

A convenience routine for parsing options for procs that are of "proc name {args} {...}" form, where the usage is as:

     name -opt1 -opt2 val -opt3 -val   arg1  arg2 arg3
          ^^^^^^^^^^^^^^^^^^^^^^^^^^   ^^^^^^^^^^^^^^^
           |                                 |
           +--- options and their values     + extra agruments that follow after options

BEWARE

In addition to the args variable, the following variables must also be defined to use this proc:

and either:

or:

The parsed opions are stored in "opt" array.

SOURCE

    uplevel 1 {
        foreach var {args options usage} {            
            if { ! [info exists $var] } {
                ::error "coding error: variable $var does not exist"
            }
        }
        set args_ $args 
        array set opt [::cmdline::getoptions args $options "error while executing:\n\n[pwtk::procName] $args_\n\n[::pwtk::procName] options:"]
        
        if { [info exists narg] } {
            if { $narg >= 0 && [llength $args] != $narg } {
                # nargs
                ::pwtk::error "wrong # args, should be:\n\n[::pwtk::procName] $usage\n\nbut got: [::pwtk::procName] $args_" 1
            }
        } elseif { [info exists nargmin] && [info exists nargmax] } {
            # nargmin nargmax
            if { [llength $args] < $nargmin } {
                ::pwtk::error "wrong # args, should be:\n\n[::pwtk::procName] $usage\n\nbut got: [::pwtk::procName] $args_" 1
            }
            if { $nargmax >= 0 && [llength $args] > $nargmax } {
                ::pwtk::error "wrong # args, should be: \n\n[::pwtk::procName] $usage\n\nbut got: [::pwtk::procName] $args_" 1
            }
            # if nargmax < 0 ==> no checking
        } else {
            ::error "coding error: neither narg nor nargmin & nargmax exist"
        }        
    }
}