cmdr
Check-in [288c34780b]
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:Move the p-name helper command of validate::common into the parameter class, as a convenience method.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 288c34780b54396ed7b00f7fb2d1df4c462f41cc
User & Date: aku 2014-04-23 05:39:22
Context
2014-05-16
00:29
cmdr::actor - New feature "common -extend", enabling extension of a block instead of overwriting it. check-in: 7ab77ead21 user: aku tags: trunk
2014-05-05
18:52
cmdr::help::json, cmdr::help::tcl - Fixed handling of category with sub-categories, but no commands. Bumped to version 1.0.1. check-in: b5c4809789 user: andreask tags: trunk
2014-04-23
05:39
Move the p-name helper command of validate::common into the parameter class, as a convenience method. check-in: 288c34780b user: aku tags: trunk
2014-04-22
06:56
Merged branch back, making the channel v-types official. check-in: c7a27f1422 user: aku tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to parameter.tcl.

   152    152   	if {$myiscmdline} { return "option" }
   153    153   	return "state"
   154    154       }
   155    155   
   156    156       # Identification and help. Add context name into it?
   157    157       method name        {} { return $myname }
   158    158       method label       {} { return $mylabel }
          159  +
          160  +    method the-name {} {
          161  +	if {[my type] eq "option"} {
          162  +	    return [my flag]
          163  +	} else {
          164  +	    return $mylabel
          165  +	}
          166  +    }
          167  +
   159    168       method description {{detail {}}} {
   160    169   	if {($detail ne {}) && [dict exists $myflags $detail]} {
   161    170   	    switch -exact -- [dict get $myflags $detail] {
   162    171   		primary  {}
   163    172   		alias    { return "Alias of [my Option $myname]." }
   164    173   		inverted { return "Complementary alias of [my Option $myname]." }
   165    174   	    }
................................................................................
  1203   1212   	myisundefined mynopromote
  1204   1213   
  1205   1214       # # ## ### ##### ######## #############
  1206   1215   }
  1207   1216   
  1208   1217   # # ## ### ##### ######## ############# #####################
  1209   1218   ## Ready
  1210         -package provide cmdr::parameter 1.1
         1219  +package provide cmdr::parameter 1.2

Changes to vcommon.tcl.

    36     36       namespace ensemble create
    37     37   }
    38     38   
    39     39   namespace eval ::cmdr::validate::common {
    40     40       namespace export \
    41     41   	complete-enum complete-glob ok-directory \
    42     42   	fail fail-unknown-thing fail-known-thing \
    43         -	p-name lead-in
           43  +	lead-in
    44     44       namespace ensemble create
    45     45   }
    46     46   
    47     47   # # ## ### ##### ######## ############# #####################
    48     48   
    49     49   debug define cmdr/validate/common
    50     50   debug level  cmdr/validate/common
................................................................................
    53     53   # # ## ### ##### ######## ############# #####################
    54     54   ## Different forms of validation failure messages
    55     55   
    56     56   proc ::cmdr::validate::common::fail {p code type x {context {}}} {
    57     57       # Generic failure: "Expected foo, got x".
    58     58       debug.cmdr/validate/common {}
    59     59   
    60         -    append msg "Expected $type for [$p type] \"[p-name $p]\"$context,"
           60  +    append msg "Expected $type for [$p type] \"[$p the-name]\"$context,"
    61     61       append msg " got \"$x\""
    62     62   
    63     63       return -code error -errorcode [list CMDR VALIDATE {*}$code] $msg
    64     64   }
    65     65   
    66     66   proc ::cmdr::validate::common::fail-unknown-thing {p code type x {context {}}} {
    67     67       # Specific failure for a named thing: Expected existence, found it missing.
    68     68       debug.cmdr/validate/common {}
    69     69   
    70         -    append msg "Found a problem with [$p type] \"[p-name $p]\":"
           70  +    append msg "Found a problem with [$p type] \"[$p the-name]\":"
    71     71       append msg " [lead-in $type] \"$x\" does not exist$context."
    72     72       append msg " Please use a different value."
    73     73   
    74     74       return -code error -errorcode [list CMDR VALIDATE {*}$code] $msg
    75     75   }
    76     76   
    77     77   proc ::cmdr::validate::common::fail-known-thing {p code type x {context {}}} {
    78     78       # Specific failure for a named thing: Expected non-existence, found a definition.
    79     79       debug.cmdr/validate/common {}
    80     80   
    81         -    append msg "Found a problem with [$p type] \"[p-name $p]\":"
           81  +    append msg "Found a problem with [$p type] \"[$p the-name]\":"
    82     82       append msg " [lead-in $type] named \"$x\" already exists$context."
    83     83       append msg " Please use a different name."
    84     84   
    85     85       return -code error -errorcode [list CMDR VALIDATE {*}$code] $msg
    86     86   }
    87     87   
    88     88   # # ## ### ##### ######## ############# #####################
................................................................................
    96     96   	set lead {An }
    97     97       } else {
    98     98   	set lead {A }
    99     99       }
   100    100       return $lead$type
   101    101   }
   102    102   
   103         -proc ::cmdr::validate::common::p-name {p} {
   104         -    if {[$p type] eq "option"} {
   105         -	return [$p flag]
   106         -    } else {
   107         -	return [$p label]
   108         -    }
   109         -}
   110         -
   111    103   # # ## ### ##### ######## ############# #####################
   112    104   
   113    105   proc ::cmdr::validate::common::complete-enum {choices nocase buffer} {
   114    106       # As a helper function for command completion printing anything
   115    107       # here would mix with the output of linenoise. Do that only on
   116    108       # explicit request (level 10).
   117    109       debug.cmdr/validate/common {} 10