cmdr
Check-in [f41f44de14]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Moved handling of option arguments in help to separate proc. Reworked the handling of global options to show arguments as well. Fixed sorting of section display when seeing options with arguments.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f41f44de14b06cc430c68f2716202e8e259be6b5
User & Date: andreask 2014-09-10 20:21:12
Context
2014-09-10
20:35
Move handling of global option to before checking for a command. We can now enter a main shell with global options set. Bump version numbers. check-in: 2bfa8d5785 user: andreask tags: trunk
20:21
Moved handling of option arguments in help to separate proc. Reworked the handling of global options to show arguments as well. Fixed sorting of section display when seeing options with arguments. check-in: f41f44de14 user: andreask tags: trunk
2014-08-29
20:19
cmdr::parameter - Extended spec with description of option argument, if any. cmdr::help - Modified to make use of the new information in help texts. check-in: 463519edc6 user: andreask tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to help.tcl.

   232    232       }
   233    233   
   234    234       # plus per-option descriptions (sort by flag name)
   235    235       if {[dict size $options]} {
   236    236   	set onames {}
   237    237   	set odefs  {}
   238    238   	foreach {oname ohelp} [::cmdr util dictsort $options] {
   239         -	    # Inspect the parameter and determine of the option
   240         -	    # requires an argument. If yes, suitably extend the
   241         -	    # definition key of the option list.
   242         -	    set pname [dict get $opt2para $oname]
   243         -	    set vt    [dict get $parameters $pname validator]
   244         -	    if {$vt ne "::cmdr::validate::boolean"} {
   245         -		if {[dict exists $parameters $pname arglabel]} {
   246         -		    set plabel [dict get $parameters $pname arglabel]
   247         -		} else {
   248         -		    set plabel [dict get $parameters $pname label]
   249         -		}
   250         -		append oname " [string toupper $plabel]"
   251         -	    }
   252         -
          239  +	    set oname [OptionName $oname parameters opt2para]
   253    240   	    lappend onames $oname
   254    241   	    lappend odefs  $ohelp
   255    242   	}
   256    243   	DefList $width $onames $odefs
   257    244       }
   258    245   
   259    246       # plus per-argument descriptions (keep in cmdline order)
................................................................................
   371    358   
   372    359       # Get the commands in the category, preliminary formatting
   373    360       # (labels, descriptions).
   374    361   
   375    362       set names {}
   376    363       set descs {}
   377    364       if {[dict exists $cmds $path]} {
   378         -	foreach def [lsort -dict -unique [dict get $cmds $path]] {
          365  +	foreach def [lsort -dict -unique -index 0 [dict get $cmds $path]] {
   379    366   	    lassign $def syntax desc
   380    367   	    lappend names $syntax
   381    368   	    lappend descs $desc
   382    369   	}
   383    370       }
   384    371       set labels [cmdr util padr $names]
   385    372   
................................................................................
   480    467   	    continue
   481    468   	}
   482    469   
   483    470   	# Exclude officers from the categorized help. They can only be
   484    471   	# a source of shared options. Shared options are collected in
   485    472   	# a separate structure.
   486    473   	if {![info exists action] && [dict size $options]} {
   487         -	    set opts($name) $options
          474  +	    set opts($name) [::list $options $parameters $opt2para]
   488    475   	    continue
   489    476   	}
   490    477   
   491    478   
   492    479   	if {![llength $sections]} {
   493    480   	    lappend sections Miscellaneous
   494    481   	}
................................................................................
   505    492   	}
   506    493       }
   507    494   
   508    495       # Options for the root => global options, put into the section tree.
   509    496       # We are ignoring deeper shared options.
   510    497   
   511    498       if {[info exists opts($root)]} {
   512         -	set options $opts($root)
          499  +	lassign $opts($root) options parameters opt2para
   513    500   
   514    501   	set category {Global Options}
   515    502   	lappend sections $category
   516    503   	set category [::list $category]
   517         -	foreach {o d} $options {
          504  +	foreach {o d} [::cmdr util dictsort $options] {
          505  +	    set o [OptionName $o parameters opt2para]
   518    506   	    lappend cmds($category) [::list $o [string trim $d]]
   519    507   	    LinkParent $category
   520    508   	}
   521    509   
   522    510   	unset opts($root)
   523    511       }
   524    512   
................................................................................
   526    514       # parray subc
   527    515       # parray cmds
   528    516       # parray opts
   529    517       # puts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   530    518   
   531    519       ::list [array get subc] [array get cmds]
   532    520   }
          521  +
          522  +proc ::cmdr::help::format::OptionName {oname pv ov} {
          523  +    upvar 1 $pv parameters $ov opt2para
          524  +
          525  +    # Inspect the parameter and determine of the option
          526  +    # requires an argument. If yes, suitably extend the
          527  +    # definition key of the option list.
          528  +
          529  +    set pname [dict get $opt2para $oname]
          530  +    set vt    [dict get $parameters $pname validator]
          531  +
          532  +    if {$vt ne "::cmdr::validate::boolean"} {
          533  +	if {[dict exists $parameters $pname arglabel]} {
          534  +	    set plabel [dict get $parameters $pname arglabel]
          535  +	} else {
          536  +	    set plabel [dict get $parameters $pname label]
          537  +	}
          538  +	append oname " [string toupper $plabel]"
          539  +    }
          540  +
          541  +    return $oname
          542  +}
   533    543   
   534    544   proc ::cmdr::help::format::LinkParent {category} {
   535    545       if {![llength $category]} return
   536    546       upvar 1 subc subc
   537    547       set parent [lreverse [lassign [lreverse $category] leaf]]
   538    548       lappend subc($parent) $leaf
   539    549       LinkParent $parent