TABLE OF CONTENTS


::pwtk::setOpts_

SYNOPSIS

proc ::pwtk::setOpts_ {optionsVar optValList} {

PURPOSE

Set options values in the 'options' list variable, which has the syntax required by ::cmdline::getoptions

ARGUMENTS

SOURCE

    upvar $optionsVar options

    set ovL {}
    set new_options {}

    # purify optValList
    foreach {opt val} $optValList {
        regsub {\.arg$} [string trim $opt -] {} opt
        set found($opt) 0
        lappend ovL $opt $val
    }

    foreach optionSpecs $options {
        lassign $optionSpecs option value text

        set result {}
        foreach {opt val} $ovL {
            if { $opt eq $option } {
                ::pwtk::error "the -$opt option is valueless" 1
            }
            if { "$opt.arg" eq $option } {
                set found($opt) 1
                set result [list $option $val $text]
                break
            }
        }
        if { $result eq {} } {
            set result $optionSpecs
        }
        lappend new_options $result
    }

    foreach {opt val} $ovL {
        if { ! $found($opt) } {
            ::pwtk::error "the -$opt option is not among allowed options" 1
        }
    }

    set options $new_options
}