TABLE OF CONTENTS


::pwtk::parseKnownOpt_

SYNOPSIS

proc ::pwtk::parseKnownOpt_ {} {    

DESCRIPTION

Similar to ::pwtk::parseOpt_ but ignores any unknown options, i.e., the difference between ::pwtk::parseKnownOpt_ and ::pwtk::parseOpt_ is that the former uses ::cmdline::getKnownOptions and the latter ::cmdline::getoptions.

A convenience routine for parsing known 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:

N.B. nargmax is not considered here because due to unknown options, the max number of argumemts is unknown

    

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::getKnownOptions args $options "error while executing:\n\n[pwtk::procName] $args_\n\n[::pwtk::procName] options:"]
        
        if { [info exists narg] } {
            # nargs
            if { $narg >= 0 && [llength $args] < $narg } {
                ::pwtk::error "wrong # args, should be:\n\n[::pwtk::procName] $usage\n\nbut got: [::pwtk::procName] $args_" 1
            }
        } elseif { [info exists nargmin] } {
            # nargmin
            if { $nargmin >= 0 && [llength $args] < $nargmin } {
                ::pwtk::error "wrong # args, should be:\n\n[::pwtk::procName] $usage\n\nbut got: [::pwtk::procName] $args_" 1
            }
        } else {
            ::error "coding error: neither narg nor nargmin exist"
        }        
    }
}