Browse Source

punk::ns and punk::args better processing of ensemble commands with leading parameters, documentation and layout improvements

master
Julian Noble 3 months ago
parent
commit
b368ce51ac
  1. 4
      src/modules/argparsingtest-999999.0a1.0.tm
  2. 50
      src/modules/punk-0.1.tm
  3. 40
      src/modules/punk/ansi-999999.0a1.0.tm
  4. 346
      src/modules/punk/args-999999.0a1.0.tm
  5. 2
      src/modules/punk/args-buildversion.txt
  6. 1956
      src/modules/punk/args/moduledoc/tclcore-999999.0a1.0.tm
  7. 4
      src/modules/punk/args/moduledoc/tkcore-999999.0a1.0.tm
  8. 88
      src/modules/punk/imap4-999999.0a1.0.tm
  9. 111
      src/modules/punk/lib-999999.0a1.0.tm
  10. 2
      src/modules/punk/lib-buildversion.txt
  11. 155
      src/modules/punk/netbox-999999.0a1.0.tm
  12. 8
      src/modules/punk/netbox/man-999999.0a1.0.tm
  13. 232
      src/modules/punk/ns-999999.0a1.0.tm
  14. 2
      src/modules/punk/path-999999.0a1.0.tm
  15. 17
      src/modules/test/punk/#modpod-args-999999.0a1.0/args-0.1.5_testsuites/args/args.test
  16. 30
      src/modules/test/punk/#modpod-lib-999999.0a1.0/lib-0.1.3_testsuites/lib/compat.test
  17. 79
      src/modules/test/punk/#modpod-lib-999999.0a1.0/lib-0.1.3_testsuites/lib/index_functions.test
  18. 0
      src/modules/test/punk/#modpod-lib-999999.0a1.0/lib-0.1.3_testsuites/tests/compat.test#..+lib+compat.test.fauxlink
  19. 0
      src/modules/test/punk/#modpod-lib-999999.0a1.0/lib-0.1.3_testsuites/tests/index.test#..+lib+index_functions.test.fauxlink
  20. 211
      src/modules/test/punk/#modpod-lib-999999.0a1.0/lib-999999.0a1.0.tm
  21. 3
      src/modules/test/punk/lib-buildversion.txt
  22. 122
      src/modules/textblock-999999.0a1.0.tm

4
src/modules/argparsingtest-999999.0a1.0.tm

@ -297,7 +297,7 @@ namespace eval argparsingtest {
}
punk::args::define {
@id -id ::test1_punkargs_by_id
@id -id ::argparsingtest::test1_punkargs_by_id
@cmd -name argtest4 -help "test of punk::args::parse comparative performance"
@opts -anyopts 0
-return -default string -type string
@ -314,7 +314,7 @@ namespace eval argparsingtest {
@values
}
proc test1_punkargs_by_id {args} {
set argd [punk::args::get_by_id ::test1_punkargs_by_id $args]
set argd [punk::args::get_by_id ::argparsingtest::test1_punkargs_by_id $args]
return [tcl::dict::get $argd opts]
}

50
src/modules/punk-0.1.tm

@ -577,18 +577,18 @@ namespace eval punk {
@leaders -min 0 -max 0
@opts
-returnlines -type string -typesynopsis matched|all -default breaksandmatches -choicecolumns 1 -choices {matched all breaksandmatches} -choicelabels {
"matched"\
" Return only lines that matched."
"breaksandmatches"\
" Return configured --break= lines in between non-consecutive matches"
"all"\
" Return all lines.
This has a similar effect to the 'grep' trick of matching on 'pattern|$'
(The $ matches all lines that have an end; ie all lines, but there is no
associated character to which to apply highlighting)
except that when instead using -returnlines all with --line-number, the *
indicator after the linenumber will only be highlighted for lines with matches,
and the following matchcount will indicate zero for non-matching lines."
"matched"\
" Return only lines that matched."
"breaksandmatches"\
" Return configured --break= lines in between non-consecutive matches"
"all"\
" Return all lines.
This has a similar effect to the 'grep' trick of matching on 'pattern|$'
(The $ matches all lines that have an end; ie all lines, but there is no
associated character to which to apply highlighting)
except that when instead using -returnlines all with --line-number, the *
indicator after the linenumber will only be highlighted for lines with matches,
and the following matchcount will indicate zero for non-matching lines."
}
-B|--before-context= -parsekey "--before-context" -default 0 -type integer -typesynopsis num
-C|--context= -parsekey "--context" -default 0 -type integer -typesynopsis num -help\
@ -609,9 +609,9 @@ namespace eval punk {
"
-ansistrip -type none -help\
"Strip all ansi codes from the input string before processing.
This is not necessary for regex matching purposes, as the matching is always
performed on the ansistripped characters anyway, but by stripping ANSI, the
result only has the ANSI supplied by the -highlight option."
This is not necessary for regex matching purposes, as the matching is always
performed on the ansistripped characters anyway, but by stripping ANSI, the
result only has the ANSI supplied by the -highlight option."
#-n|--line-number as per grep utility, except that we include a * for matches
-n|--line-number -type none -help\
@ -7153,8 +7153,8 @@ namespace eval punk {
-exclude_punctlines -default 1 -type boolean
-show_largest -default 0 -type integer -help\
"Report the top largest linecount files.
The value represents the number of files
to report on."
The value represents the number of files
to report on."
} "
#we could map away whitespace and use string is punct - but not as flexible? review
-punctchars -default { [list \{ \} \" \\ - _ + = . > , < ' : \; ` ~ ! @ # \$ % ^ & * \[ \] ( ) | / ?] }
@ -7384,7 +7384,7 @@ namespace eval punk {
#dict of list-len 2 is equiv to dict of dict with one keyval pair
#--------------------------------
#!!!todo fix - linedict is unfinished and non-functioning
#linedict based on indents
@ -7615,23 +7615,23 @@ namespace eval punk {
-showcount -type boolean -default 1 -help\
"Display a leading indicator in brackets showing the number of arg values present."
-ansi -type integer -default 1 -nocase 1 -choices {0 1 2 VIEW 3 VIEWCODES 4 VIEWSTYLES} -choicelabels {
0 "Strip ANSI codes from display
0 " Strip ANSI codes from display
of values. The disply output will
still be colourised if -ansibase has
not been set to empty string or
[a+ normal]. The stderr or stdout
channels may also have an ansi colour.
(see 'colour off' or punk::config)"
1 "Leave value as is"
2 "Display the ANSI codes and
1 " Leave value as is"
2 " Display the ANSI codes and
other control characters inline
with replacement indicators.
e.g esc, newline, space, tab"
VIEW "Alias for 2"
3 "Display as per 2 but with
VIEW " Alias for 2"
3 " Display as per 2 but with
colourised ANSI replacement codes."
VIEWCODES "Alias for 3"
4 "Display ANSI and control
VIEWCODES " Alias for 3"
4 " Display ANSI and control
chars in default colour, but
apply the contained ansi to
the text portions so they display

40
src/modules/punk/ansi-999999.0a1.0.tm

@ -3287,31 +3287,32 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
#indent of 1 space is important for clarity in i -return string a+ output
dict set SGR_samples $k " [punk::ansi::a+ $k]sample\x1b\[m"
}
set SGR_help\
{SGR code from the list below, or an integer corresponding to the code e.g 31 = red.
A leading capital letter indicates a codename applies to the background colour.
Other accepted codes are:
term-<int> Term-<int> foreground/background where int is 0-255 terminal color
term-<termcolour> Term-<termcolour> foreground/background
A leading capital letter indicates a codename applies to the background colour.
Other accepted codes are:
term-<int> Term-<int> foreground/background where int is 0-255 terminal color
term-<termcolour> Term-<termcolour> foreground/background
web-<webcolour> Web-<webcolour>
web-<webcolour> Web-<webcolour>
x11-<xllcolour> X11-<x11colour>
x11-<xllcolour> X11-<x11colour>
tk-<tkcolour> Tk-<tkcolour>
tk-<tkcolour> Tk-<tkcolour>
rgb-<r>-<g>-<b> Rgb-<r>-<g>-<b> foreground/background where <r> <g> <b> are the
0-255 int values for red, green and blue.
rgb#<hexcode> Rgb#<hexcode> where <hexcode> is a 6 char hex colour e.g rgb#C71585
rgb-<r>-<g>-<b> Rgb-<r>-<g>-<b> foreground/background where <r> <g> <b> are the
0-255 int values for red, green and blue.
rgb#<hexcode> Rgb#<hexcode> where <hexcode> is a 6 char hex colour e.g rgb#C71585
The acceptable values for colours can be queried using
punk::ansi::a? term
punk::ansi::a? web
punk::ansi::a? x11
punk::ansi::a? tk
The acceptable values for colours can be queried using
punk::ansi::a? term
punk::ansi::a? web
punk::ansi::a? x11
punk::ansi::a? tk
Example to set foreground red and background cyan followed by a reset:
set str \"[a+ red Cyan]sample text[a]\"
Example to set foreground red and background cyan followed by a reset:
set str \"[a+ red Cyan]sample text[a]\"
}
lappend PUNKARGS [list {
@id -id ::punk::ansi::a+
@ -3325,6 +3326,7 @@ Brightblack 100 Brightred 101 Brightgreen 102 Brightyellow 103 Brightblu
-choicelabels {%choicelabels%}\
-choicecolumns 5 -choiceprefix 0 -choicerestricted 0 -help\
"%SGR_help%"
#note SGR_help string has same level of indent as placeholder
}]]
lappend PUNKARGS [list {
@ -8140,7 +8142,7 @@ tcl::namespace::eval punk::ansi::ansistring {
#return empty string for each index that is out of range
#review - this is possibly too slow to be very useful as is.
# consider converting to oo and maintaining state of ansisplits so we don't repeat relatively expensive operations for same string
#see also punk::lindex_resolve / punk::lindex_get for ways to handle tcl list/string indices without parsing them.
#see also punk::lib::lindex_resolve / punk::lindex_get for ways to handle tcl list/string indices without parsing them.
proc INDEXABSOLUTE {string args} {
set payload_len -1 ;# -1 as token to indicate we haven't calculated it yet (only want to call it once at most)
set testindices [list]
@ -8169,6 +8171,8 @@ tcl::namespace::eval punk::ansi::ansistring {
} else {
set offset 0
}
#2025 -BROKEN - doesn't handle indices with both + and -
#see updated punk::lib::lindex_resolve
#by now, if op = + then offset = 0 so we only need to handle the minus case
if {$payload_len == -1} {
set payload_len [punk::ansi::ansistring::length $string] ;#a little bit wasteful - but hopefully no big deal

346
src/modules/punk/args-999999.0a1.0.tm

@ -274,7 +274,13 @@ tcl::namespace::eval ::punk::args {}
# Base namespace
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
tcl::namespace::eval punk::args {
package require punk::assertion
#if 'package forget' was called on this package (e.g when loading test::punk::args) then assert may already exist in the namespace
#procs can be overridden silently, but not imports
catch {
namespace import ::punk::assertion::assert
}
punk::assertion::active 1
variable PUNKARGS ;#list of our own punk::args function argument definitions - loaded with punk::args::define at the end.
@ -607,6 +613,13 @@ tcl::namespace::eval punk::args {
If <range> allows more than one choice the value is a list
consisting of items in the choices made available through
entries in -choices/-choicegroups.
-unindentedfields {<list>}
for fields with multi-line values, tell the resolver to treat
them as unindented. ie do no indent/unindent processing of
whitespace in the values. In a definition script, these fields
should have their value strings placed with reference to the
left margin in the source code. ie all whitespace in the source
is preserved.
-minsize (type dependant)
-maxsize (type dependant)
-range (type dependant - only valid if -type is a single item)
@ -651,11 +664,14 @@ tcl::namespace::eval punk::args {
%G%#The following option defines a flag style option (solo)%R%
-flag1 -default 0 -type none -help\
"Info about flag1
subsequent help lines auto-dedented by whitespace to left
of corresponding record start (in this case -flag1)
+ first 4 spaces if they are all present.
subsequent help lines assume indent of 4 spaces with
reference to the record start (in this case -flag1).
This line has no extra indent relative to first line 'Info about flag1'
This line indented a further 6 chars"
%G%#To disable source indent processing, add for example
%G%# -unindentedfields {-help} to the argument line
%G%#This will require aligning the -help text with reference to the left
%G%#margin in the source of the definition.
@values -min 1 -max -1
%G%#Items that don't begin with * or - are value definitions%R%
@ -677,6 +693,7 @@ tcl::namespace::eval punk::args {
-choiceprefix 1\
-choicerestricted 1\
-choicemultiple {1 1}\
-unindentedfields {}\
-multiple 0\
-regexprepass {}\
-validationtransform {}\
@ -692,6 +709,7 @@ tcl::namespace::eval punk::args {
-choiceprefix 1\
-choicerestricted 1\
-choicemultiple {1 1}\
-unindentedfields {}\
-multiple 0\
-regexprepass {}\
-validationtransform {}\
@ -711,6 +729,7 @@ tcl::namespace::eval punk::args {
-choiceprefix 1\
-choicerestricted 1\
-choicemultiple {1 1}\
-unindentedfields {}\
-multiple 0\
-regexprepass {}\
-validationtransform {}\
@ -943,18 +962,40 @@ tcl::namespace::eval punk::args {
foreach a $textargs {
lappend normargs [tcl::string::map {\r\n \n} $a]
}
set optionspecs [join $normargs \n]
if {[string first \$\{ $optionspecs] > 0} {
if {$defspace ne ""} {
#normal/desired case
#set optionspecs [namespace eval $defspace [list punk::args::lib::tstr -return string -eval 1 -allowcommands $optionspecs]]
set optionspecs [namespace eval $defspace [list punk::args::lib::tstr -return string -eval 1 -paramindents none -allowcommands $optionspecs]]
} else {
#todo - deprecate/stop from happening?
puts stderr "punk::args::resolve calling tstr for id:$id with no known definition space (-defspace empty)"
set optionspecs [uplevel $LVL [list punk::args::lib::tstr -return string -eval 1 -allowcommands $optionspecs]]
}
}
set optionspecs [list]
foreach block $normargs {
if {[string first \$\{ $block] > 0} {
if {$defspace ne ""} {
set block [namespace eval $defspace [list punk::args::lib::tstr -return string -eval 1 -allowcommands -undent 1 $block]]
} else {
puts stderr "punk::args::resolve calling tstr for id:$id with no known definition space (-defspace empty)"
set block [uplevel $LVL [list punk::args::lib::tstr -return string -eval 1 -allowcommands $block]]
}
}
lappend optionspecs $block
}
set optionspecs [join $optionspecs \n]
#set optionspecs [join $normargs \n]
#if {[string first \$\{ $optionspecs] > 0} {
# if {$defspace ne ""} {
# #normal/desired case
# #JJJ
# #set optionspecs [namespace eval $defspace [list punk::args::lib::tstr -return string -eval 1 -allowcommands $optionspecs]]
# #set optionspecs [namespace eval $defspace [list punk::args::lib::tstr -return string -eval 1 -paramindents none -allowcommands $optionspecs]]
# set optionspecs [namespace eval $defspace [list punk::args::lib::tstr -return string -eval 1 -allowcommands -undent 1 $optionspecs]]
# #set optionspecs [list]
# #foreach spec $optionspecs {
# # set spec [namespace eval $defspace [list punk::args::lib::tstr -return string -eval 1 -allowcommands -undent 1 $spec]]
# # lappend optionspecs $spec
# #}
# } else {
# #todo - deprecate/stop from happening?
# puts stderr "punk::args::resolve calling tstr for id:$id with no known definition space (-defspace empty)"
# set optionspecs [uplevel $LVL [list punk::args::lib::tstr -return string -eval 1 -allowcommands $optionspecs]]
# }
#}
} else {
if {[tcl::dict::exists $argdefcache_unresolved $cache_key]} {
@ -979,9 +1020,9 @@ tcl::namespace::eval punk::args {
# -arg -choices {${$DYN_CHOICES}} -help "${$RED}important info${$RST}"
#}
if {$defspace ne ""} {
#set optionspecs [namespace eval $defspace [list punk::args::lib::tstr -return string -eval 1 -allowcommands $optionspecs]]
set optionspecs [namespace eval $defspace [list punk::args::lib::tstr -return string -eval 1 -allowcommands $optionspecs]]
#JJJ - review
set optionspecs [namespace eval $defspace [list punk::args::lib::tstr -return string -eval 1 -allowcommands -paramindents none $optionspecs]]
#set optionspecs [namespace eval $defspace [list punk::args::lib::tstr -return string -eval 1 -allowcommands -paramindents none $optionspecs]]
}
#REVIEW - join also serves to unescape things such as \$\{$x\} \$\{[cmd]\} without subst'ing or evaling (?)
if {[string first \$\{ $optionspecs] > 0} {
@ -1023,21 +1064,25 @@ tcl::namespace::eval punk::args {
set linebuild ""
set linelist [split $optionspecs \n]
set lastindent ""
set record_base_indent "" ;#indent of first line in the record e.g a parameter or @directive record which will often have subsequent lines further indented.
#find the first record's base indent
foreach ln $linelist {
if {[tcl::string::trim $ln] eq ""} {continue}
regexp {(\s*).*} $ln _all lastindent
regexp {(\s*).*} $ln _all record_base_indent
break ;#break at first non-empty
}
#puts "indent1:[ansistring VIEW $lastindent]"
set in_record 0
#puts "indent1:[ansistring VIEW $record_base_indent]"
set in_record_continuation 0
if {[catch {package require punk::ansi} errM]} {
set has_punkansi 0
} else {
set has_punkansi 1
}
set record_id 0
set record_line 0 ;#incremented at each incomplete record, set to zero after processing a complete record
foreach rawline $linelist {
set recordsofar [tcl::string::cat $linebuild $rawline]
#puts stderr "$record_line $rawline"
set record_so_far [tcl::string::cat $linebuild $rawline]
#ansi colours can stop info complete from working (contain square brackets)
#review - when exactly are ansi codes allowed/expected in record lines.
# - we might reasonably expect them in default values or choices or help strings
@ -1045,53 +1090,95 @@ tcl::namespace::eval punk::args {
# - eg set line "set x \"a[a+ red]red[a]\""
# - 'info complete' will report 0, and subst would require -nocommand option or it will complain of missing close-bracket
if {$has_punkansi} {
set test_complete [punk::ansi::ansistrip $recordsofar]
set test_record [punk::ansi::ansistrip $record_so_far]
} else {
#review
#we only need to strip enough to stop interference with 'info complete'
set test_complete [string map [list \x1b\[ ""] $recordsofar]
set test_record [string map [list \x1b\[ ""] $record_so_far]
}
if {![tcl::info::complete $test_complete]} {
if {![tcl::info::complete $test_record]} {
#append linebuild [string trimleft $rawline] \n
if {$in_record} {
#trim only the whitespace corresponding to last record indent or lastindent + 4 spaces - not all whitespace on left
if {$in_record_continuation} {
#incr record_line
#if {$record_line == 1} {
# #first continuation line sets the indent
#}
#///
#if {[tcl::string::first "$record_base_indent " $rawline] == 0} {
# set trimmedline [tcl::string::range $rawline [tcl::string::length "$record_base_indent "] end]
# append linebuild $trimmedline \n
#} else {
# append linebuild $rawline \n
#}
if {[tcl::string::first $record_base_indent $rawline] == 0} {
set trimmedline [tcl::string::range $rawline [tcl::string::length $record_base_indent] end]
append linebuild $trimmedline \n
} else {
append linebuild $rawline \n
}
#trim only the whitespace corresponding to last record indent or record_base_indent + 4 spaces - not all whitespace on left
#this allows alignment of multiline help strings to left margin whilst maintaining a visual indent in source form.
#Aligning subsequent lines with the record, or aligning 4 spaces in are equivalent.
#ie to indent lines further - whitespace should be added 4+ columns in from the record-line start position.
#(this leaves an oddity if indenting is only 1 2 or 3 spaces mixed with longer indents as we don't check for it.. REVIEW)
#(note string first "" $str is fast and returns -1)
if {[tcl::string::first "$lastindent " $rawline] == 0} {
set trimmedline [tcl::string::range $rawline [tcl::string::length "$lastindent "] end]
append linebuild $trimmedline \n
} elseif {[tcl::string::first $lastindent $rawline] == 0} {
set trimmedline [tcl::string::range $rawline [tcl::string::length $lastindent] end]
append linebuild $trimmedline \n
} else {
append linebuild $rawline \n
}
#if {[tcl::string::first "$record_base_indent " $rawline] == 0} {
# set trimmedline [tcl::string::range $rawline [tcl::string::length "$record_base_indent "] end]
# append linebuild $trimmedline \n
#} elseif {[tcl::string::first $record_base_indent $rawline] == 0} {
# set trimmedline [tcl::string::range $rawline [tcl::string::length $record_base_indent] end]
# append linebuild $trimmedline \n
#} else {
# append linebuild $rawline \n
#}
} else {
set in_record 1
regexp {(\s*).*} $rawline _all lastindent
#puts "indent: [ansistring VIEW -lf 1 $lastindent]"
assert {$record_line == 0} punk::args::resolve record_line
regexp {(\s*).*} $rawline _all record_base_indent
#puts "indent: [ansistring VIEW -lf 1 $record_base_indent]"
#puts "indent from rawline:$rawline "
append linebuild $rawline \n
set in_record_continuation 1
}
incr record_line
} else {
set in_record 0
#trim only the whitespace corresponding to last record indent or lastindent + 4 spaces - not all whitespace on left
if {[tcl::string::first "$lastindent " $rawline] == 0} {
set trimmedline [tcl::string::range $rawline [tcl::string::length "$lastindent "] end]
append linebuild $trimmedline
} elseif {[tcl::string::first $lastindent $rawline] == 0} {
set trimmedline [tcl::string::range $rawline [tcl::string::length $lastindent] end]
append linebuild $trimmedline
#either we're on a single line record, or last line of multiline record
if {$record_line != 0} {
#trim only the whitespace corresponding to record_base_indent or record_base_indent + 4 spaces - not all whitespace on left
#if {[tcl::string::first "$record_base_indent " $rawline] == 0} {
# set trimmedline [tcl::string::range $rawline [tcl::string::length "$record_base_indent "] end]
# append linebuild $trimmedline
#} elseif {[tcl::string::first $record_base_indent $rawline] == 0} {
# set trimmedline [tcl::string::range $rawline [tcl::string::length $record_base_indent] end]
# append linebuild $trimmedline
#} else {
# append linebuild $rawline
#}
if {[tcl::string::first $record_base_indent $rawline] == 0} {
set trimmedline [tcl::string::range $rawline [tcl::string::length $record_base_indent] end]
append linebuild $trimmedline
} else {
append linebuild $rawline
}
} else {
append linebuild $rawline
}
lappend records $linebuild
set linebuild ""
#prep for next record
set in_record_continuation 0
incr record_id
set record_line 0
}
}
#puts stderr 1[lindex $records 1]
#puts stderr 4[lindex $records 4]
#puts stderr 5[lindex $records 5]
#puts stderr 6[lindex $records 6]
set cmd_info {}
set package_info {}
set id_info {} ;#e.g -children <list> ??
@ -1344,6 +1431,8 @@ tcl::namespace::eval punk::args {
#e.g -name <str>
# -summary <str>
# -help <str>
#
# -cmdtype <str>
set cmd_info [dict merge $cmd_info $at_specs]
}
doc {
@ -1382,6 +1471,7 @@ tcl::namespace::eval punk::args {
#if no -max explicitly specified, and llength OPT_NAMES == 0 and OPT_ANY == 0 - -max will be set to 0 below.
dict set F $fid OPT_MAX $v
}
-unindentedfields -
-minsize - -maxsize -
-choices - -choicegroups - -choicemultiple - -choicecolumns - -choicelabels - -choiceinfo -
-choiceprefix - -choiceprefixdenylist - -choiceprefixreservelist - -choicerestricted {
@ -1485,6 +1575,7 @@ tcl::namespace::eval punk::args {
-any -anyopts -arbitrary -form -minsize -maxsize -choices -choicegroups -choicemultiple -choicecolumns -choicelabels -choiceinfo\
-type -range -typeranges -default -defaultdisplaytype -typedefaults
-choiceprefix -choiceprefixdenylist -choiceprefixreservelist -choicerestricted -nocase\
-unindentedfields\
-nominsize -nomaxsize -norange -nochoices -nochoicelabels\
-type -optional -allow_ansi -validate_ansistripped -strip_ansi -multiple -prefix\
-regexprepass -regexprefail -regexprefailmsg -validationtransform\
@ -1584,6 +1675,7 @@ tcl::namespace::eval punk::args {
-typeranges {
tcl::dict::set tmp_leaderspec_defaults -range $v
}
-unindentedfields -
-minsize - -maxsize -
-choices - -choicegroups - -choicemultiple - -choicecolumns - -choiceprefixdenylist - -choiceprefixreservelist - -nocase {
#review - only apply to certain types?
@ -1622,6 +1714,7 @@ tcl::namespace::eval punk::args {
-choices -choicegroups -choicemultiple -choicecolumns -choicelabels -choiceinfo\
-choiceprefix -choiceprefixdenylist -choiceprefixreservelist -choicerestricted\
-nocase -nominsize -nomaxsize -norange -nochoices -nochoicelabels\
-unindentedfields\
-type -optional -allow_ansi -validate_ansistripped -strip_ansi -multiple\
-regexprepass -regexprefail -regexprefailmsg -validationtransform\
-unnamed\
@ -1662,6 +1755,7 @@ tcl::namespace::eval punk::args {
#set val_max $v
dict set F $fid VAL_MAX $v
}
-unindentedfields -
-minsize - -maxsize - -choices - -choicemultiple - -choicecolumns -
-choicelabels - -choiceprefix - -choiceprefixdenylist - -choiceprefixreservelist - -choicerestricted - -nocase {
#review - only apply to certain types?
@ -1741,6 +1835,7 @@ tcl::namespace::eval punk::args {
-choices -choicegroups -choicemultiple -choicecolumns -choicelabels -choiceinfo\
-choiceprefix -choiceprefixdenylist -choiceprefixreservelist -choicerestricted\
-nocase\
-unindentedfields\
-nominsize -nomaxsize -norange -nochoices -nochoicelabels\
-optional -allow_ansi -validate_ansistripped -strip_ansi -multiple\
-regexprepass -regexprefail -regexprefailmsg -validationtransform\
@ -1878,13 +1973,16 @@ tcl::namespace::eval punk::args {
#set all_choices [_resolve_get_record_choices]
foreach fid $record_form_ids {
if {[dict get $F $fid argspace] eq "leaders"} {
dict set F $fid argspace "options"
} elseif {[dict get $F $fid argspace] eq "values"} {
error "punk::args::resolve - invalid placement of line '$rec' - must come before @values (command form:'$fid') @id:$DEF_definition_id"
switch -exact -- [dict get $F $fid argspace] {
leaders {
dict set F $fid argspace "options"
}
values {
error "punk::args::resolve - invalid placement of line '$rec' - must come before @values (command form:'$fid') @id:$DEF_definition_id"
}
}
set record_type option
dict set F $fid OPT_NAMES [list {*}[dict get $F $fid OPT_NAMES] $argname]
}
@ -2062,6 +2160,7 @@ tcl::namespace::eval punk::args {
-parsekey - -group {
tcl::dict::set spec_merged -typesynopsis $specval
}
-unindentedfields -
-solo -
-choices - -choicegroups - -choicemultiple - -choicecolumns -
-choiceprefix - -choiceprefixdenylist - -choiceprefixreservelist - -choicerestricted - -choicelabels - -choiceinfo -
@ -2169,6 +2268,7 @@ tcl::namespace::eval punk::args {
-default -defaultdisplaytype -typedefaults\
-minsize -maxsize -choices -choicegroups\
-choicemultiple -choicecolumns -choiceprefix -choiceprefixdenylist -choiceprefixreservelist -choicerestricted\
-unindentedfields\
-nocase -optional -multiple -validate_ansistripped -allow_ansi -strip_ansi -help\
-regexprepass -regexprefail -regexprefailmsg -validationtransform\
-ensembleparameter\
@ -2399,7 +2499,7 @@ tcl::namespace::eval punk::args {
-override dictionary The members of each override sub dictionary are
usually options beginning with a dash. The key 'name' can be used to
override the name of the leader/option/value itself.
e.g
e.g
punk::args::resolved_def -types values -override {version {name version1 -optional 0}} (shared)::package version
"
@leaders -min 0 -max 0
@ -2462,16 +2562,21 @@ tcl::namespace::eval punk::args {
#a definition id must not begin with "-" ??? review
for {set i 0} {$i < [llength $args]} {incr i} {
set a [lindex $args $i]
if {$a in {-type -types}} {
incr i
dict set opts -types [lindex $args $i]
} elseif {[string match -* $a]} {
incr i
dict set opts $a [lindex $args $i]
} else {
set id [lindex $args $i]
set patterns [lrange $args $i+1 end]
break
switch -exact -- $a {
-type - -types {
incr i
dict set opts -types [lindex $args $i]
}
default {
if {[string match -* $a]} {
incr i
dict set opts $a [lindex $args $i]
} else {
set id [lindex $args $i]
set patterns [lrange $args $i+1 end]
break
}
}
}
if {$i == [llength $args]-1} {
punk::args::parse $args withid ::punk::args::resolved_def
@ -3349,6 +3454,7 @@ tcl::namespace::eval punk::args {
#limit colours to standard 16 so that themes can apply to help output
variable arg_error_isrunning
if {$arg_error_isrunning} {
set arg_error_isrunning 0
error "arg_error already running - error in arg_error?\n triggering errmsg: $msg"
}
@ -3518,6 +3624,11 @@ tcl::namespace::eval punk::args {
set cmdname [Dict_getdef $spec_dict cmd_info -name ""]
set cmdsummary [Dict_getdef $spec_dict cmd_info -summary ""]
set cmdhelp [Dict_getdef $spec_dict cmd_info -help ""]
#===========
#unindentedfields ?
set maxundent 4
set cmdhelp [punk::lib::undent " $cmdhelp" $maxundent]
#===========
set docname [Dict_getdef $spec_dict doc_info -name "Manual:"]
set docurl [Dict_getdef $spec_dict doc_info -url ""]
@ -3865,6 +3976,13 @@ tcl::namespace::eval punk::args {
set help ""
if {[dict exists $form_dict OPT_GROUPS $thisgroup -help]} {
set help [dict get $form_dict OPT_GROUPS $thisgroup -help]
#field in @directiveline was -grouphelp
#review - where to specify -unindentedfields for a group? do we really need it?
#if {"-grouphelp" ni $unindentedfields} {
set maxundent 4
set help " $help"
set help [punk::lib::undent $help $maxundent]
#}
}
if {$thisgroup_parsekey eq ""} {
set groupinfo "(documentation group)"
@ -3935,6 +4053,7 @@ tcl::namespace::eval punk::args {
} else {
set default ""
}
set unindentedfields [Dict_getdef $arginfo -unindentedfields {}]
set help [Dict_getdef $arginfo -help ""]
set allchoices_originalcase [list]
set choices [Dict_getdef $arginfo -choices {}]
@ -3979,18 +4098,26 @@ tcl::namespace::eval punk::args {
} else {
set prefixmsg ""
}
set choicelabeldict [Dict_getdef $arginfo -choicelabels {}]
set choiceinfodict [Dict_getdef $arginfo -choiceinfo {}]
set formattedchoices [dict create] ;#use dict rather than array to preserve order
append help "Choices$prefixmsg$casemsg"
set choicelabeldict [Dict_getdef $arginfo -choicelabels {}]
set choiceinfodict [Dict_getdef $arginfo -choiceinfo {}]
set formattedchoices [dict create] ;#use dict rather than array to preserve order
if {$help eq ""} {
#first line of help - no included base of 4 indent is the normal state of first help lines in definitions scripts
#align fully left to distinguish from previous argument help text
append help "Choices$prefixmsg$casemsg"
} else {
#we are on a subsequent line of -help. Indent the usual base of 4 + desired offset
#offset of 2 to align with choices table
append help " Choices$prefixmsg$casemsg"
}
if {$choicemultiple_max > 1 || $choicemultiple_max == -1} {
if {$choicemultiple_max == -1} {
append help \n " The value can be a list of $choicemultiple_min or more of these choices"
append help \n " The value can be a list of $choicemultiple_min or more of these choices"
} else {
if {$choicemultiple_min eq $choicemultiple_max} {
append help \n " The value must be a list of $choicemultiple_min of these choices"
append help \n " The value must be a list of $choicemultiple_min of these choices"
} else {
append help \n " The value can be a list of $choicemultiple_min to $choicemultiple_max of these choices"
append help \n " The value can be a list of $choicemultiple_min to $choicemultiple_max of these choices"
}
}
}
@ -4006,7 +4133,16 @@ tcl::namespace::eval punk::args {
set cdisplay $c
}
if {[dict exists $choicelabeldict $c]} {
append cdisplay \n [dict get $choicelabeldict $c]
#append cdisplay \n [dict get $choicelabeldict $c]
if {"-choicelabels" ni $unindentedfields} {
set maxundent 4
set ctext " [dict get $choicelabeldict $c]"
set ctext [punk::lib::undent $ctext $maxundent]
} else {
set ctext [dict get $choicelabeldict $c]
}
append cdisplay \n $ctext
}
if {[dict exists $parsedvalues $arg] && [dict get $parsedvalues $arg] eq $c} {
dict lappend formattedchoices $groupname [punk::ansi::ansiwrap reverse $cdisplay]
@ -4082,7 +4218,16 @@ tcl::namespace::eval punk::args {
}
set cdisplay "$A_PREFIX[ansistring VIEW $prefix]$A_PREFIXEND[ansistring VIEW $tail]$mk"
if {[dict exists $choicelabeldict $c]} {
append cdisplay \n [dict get $choicelabeldict $c]
#append cdisplay \n [dict get $choicelabeldict $c]
#undent
if {"-choicelabels" ni $unindentedfields} {
set maxundent 4
set ctext " [dict get $choicelabeldict $c]"
set ctext [punk::lib::undent $ctext $maxundent]
} else {
set ctext [dict get $choicelabeldict $c]
}
append cdisplay \n $ctext
}
#puts "-- parsed:$parsedvalues arg:$arg c:$c"
if {[dict exists $parsedvalues $arg] && [dict get $parsedvalues $arg] eq $c} {
@ -4180,9 +4325,9 @@ tcl::namespace::eval punk::args {
}
} else {
if {$groupname eq ""} {
append help \n " " $CLR(errormsg)(no choices defined)$RST
append help \n " " $CLR(errormsg)(no choices defined)$RST
} else {
append help \n " " $CLR(errormsg)(no choices defined for group $groupname)$RST
append help \n " " $CLR(errormsg)(no choices defined for group $groupname)$RST
}
}
}
@ -4202,7 +4347,7 @@ tcl::namespace::eval punk::args {
$obj configure_column $i -blockalign left
incr i
}
append help \n[textblock::join -- " " [$obj print]]
append help \n[textblock::join -- " " [$obj print]] ;#4 for standard source-layout indent + 2
#-------------
#todo - tests
#see special case double reset at end of content in textblock class table get_column_by_index
@ -4227,9 +4372,9 @@ tcl::namespace::eval punk::args {
if {![dict get $arginfo -choicerestricted]} {
#when -choicemultiple - the -type refers to each selection
if {[dict get $arginfo -type] eq "string"} {
append help "\n (values not in defined choices are allowed)"
append help "\n (values not in defined choices are allowed)"
} else {
append help "\n (values not in defined choices are allowed but must by of type: [dict get $arginfo -type])"
append help "\n (values not in defined choices are allowed but must by of type: [dict get $arginfo -type])"
}
}
}
@ -4266,6 +4411,14 @@ tcl::namespace::eval punk::args {
}
}
# =============================================
#REVIEW
if {"-help" ni $unindentedfields} {
# see punk::args::resolve
set maxundent 4
set help [punk::lib::undent " $help" $maxundent]
}
# =============================================
if {$use_table} {
if {$hint ne ""} {
set col1 $argshow\n$hint
@ -4934,7 +5087,7 @@ tcl::namespace::eval punk::args {
set clause_member_optional 0
}
set tp [string trim $tp ?]
switch -glob $tp {
switch -glob -- $tp {
literal* {
set litinfo [string range $tp 7 end]
set match [string range $litinfo 1 end-1]
@ -5226,7 +5379,7 @@ tcl::namespace::eval punk::args {
#more complex type_expressions would require a bracketing syntax - (and probably pre-parsing)
#or perhaps more performant, RPN to avoid bracket parsing
#if literal(..), literalprefix(..), stringstartswith(..) etc can have pipe symbols and brackets etc - we can't just use split
#if we require -type to always be treated as a list - and if an element is length 1 - require it to
#if we require -type to always be treated as a list - and if an element is length 1 - require it to
#have properly balanced brackets that don't contain | ( ) etc we can simplify - REVIEW
#consider:
@ -6239,7 +6392,7 @@ tcl::namespace::eval punk::args {
#no pass for this clause - fetch first? error and raise
#todo - return error containing clause_indices so we can report more than one failing element at once?
foreach e $clauseresult {
switch -exact [lindex $e 0] {
switch -exact -- [lindex $e 0] {
errorcode {
#errorcode <list> msg <string
set errorcode [lindex $e 1]
@ -7157,7 +7310,7 @@ tcl::namespace::eval punk::args {
set nameidx 0
if {$can_have_leaders} {
if {$LEADER_TAKEWHENARGSMODULO} {
#assign set of leaders purely based on number of total args
#assign set of leaders purely based on number of total args
set take [expr {[llength $remaining_rawargs] % $LEADER_TAKEWHENARGSMODULO}]
set pre_values [lrange $remaining_rawargs 0 $take-1]
set remaining_rawargs [lrange $remaining_rawargs $take end]
@ -8998,7 +9151,11 @@ tcl::namespace::eval punk::args {
if {$spec eq ""} {
return
}
return [dict get $spec examples_info -help]
if {[dict exists $spec examples_info -help]} {
return [dict get $spec examples_info -help]
} else {
return "no @examples defined for $id"
}
}
lappend PUNKARGS [list {
@ -9755,7 +9912,8 @@ tcl::namespace::eval punk::args {
set tp [dict get $cinfo cmdtype]
}
dict set choiceinfodict $sc [list [list resolved $cmd]]
#-resolved-
dict set choiceinfodict $sc [list [list ensemblesubtarget {*}$cmd]]
switch -- $tp {
ensemble - native {
@ -9778,7 +9936,8 @@ tcl::namespace::eval punk::args {
if {[punk::args::id_exists $checkid]} {
dict lappend choiceinfodict $sc {doctype punkargs}
dict lappend choiceinfodict $sc [list subhelp {*}$checkid]
dict set choicelabelsdict $sc [punk::ansi::a+ normal][punk::ns::synopsis $checkid][punk::ansi::a]
#dict set choicelabelsdict $sc [punk::ansi::a+ normal][punk::ns::synopsis $checkid][punk::ansi::a]
dict set choicelabelsdict $sc [punk::ansi::a+ normal][punk::args::synopsis $checkid][punk::ansi::a]
break
}
}
@ -9814,7 +9973,9 @@ tcl::namespace::eval punk::args {
dict for {g members} $opt_groupdict {
append argdef " \"$g\" \{$members\}" \n
}
append argdef " \} -choicecolumns $opt_columns -choicelabels {$choicelabelsdict} -choiceinfo {$choiceinfodict}" \n
append argdef " \} -choicecolumns $opt_columns -choicelabels \{" \n
append argdef " $choicelabelsdict" \n
append argdef " \} -choiceinfo \{$choiceinfodict\} -unindentedfields \{-choicelabels\}" \n
#todo -choicelabels
#detect subcommand further info available e.g if oo or ensemble or punk::args id exists..
@ -10172,16 +10333,23 @@ tcl::namespace::eval punk::args::lib {
#undent left of paramstart only for lines of expression that arent on opening ${..} line
set tail [string range $expression $brk1+1 end]
set leader [string repeat " " [string length $lastline]]
set undentedtail [punk::args::lib::undentleader $tail $leader]
#set undentedtail [punk::lib::undent [string range $expression $brk1+1 end]]
#set undentedtail [punk::args::lib::undentleader $tail $leader]
#jjj
set undentedtail [punk::lib::undent [string range $expression $brk1+1 end]]
set expression "[string range $expression 0 $brk1]$undentedtail"
}
if {$opt_eval} {
#puts "-----------------------"
#puts "TSTR"
#puts $expression
#puts "-----------------------"
if {[catch [list uplevel 1 [list ::subst {*}$nocommands $expression]] result]} {
lappend params [string cat \$\{ $expression \}]
dict set errors [expr {[llength $params]-1}] $result
} else {
set result [string map [list \n "\n$leader"] $result]
#JJJ
# e.g i glob
#set result [string map [list \n "\n$leader"] $result]
lappend params $result
}
#lappend params [uplevel 1 [list ::subst {*}$nocommands $expression]]

2
src/modules/punk/args-buildversion.txt

@ -1,3 +1,3 @@
0.2
0.2.1
#First line must be a semantic version number
#all other lines are ignored.

1956
src/modules/punk/args/moduledoc/tclcore-999999.0a1.0.tm

File diff suppressed because it is too large Load Diff

4
src/modules/punk/args/moduledoc/tkcore-999999.0a1.0.tm

@ -508,9 +508,9 @@ tcl::namespace::eval punk::args::moduledoc::tkcore {
punk::args::define {
@id -id (widgetcommand)Class_Button
@cmd -name "Tk widget: (widgetcommand)Class_Button"\
-summary\
-summary\
"widgetcommand for Tk class Button"\
-help\
-help\
"widgetcommand for Tk class Button"
@leaders -min 1 -max 1
option -type string\

88
src/modules/punk/imap4-999999.0a1.0.tm

@ -478,7 +478,7 @@ tcl::namespace::eval punk::imap4::proto {
@values -min 0 -max 1
capability -type string -default "" -help\
"The name of a capability to look for
in the cached response."
in the cached response."
}]
proc has_capability {chan {capability ""}} {
variable info
@ -557,25 +557,25 @@ tcl::namespace::eval punk::imap4::proto {
@opts
-validstates -default * -help\
"A list of valid states from which this
command can be called"
command can be called"
@values -min 1 -max -1
command -type string
arg -multiple 1 -optional 1 -help\
{Each argument for the command must be
supplied in a way that preserved the form
expected by an IMAP server.
For example, if an argument has spaces it
may need to be in double quotes and so need
to be explicitly specified with quotes and a
protecting set of braces.
e.g
simplecmd EXAMINE {"mailbox name with spaces"}
If Tcl variable substitution is required, escapes
within a quoted string could be used, or string map.
e.g
simplecmd $ch SETMETADATA $b "($ann \"$val\")"
supplied in a way that preserved the form
expected by an IMAP server.
For example, if an argument has spaces it
may need to be in double quotes and so need
to be explicitly specified with quotes and a
protecting set of braces.
e.g
simplecmd EXAMINE {"mailbox name with spaces"}
If Tcl variable substitution is required, escapes
within a quoted string could be used, or string map.
e.g
simplecmd $ch SETMETADATA $b "($ann \"$val\")"
}
}]
}]
proc simplecmd {args} {
set argd [punk::args::parse $args withid ::punk::imap4::proto::simplecmd]
lassign [dict values $argd] leaders opts values received
@ -2059,18 +2059,18 @@ tcl::namespace::eval punk::imap4 {
user
rights -help\
"A rights string consisting of zero or more rights
characters (lowercase) optionally beginning with a
\"+\" or \"-\"
e.g SETACL projectfolder other.user +cda
If the string starts with a plus, the following
rights are added to any existing rights for the
specified user.
If the string starts with a minus, the following
rights are removed from any existing rights for
the specified user.
If the string does not start with a plus or minus,
the rights replace any existing rights for the
specified user.
characters (lowercase) optionally beginning with a
\"+\" or \"-\"
e.g SETACL projectfolder other.user +cda
If the string starts with a plus, the following
rights are added to any existing rights for the
specified user.
If the string starts with a minus, the following
rights are removed from any existing rights for
the specified user.
If the string does not start with a plus or minus,
the rights replace any existing rights for the
specified user.
"
}]
proc SETACL {args} {
@ -2142,12 +2142,12 @@ tcl::namespace::eval punk::imap4 {
@values -min 0 -max 1
mailbox -default INBOX -help\
{To supply a mailbox name with spaces
The value will need to be enclosed with
double quotes - and these quotes need to
be sent to the server. Enclose in curly
braces to ensure this.
e.g
SELECT $ch {"Deleted Items"}
The value will need to be enclosed with
double quotes - and these quotes need to
be sent to the server. Enclose in curly
braces to ensure this.
e.g
SELECT $ch {"Deleted Items"}
}
}]
proc SELECT {args} {
@ -2172,12 +2172,12 @@ tcl::namespace::eval punk::imap4 {
#todo - share argdefs more!
mailbox -default INBOX -help\
{To supply a mailbox name with spaces
The value will need to be enclosed with
double quotes - and these quotes need to
be sent to the server. Enclose in curly
braces to ensure this.
e.g
SELECT $ch {"Deleted Items"}
The value will need to be enclosed with
double quotes - and these quotes need to
be sent to the server. Enclose in curly
braces to ensure this.
e.g
SELECT $ch {"Deleted Items"}
}
}]
proc EXAMINE {args} {
@ -2339,12 +2339,12 @@ tcl::namespace::eval punk::imap4 {
queryitems -default {} -help\
"Some common FETCH queries are shown here, but
this list isn't exhaustive."\
-multiple 1 -optional 0 -choiceprefix 0 -choicerestricted 0 -choicecolumns 2 -choices {
-multiple 1 -optional 0 -choiceprefix 0 -choicerestricted 0 -choicecolumns 2 -choices {
ALL FAST FULL BODY BODYSTRUCTURE ENVELOPE FLAGS INTERNALDATE
SIZE RFC822.SIZE
UID
TEXT HEADER BODY[] BINARY[] BINARY.SIZE[]
} -choicelabels {
} -choicelabels {
ALL\
" Macro equivalent to:
(FLAGS INTERNALDATE RFC822.SIZE ENVELOPE)
@ -2928,7 +2928,7 @@ tcl::namespace::eval punk::imap4 {
@values -min 2 -max 2
mailbox -help\
{Mailbox name or empty string {""} for server annotations}
annotation -choicerestricted 0 -help\
annotation -choicerestricted 0 -choiceprefix 0 -help\
"May include glob character *"\
-choices {
/private/specialuse /private/squat /private/sieve /private/sharedseen /private/comment
@ -2986,7 +2986,7 @@ tcl::namespace::eval punk::imap4 {
/private/expire /private/news2mail /private/pop3showafter
} -help\
"Annotation is a string beginning with /private/ or /shared/
Check specific server for supported mailbox annotations.
Check specific server for supported mailbox annotations.
"
value -help\
"Pass the empty string or NIL to unset/delete the annotation"
@ -3405,7 +3405,7 @@ tcl::namespace::eval punk::imap4 {
*:3
1,3,5,7:9
"
storetype -default +FLAGS -choicecolumns 1 -choices {+FLAGS +FLAGS.SILENT -FLAGS -FLAGS.SILENT FLAGS FLAGS.SILENT}\
storetype -default +FLAGS -choicecolumns 1 -choiceprefix 0 -choices {+FLAGS +FLAGS.SILENT -FLAGS -FLAGS.SILENT FLAGS FLAGS.SILENT}\
-choicelabels {
+FLAGS\
"Add the supplied flagnames to the flags for the message.

111
src/modules/punk/lib-999999.0a1.0.tm

@ -360,7 +360,8 @@ tcl::namespace::eval punk::lib::compat {
set fidx [llength $l]
}
default {
set pre [lrange $l 0 $first-1]
#set pre [lrange $l 0 $first-1]
set pre [lrange $l 0 $fidx-1]
}
}
set lidx [punk::lib::lindex_resolve [llength $l] $last]
@ -379,7 +380,8 @@ tcl::namespace::eval punk::lib::compat {
#If last is less than first, then any specified elements will be inserted into the list before the element specified by first with no elements being deleted.
set post [lrange $l $fidx end]
} else {
set post [lrange $l $last+1 end]
#set post [lrange $l $last+1 end]
set post [lrange $l $lidx+1 end]
}
}
}
@ -1526,7 +1528,7 @@ namespace eval punk::lib {
set pnext [string range $pnext 1 end]
}
# single type in segment e.g /@@something/
switch -exact $pnext {
switch -exact -- $pnext {
"" {
set substructure string
}
@ -2159,7 +2161,7 @@ namespace eval punk::lib {
if {[tcl::string::is integer -strict $expression]} {
return [expr {$expression}]
}
if {[regexp {(.*)([+-])(.*)} $expression _match a op b] && [tcl::string::is integer -strict $a] && [tcl::string::is integer -strict $b]} {
if {[regexp {([^+-]*)([+-])(.*)} $expression _match a op b] && [tcl::string::is integer -strict $a] && [tcl::string::is integer -strict $b]} {
if {$op eq "-"} {
return [expr {$a - $b}]
} else {
@ -2180,7 +2182,18 @@ namespace eval punk::lib {
An indexset consists of a comma delimited list of indexes or index-ranges.
The indexes are 0-based.
Ranges must be specified with .. as the separator.
The normal 'range' specifier is ..
The range specifier can appear at the beginning, middle or end, or even alone to indicate the entire
range of valid values.
e.g the following are all valid ranges
1..
(index 1 to max)
..10
(index 0 to 10)
2..11
(index 2o to 11)
..
(all indices)
Common whitespace elements space,tab,newlines are ignored.
Each index (or endpoint of an index-range) can be of the forms accepted by Tcl list or string commands,
e.g end-2 or 2+2.
@ -2199,6 +2212,19 @@ namespace eval punk::lib {
foreach r $ranges {
set validateindices [list]
set rposn [string first .. $r]
if {$rposn >= 0} {
set sepsize 2
set step 1
} else {
#check for .n. 'stepped' range
set fdot [string first . $r]
set ldot [string last . $r]
set step [string range $r $fdot+1 $ldot-1]
#todo - allow basic mathops for step: 2+1 2+-1 etc same as tcl lindex, lseq
if {![string is integer -strict $step]} {
}
}
if {$rposn >= 0} {
lappend validateindices {*}[string range $r 0 $rposn-1] {*}[string range $r $rposn+2 end]
} else {
@ -2389,16 +2415,22 @@ namespace eval punk::lib {
#[para]For empty lists, end and end+x indices are considered to be out of bounds on the upper side - thus returning -2
#Note that for an index such as $x+1 - we never see the '$x' as it is substituted in the calling command. We will get something like 10+1 - which can be resolved safely with expr
#if {![llength $list]} {
# #review
# return ???
#}
if {![string is integer -strict $len]} {
#<0 ?
error "lindex_resolve len must be an integer"
}
set index [tcl::string::map {_ {}} $index] ;#basic forward compatibility with integers such as 1_000 for 8.6
#REVIEW - we need compat for 1_000 etc to handle things like toml even in 8.6?
#A basic string map means we aren't properly validating
#todo - be stricter about malformations such as 1000_
if {![string is integer -strict 1_0]} {
#basic forward compatibility with integers such as 1_000 for 8.6.x
set index [tcl::string::map {_ {}} $index]
set len [tcl::string::map {_ {}} $len]
}
if {![string is integer -strict $len] || $len < 0} {
error "lindex_resolve len must be a positive integer"
}
if {[string is integer -strict $index]} {
#can match +i -i
if {$index < 0} {
@ -2414,40 +2446,42 @@ namespace eval punk::lib {
if {$index ne "end"} {
set op [string index $index 3]
set offset [string range $index 4 end]
#note - offset could have leading + or -
# 'string is integer -strict +1' ==> true
#e.g end+-1 is valid (end++-1 is not)
if {$op ni {+ -} || ![string is integer -strict $offset]} {error "bad index '$index': must be integer?\[+-\]integer? or end?\[+-\]integer?"}
if {$op eq "+" && $offset != 0} {
return -2
if {$offset == 0} {
#(offset +0, -0 or 0 or 000 0_0 etc)
#op either + or - is irrelevant
set index [expr {$len-1}]
if {$index < 0} {
return -2 ;#special case - equivalent to 'end', with empty list - treat like a positive number out of bounds
} else {
return $index
}
}
} else {
#index is 'end'
set index [expr {$len-1}]
set index [if {$op eq "+"} {expr {($len-1) + $offset}} else {expr {($len-1) - $offset}}]
if {$index < 0} {
#special case - 'end' with empty list - treat end like a positive number out of bounds
return -3
} elseif {$index > $len-1} {
return -2
} else {
return $index
}
}
if {$offset == 0} {
set index [expr {$len-1}]
if {$index < 0} {
return -2 ;#special case as above
} else {
return $index
}
} else {
#by now, if op = + then offset = 0 so we only need to handle the minus case
set index [expr {($len-1) - $offset}]
}
if {$index < 0} {
return -3
} else {
return $index
#index is 'end'
if {$len == 0} {
#special case - 'end' with empty list - treat end like a positive number out of bounds
return -2
}
return [expr {$len - 1}]
}
} else {
#plain +-<int> already handled above.
#we are trying to avoid evaluating unbraced expr of potentially insecure origin
if {[regexp {(.*)([+-])(.*)} $index _match a op b]} {
#regexp must split a++b to a + +b (not a+ + b) ie first +/- is the op
if {[regexp {([^+-]*)([+-])(.*)} $index _match a op b]} {
if {[string is integer -strict $a] && [string is integer -strict $b]} {
if {$op eq "-"} {
set index [expr {$a - $b}]
@ -3089,7 +3123,7 @@ namespace eval punk::lib {
return [join $result \n]
}
#dedent?
proc undent {text} {
proc undent {text {max -1}} {
if {$text eq ""} {
return ""
}
@ -3110,6 +3144,9 @@ namespace eval punk::lib {
return $text
}
set len [string length $lcp]
if {$max != -1} {
set len [expr {min($len,$max)}]
}
set result [list]
foreach ln $lines {
if {[string trim $ln] eq ""} {

2
src/modules/punk/lib-buildversion.txt

@ -1,3 +1,3 @@
0.1.2
0.1.3
#First line must be a semantic version number
#all other lines are ignored.

155
src/modules/punk/netbox-999999.0a1.0.tm

@ -980,10 +980,10 @@ tcl::namespace::eval punk::netbox {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
}\
[set ::punk::netbox::argdoc::_RETURN_STATUS]\
@ -1091,27 +1091,28 @@ tcl::namespace::eval punk::netbox::dcim {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
-id -type integer
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help\
{${$::punk::netbox::argdoc::_number_filter_help}}
-name
-NAME_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_name_filter_help}}
-NAME_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_name_filter_help}}
-asset_tag -type string
-ASSET_TAG_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_string_filter_help}}
-ASSET_TAG_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_string_filter_help}}
-face -type string
-face__n -type string
-position -type integer
-POSITION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-POSITION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-airflow -type string
-airflow__n -type string
-vc_position -type integer
-VC_POSITION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-VC_POSITION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-vc_priority -type integer
-VC_PRIORITY_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-VC_PRIORITY_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
}\
[set ::punk::netbox::argdoc::_create_update_options]\
{
@ -1155,9 +1156,9 @@ tcl::namespace::eval punk::netbox::dcim {
-status -type string
-status__n -type string
-mac_address -type string
-MAC_ADDRESS_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_string_filter_help}}
-MAC_ADDRESS_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_string_filter_help}}
-serial -type string
-SERIAL_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_string_filter_help}}
-SERIAL_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_string_filter_help}}
-virtual_chassis_id -type integer
-virtual_chassis_id__n -type integer
}\
@ -1188,14 +1189,14 @@ tcl::namespace::eval punk::netbox::ipam {
-choices {${[punk::netbox::api_context_names]}}
@opts
-id -type integer
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-name
-NAME_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_name_filter_help}}
-NAME_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_name_filter_help}}
-rd -type string -help\
"Route distinguisher in any format"
-enforce_unique
-description -type string -help "Exact Match (case sensitive)"
-DESCRIPTION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_description_filter_help}}
-DESCRIPTION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_description_filter_help}}
}\
[set ::punk::netbox::argdoc::_create_update_options]\
{
@ -1230,10 +1231,10 @@ tcl::namespace::eval punk::netbox::ipam {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
}\
[set ::punk::netbox::argdoc::_RETURN_DICT]\
@ -1261,11 +1262,11 @@ tcl::namespace::eval punk::netbox::ipam {
-choices {${[punk::netbox::api_context_names]}}
@opts
-id -type integer
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-is_pool
-mark_utilized
-description -type string -help "Exact Match (case sensitive)"
-DESCRIPTION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_description_filter_help}}
-DESCRIPTION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_description_filter_help}}
}\
[set ::punk::netbox::argdoc::_create_update_options]\
{
@ -1285,16 +1286,16 @@ tcl::namespace::eval punk::netbox::ipam {
-within_include
-contains
-depth
-DEPTH_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-DEPTH_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-children
-CHILDREN_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-CHILDREN_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-mask_length
-mask_length__gte
-mask_length__lte
-vlan_id -type integer
-vlan_id__n -type integer
-vlan_vid -type integer
-VLAN_VID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-VLAN_VID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-vrf_id
-vrf
-status
@ -1319,10 +1320,10 @@ tcl::namespace::eval punk::netbox::ipam {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
}\
[set ::punk::netbox::argdoc::_RETURN_DICT]\
@ -1343,10 +1344,10 @@ tcl::namespace::eval punk::netbox::ipam {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
}\
[set ::punk::netbox::argdoc::_RETURN_DICT]\
@ -1368,10 +1369,10 @@ tcl::namespace::eval punk::netbox::ipam {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
}\
[set ::punk::netbox::argdoc::_page_options]\
@ -1508,11 +1509,11 @@ tcl::namespace::eval punk::netbox::ipam {
-choices {${[punk::netbox::api_context_names]}}
@opts
-id -type integer
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-dns_name
-DNS_NAME_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_string_filter_help}}
-DNS_NAME_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_string_filter_help}}
-description -type string -help "Exact Match (case sensitive)"
-DESCRIPTION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_description_filter_help}}
-DESCRIPTION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_description_filter_help}}
}\
[set ::punk::netbox::argdoc::_create_update_options]\
{
@ -1686,19 +1687,19 @@ tcl::namespace::eval punk::netbox::tenancy {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
-id -type integer
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-name
-NAME_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_name_filter_help}}
-NAME_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_name_filter_help}}
-slug -type string
-SLUG_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_string_filter_help}}
-SLUG_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_string_filter_help}}
-description -type string
-DESCRIPTION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_string_filter_help}}
-DESCRIPTION_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_string_filter_help}}
}\
[set ::punk::netbox::argdoc::_create_update_options]\
{
@ -1735,24 +1736,24 @@ tcl::namespace::eval punk::netbox::virtualization {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
-id -type integer
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-ID_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-name
-NAME_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_name_filter_help}}
-NAME_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_name_filter_help}}
-cluster -type string
-cluster_n -type string
-vcpus -type integer
-VCPUS_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-VCPUS_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-memory -type integer -help\
"Whole number"
-MEMORY_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-MEMORY_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
-disk -type integer
-DISK_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_number_filter_help}}
-DISK_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_number_filter_help}}
}\
[set ::punk::netbox::argdoc::_create_update_options]\
{
@ -1782,7 +1783,7 @@ tcl::namespace::eval punk::netbox::virtualization {
-platform
-platform__n
-mac_address
-MAC_ADDRESS_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -help {${$::punk::netbox::argdoc::_string_filter_help}}
-MAC_ADDRESS_FILTER -type list -minsize 2 -maxsize 2 -multiple 1 -unindentedfields {-help} -help {${$::punk::netbox::argdoc::_string_filter_help}}
-has_primary_ip
}\
[set ::punk::netbox::argdoc::_group_options]\
@ -1807,10 +1808,10 @@ tcl::namespace::eval punk::netbox::virtualization {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
}\
[set ::punk::netbox::argdoc::_RETURN_DICT]\
@ -1835,10 +1836,10 @@ tcl::namespace::eval punk::netbox::virtualization {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
-FORCE -default 0 -type boolean -help\
"Set to true to BULK delete all items at this endpoint"
@ -1859,10 +1860,10 @@ tcl::namespace::eval punk::netbox::virtualization {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
}\
[set ::punk::netbox::argdoc::_RETURN_DICT]\
@ -1883,10 +1884,10 @@ tcl::namespace::eval punk::netbox::virtualization {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
}\
[set ::punk::netbox::argdoc::_RETURN_DICT]\

8
src/modules/punk/netbox/man-999999.0a1.0.tm

@ -132,10 +132,10 @@ tcl::namespace::eval punk::netbox::man {
@leaders -min 1 -max 1
apicontextid -help\
"The name of the stored api context to use.
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
A contextid can be created in-memory using
api_context_create, or loaded from a .toml
file using api_context_load."\
-choices {${[punk::netbox::api_context_names]}}
@opts
}\
]

232
src/modules/punk/ns-999999.0a1.0.tm

@ -491,42 +491,50 @@ tcl::namespace::eval punk::ns {
lassign $cindices cstart cend
append p [string range $nspath $s $cstart-1]
set numcolons [expr {$cend - $cstart + 1}]
if {$numcolons == 1} {
#internal colon
append p :
set s [expr {$cend+1}]
continue
} elseif {$numcolons == 2} {
lappend parts $p
set p ""
set s [expr {$cend+1}]
continue
} elseif {($numcolons -1) % 3 == 0} {
set numcolons [expr {$numcolons -2}]
}
#assert numcolons >=3 and not in 4,7,10,13,16,19,22... sequence
if {$numcolons % 3 == 0} {
#if numcolons % 3 == 0 we have a leading colon left for next ns
#this is the ambiguous case x::::::y -> x: :: : ::y vs x:: : :: :y
#we resolve with allowing leading colons only for each ns.
set singlec_count [expr {($numcolons /3) -1}]
if {$singlec_count > 0} {
lappend parts $p {*}[lrepeat $singlec_count :]
} else {
#assert numcolons != 0 due to regexp +
switch -exact -- $numcolons {
2 - 4 {
#4 is a somewhat common case - could handle with default branch but may as well short circuit here.
lappend parts $p
set p ""
set s [expr {$cend+1}]
#continue
}
set p ":"
set s [expr {$cend+1}]
continue
} else {
set singlec_count [expr {(($numcolons +1)/3) -1}]
if {$singlec_count > 0} {
lappend parts $p {*}[lrepeat $singlec_count :]
} else {
lappend parts $p
1 {
#internal colon
append p :
set s [expr {$cend+1}]
#continue
}
default {
if {($numcolons -1) %3 == 0} {
set numcolons [expr {$numcolons -2}]
}
#assert numcolons >=4 and not in 7,10,13,16,19,22... sequence
if {$numcolons % 3 == 0} {
#if numcolons % 3 == 0 we have a leading colon left for next ns
#this is the ambiguous case x::::::y -> x: :: : ::y vs x:: : :: :y
#we resolve with allowing leading colons only for each ns.
set singlec_count [expr {($numcolons /3) -1}]
if {$singlec_count > 0} {
lappend parts $p {*}[lrepeat $singlec_count :]
} else {
lappend parts $p
}
set p ":"
set s [expr {$cend+1}]
#continue
} else {
set singlec_count [expr {(($numcolons +1)/3) -1}]
if {$singlec_count > 0} {
lappend parts $p {*}[lrepeat $singlec_count :]
} else {
lappend parts $p
}
set p ""
set s [expr {$cend+1}]
}
}
set p ""
set s [expr {$cend+1}]
}
}
if {$cend < ([string length $nspath]-1)} {
@ -695,6 +703,39 @@ tcl::namespace::eval punk::ns {
}
proc nsglob_as_re {glob} {
#any segment that is not just * must match exactly one segment in the path
set pats [list]
foreach seg [nsparts_cached $glob] {
switch -exact -- $seg {
"" {
lappend pats ""
}
* {
#review - ::g*t will not find ::got:it (won't match single inner colon) - this should be fixed
#lappend pats {[^:]*}
#negative lookahead
#any number of chars not followed by ::, followed by any number of non :
lappend pats {(?:.(?!::))*[^:]*}
}
** {
lappend pats {.*}
}
default {
set seg [string map {. [.]} $seg]
if {[regexp {[*?]} $seg]} {
#set pat [string map [list ** {.*} * {[^:]*} ? {[^:]}] $seg]
set pat [string map [list ** {.*} * {(?:.(?!::))*[^:]*} ? {[^:]}] $seg]
lappend pats "$pat"
} else {
lappend pats "$seg"
}
}
}
}
return "^[join $pats ::]\$"
}
#obsolete
proc nsglob_as_re1 {glob} {
#any segment that is not just * must match exactly one segment in the path
set pats [list]
foreach seg [nsparts_cached $glob] {
@ -3042,9 +3083,10 @@ tcl::namespace::eval punk::ns {
@cmd -name "${$objtype}: ${$origin}" -help\
"Instance of class: ${$class} (info autogenerated by generate_autodef)
(see 'i punk::ns::Cmark' for symbols)"
@leaders -min 1
@leaders -min 1 -max 1
}]
append argdef \n $vline
append argdef \n "@values -unnamed true"
punk::args::define $argdef
}
@ -3148,15 +3190,15 @@ tcl::namespace::eval punk::ns {
dict for {sub subwhat} $subcommand_dict {
if {[llength $subwhat] > 1} {
#TODO - resolve using cmdinfo?
puts stderr "arginfo warning: subcommand $sub points to multiword target $subwhat - TODO"
puts stderr "generate_autodef warning: subcommand $sub points to multiword target $subwhat - TODO"
}
set targetfirstword [lindex $subwhat 0]
set targetinfo [cmdwhich $targetfirstword]
set targetorigin [dict get $targetinfo origin]
set targetcmdtype [dict get $targetinfo origintype]
set nstarget [nsprefix $targetorigin]
dict set choiceinfodict $sub [list [list resolved $subwhat]]
# -resolved-
dict set choiceinfodict $sub [list [list ensemblesubtarget {*}$subwhat]]
dict lappend choiceinfodict $sub [list doctype $targetcmdtype]
if {[punk::args::id_exists [list $origin $sub]]} {
@ -3190,7 +3232,7 @@ tcl::namespace::eval punk::ns {
} else {
append argdef \n "@leaders -min [expr {[llength $parameters]+1}] -max [expr {[llength $parameters]+1}]"
foreach p $parameters {
append argdef \n "$p -type string -help { (leading ensemble parameter)}"
append argdef \n "$p -type string -ensembleparameter 1 -help { (leading ensemble parameter)}"
}
}
append argdef \n $vline
@ -3316,7 +3358,7 @@ tcl::namespace::eval punk::ns {
if {[string match (autodef)* $origin]} {
set origin [string range $origin 9 end]
}
#puts "->$final neworigin: $origin consumed:$consumed remaining:$remainingargs docid:$docid"
puts "->$final neworigin: $origin consumed:$consumed remaining:$remainingargs docid:$docid"
lappend stack [list $origin {*}$consumed]
lappend commands $origin
lappend consumed_args {*}$consumed
@ -3326,6 +3368,13 @@ tcl::namespace::eval punk::ns {
set cinfo [cmdwhich $finalcommand]
set origin [dict get $cinfo origin]
set cmdtype [dict get $cinfo origintype]
if {$cmdtype eq "notfound" && [llength $finalcommand] > 1} {
#e.g see curried command produced by 'punk::netbox::man <apicontextid> new'
set next [list {*}$finalcommand {*}$remainingargs]
if {$next ne $args} {
return [cmdinfo {*}$next]
}
}
return [list origin $origin cmdtype $cmdtype args_resolved [list [lindex $commands 0] {*}$consumed_args] args_remaining $remainingargs docid $docid stack $stack]
}
proc cmd_traverse {ns formid args} {
@ -3494,6 +3543,7 @@ tcl::namespace::eval punk::ns {
#we could at least check for the next level down - allowing a single level of progression beyond undoc'ed subcommand-accepting procs.
#(would not support shor-form prefix of subcommand - even if the proc implementation did)
set docid_exists 0
set eparams [list]
if {[punk::args::id_exists "$origin [lindex $args $i]"]} {
set a [lindex $args $i]
#review - tests?
@ -3544,6 +3594,12 @@ tcl::namespace::eval punk::ns {
set leadernames [dict get $spec FORMS $fid LEADER_NAMES]
set optnames [dict get $spec FORMS $fid OPT_NAMES]
set valnames [dict get $spec FORMS $fid VAL_NAMES]
#review - see 'string is word' vs 'string is wordchar' behaviour due to documented common opts/vals in the parent ensemble-like command '::tcl::string::is'
#we should be preferring the most specific documentation
#Alternatively - we could adjust the 'string is' documentation to have @values -unnamed true
#and put the common info in the help for <unnamed> - but that would give us an inferior synopsis for 'string is'
if {![llength $optnames] && ![llength $valnames]} {
#set queryargs [lrange $args $i end]
@ -3575,8 +3631,26 @@ tcl::namespace::eval punk::ns {
if {$is_ensembleparam} {
lappend resolvedargs $q
lpop queryargs_untested 0
lappend eparams $q
puts stderr "---> cmd_traverse ensembleparam $q ($lname)"
puts stderr "arginfo: $arginfo"
puts stderr "---> eparams: $eparams"
puts stderr "---> existing args: $args"
#ledit queryargs_untested 0 0
#review - add tests
#todo - put param in untested (multiple ensembleparams??)
#ledit queryargs_untested 1 0 $q ;#(linsert)
#set posn_subcommand [llength $parameters];#ensemble may have '-parameters' list specified - parameters that come before the subcommand
#if {$posn_subcommand > 0} {
# set params [lrange $queryargs 0 $posn_subcommand-1]
# set remaining_queryargs [lrange $queryargs $posn_subcommand end]
#} else {
# set params [list]
# set remaining_queryargs $queryargs
#}
incr i
continue
}
if {![llength $allchoices]} {
@ -3586,7 +3660,7 @@ tcl::namespace::eval punk::ns {
#ledit queryargs_untested 0 0
#jjj
#continue
return [list 3 $origin $resolvedargs $queryargs_untested $docid]
return [list 3 $origin $resolvedargs [list {*}$eparams {*}$queryargs_untested] $docid]
break
}
set resolved_q [tcl::prefix::match -error "" $allchoices $q]
@ -3611,9 +3685,9 @@ tcl::namespace::eval punk::ns {
set docid ""
foreach inf $cinfo {
switch -- [lindex $inf 0] {
"resolved" {
#punk::args::ensemble_subcommands_definition
"subhelp" {
set mapped_subcmd [lrange $inf 1 end]
#set mapped_subcmd [lindex $inf 1]
if {![punk::args::id_exists $mapped_subcmd]} {
punk::args::update_definitions [list [namespace qualifiers $mapped_subcmd]]
if {![dict exists $autodefined $mapped_subcmd]} {
@ -3631,11 +3705,14 @@ tcl::namespace::eval punk::ns {
} else {
set docid ""
}
#puts stderr "cmd_traverse 'resolved' $mapped_subcmd"
#allow subhelp override - todo: review/document rationale/usecases
break
}
"subhelp" {
"ensemblesubtarget" {
# -resolved-
#punk::args::ensemble_subcommands_definition
#This could be a list representing some other ensemble or command with pre-included arguments
set mapped_subcmd [lrange $inf 1 end]
#set mapped_subcmd [lindex $inf 1]
if {![punk::args::id_exists $mapped_subcmd]} {
punk::args::update_definitions [list [namespace qualifiers $mapped_subcmd]]
if {![dict exists $autodefined $mapped_subcmd]} {
@ -3653,8 +3730,16 @@ tcl::namespace::eval punk::ns {
} else {
set docid ""
}
#allow subhelp override - todo: review/document rationale/usecases
break
#puts stderr "cmd_traverse 'resolved' $mapped_subcmd"
}
"doctype" {
set d [lindex $inf 1]
switch -- $d {
"classmethod" {
}
"coremethod" {
}
}
}
}
}
@ -3669,23 +3754,9 @@ tcl::namespace::eval punk::ns {
set mapped_subcmd "$raw_origin $resolved_q"
set docid $mapped_subcmd
} else {
#REVIEW - there is no reason to assume a subcommand (even in an ensemble)
#NOTE there is no reason to assume a subcommand (even in an ensemble)
#will be located at "${raw_origin}::$resolved_q"
#ensemble -map could point resolved_q somewhere else entirely
#punk::args::update_definitions [list $raw_origin]
#if {[punk::args::id_exists "${raw_origin}::$resolved_q"]} {
# set mapped_subcmd "${raw_origin}::$resolved_q"
# set docid $mapped_subcmd
#} else {
# if {![punk::args::id_exists "(autodef)${raw_origin}::$resolved_q"]} {
# namespace eval $ns [list punk::ns::generate_autodef "${raw_origin}::$resolved_q"]
# }
# if {[punk::args::id_exists "(autodef)${raw_origin}::$resolved_q"]} {
# set mapped_subcmd ${raw_origin}::$resolved_q
# set docid (autodef)${raw_origin}::$resolved_q
# }
#}
}
}
#puts "----------$mapped_subcmd"
@ -3696,15 +3767,18 @@ tcl::namespace::eval punk::ns {
#punk::args::update_definitions [list [namespace qualifiers $mapped_subcmd]]
if {[llength $queryargs_untested] == 0} {
return [list 6 $mapped_subcmd $resolvedargs $queryargs_untested $docid]
return [list 6 $mapped_subcmd $resolvedargs [list {*}$eparams {*}$queryargs_untested] $docid]
}
set origin [yield [list 0 $mapped_subcmd $resolvedargs $queryargs_untested $docid]]
set origin [yield [list 0 $mapped_subcmd $resolvedargs [list {*}$eparams {*}$queryargs_untested] $docid]]
#set resolvedargs [list]
#incr i [expr {-1 * [llength $resolvedargs]+1}] ;#wrong e.g test trace add execution blah enterstep cmd
#JJJ
#puts stderr "... yield-result $origin i:$i args: $args"
puts stderr "... yield-result $origin i:$i args: $args"
ledit args $i+1 $i {*}$eparams
set eparams [list]
set whichinfo [namespace eval $ns [list punk::ns::cmdwhich $origin]]
set origin [dict get $whichinfo origin]
@ -3730,7 +3804,7 @@ tcl::namespace::eval punk::ns {
} ;#end loop foreach q $queryargs lname $leadernames_matched
} else {
#??
puts stderr "cmdinfo.cmd_traverse returning 8 $origin $resolvedargs [lrange $args $i end] $docid"
puts stderr "cmdinfo.cmd_traverse returning 8 origin: $origin resolved: $resolvedargs remaining: [lrange $args $i end] docid: $docid"
return [list 8 $origin $resolvedargs [lrange $args $i end] $docid]
}
} else {
@ -3855,7 +3929,30 @@ tcl::namespace::eval punk::ns {
#puts stderr [textblock::frame $syn]
#set replaceuntil [expr {[llength $resolved_id]-1}]
set replaceuntil [expr {[llength $resolved_id]-1+$excess}]
append resultstr [join [lreplace $synline 0 $replaceuntil {*}$resolved_args] " "] \n
#append resultstr [join [lreplace $synline 0 $replaceuntil {*}$resolved_args] " "] \n ;#don't use join - will destroy braced sets
#e.g see s dict filter
#treating a somewhat arbitrary string $synline as a list here is a bit risky
#todo - consider always using 'punk::args::synopsis -return dict' and operating on that list to rebuild string - REVIEW
set adjusted_synline [lreplace $synline 0 $replaceuntil {*}$resolved_args] ;#don't use join - will destroy braced sets
#however - we don't want the extra bracing around ansi elements caused by list rep!
#::dict filter {dictionaryValue} script {keyVariable valueVariable} {script}
#vs
#::dict filter dictionaryValue script {keyVariable valueVariable} script
#(due to ansi in dictionaryValue and trailing script)
#manually join based on list length review
set lineout ""
foreach part $adjusted_synline {
if {[llength $part] == 1} {
append lineout " " $part
} else {
append lineout " " [list $part]
}
}
#must be no leading space for tests in test::punk::args synopsis.test
append resultstr [string trim $lineout] \n
}
}
set resultstr [string trimright $resultstr \n]
@ -4626,6 +4723,7 @@ tcl::namespace::eval punk::ns {
@values
}]
set i 0
#for 9.1+ can use -integer
foreach a $arglist {
switch -- [llength $a] {
1 {

2
src/modules/punk/path-999999.0a1.0.tm

@ -182,7 +182,7 @@ namespace eval punk::path {
proc normjoin {args} {
set args [lmap a $args {string map "\\\\ /" $a}]
set path [plainjoin {*}$args]
switch -exact $path {
switch -exact -- $path {
"" {
return ""
}

17
src/modules/test/punk/#modpod-args-999999.0a1.0/args-0.1.5_testsuites/args/args.test

@ -22,6 +22,23 @@ namespace eval ::testspace {
x a y b
]
test parse_withdef_auto_change_argspace_from_options_to_values {test first non dashed argdef after option is treated as a value when @values not explicit}\
-setup $common -body {
#test val1 following -opt is automatically placed in 'values' when @values directive is missing
set argd [punk::args::parse {-opt 1 b} withdef -opt val1]
set docid [dict get $argd id]
set vals [dict get $argd values]
set result $vals
}\
-cleanup {
punk::args::undefine $docid 1
}\
-result [list\
val1 b
]
test parse_withdef_option_ordering_defaults {Test ordering of options when some have defaults}\
-setup $common -body {
#for consistency with leaders and values dicts - try to maintain definition order for options too

30
src/modules/test/punk/#modpod-lib-999999.0a1.0/lib-0.1.3_testsuites/lib/compat.test

@ -0,0 +1,30 @@
package require tcltest
namespace eval ::testspace {
namespace import ::tcltest::*
variable common {
set result ""
}
test compat_ledit_math_first {test basic mathop in 'first' index}\
-setup $common -body {
set l {a b c d}
lappend result [punk::lib::compat::ledit l 0+1 1 x]
}\
-cleanup {
}\
-result [list\
{a x c d}
]
test compat_ledit_math_last {test basic mathop in 'last' index}\
-setup $common -body {
set l {a b c d}
lappend result [punk::lib::compat::ledit l 1 0+1 x]
}\
-cleanup {
}\
-result [list\
{a x c d}
]
}

79
src/modules/test/punk/#modpod-lib-999999.0a1.0/lib-0.1.3_testsuites/lib/index_functions.test

@ -0,0 +1,79 @@
package require tcltest
namespace eval ::testspace {
namespace import ::tcltest::*
variable common {
set result ""
}
test lindex_resolve_endoffsets {}\
-setup $common -body {
#e.g indices {0 1 2 3 4} n = 5
lappend result [punk::lib::lindex_resolve 5 end] ;# -> 4
lappend result [punk::lib::lindex_resolve 5 end--0] ;# -> 4
lappend result [punk::lib::lindex_resolve 5 end++0] ;# -> 4
lappend result [punk::lib::lindex_resolve 5 end+-0] ;# -> 4
lappend result [punk::lib::lindex_resolve 5 end-+0] ;# -> 4
lappend result [punk::lib::lindex_resolve 5 end-1] ;# -> 3
lappend result [punk::lib::lindex_resolve 5 end-+1] ;# -> 3
lappend result [punk::lib::lindex_resolve 5 end+-1] ;# -> 3
}\
-cleanup {
}\
-result [list\
4 4 4 4 4 3 3 3
]
test lindex_resolve_endoffsets_out_of_range {}\
-setup $common -body {
#e.g indices {0 1 2 3 4} n = 5
lappend result [punk::lib::lindex_resolve 5 end+1] ;# -> -2 out of bounds on upper side
lappend result [punk::lib::lindex_resolve 5 end--1] ;# equiv to +1 -> -2
lappend result [punk::lib::lindex_resolve 5 4--5] ;# -> -2 out of bounds on upper side
lappend result [punk::lib::lindex_resolve 5 end--5] ;# -> -2 out of bounds on upper side
lappend result [punk::lib::lindex_resolve 5 4-5] ;# -> -3 out of bounds on lower side
lappend result [punk::lib::lindex_resolve 5 end-5] ;# -> -3 out of bounds on lower side
lappend result [punk::lib::lindex_resolve 5 4+-5] ;# -> -3 out of bounds on lower side
lappend result [punk::lib::lindex_resolve 5 end+-5] ;# -> -3 out of bounds on lower side
lappend result [punk::lib::lindex_resolve 5 4-+5] ;# -> -3 out of bounds on lower side
lappend result [punk::lib::lindex_resolve 5 end-+5] ;# -> -3 out of bounds on lower side
}\
-cleanup {
}\
-result [list\
-2 -2 -2 -2 -3 -3 -3 -3 -3 -3
]
test lindex_resolve_endoffset_errors {test some end-like offsets that should error}\
-setup $common -body {
#e.g indices {0 1 2 3 4} n = 5
lappend result [catch {[punk::lib::lindex_resolve 5 end-]}] ;#must error
lappend result [catch {[punk::lib::lindex_resolve 5 end+]}] ;#must error
lappend result [catch {[punk::lib::lindex_resolve 5 end+--1]}] ;#must error
lappend result [catch {[punk::lib::lindex_resolve 5 end-++1]}] ;#must error
lappend result [catch {[punk::lib::lindex_resolve 5 end---1]}] ;#must error
lappend result [catch {[punk::lib::lindex_resolve 5 end+++1]}] ;#must error
#should error
# - but we have simplistic backwards compat to strip underscores - REVIEW
#lappend result [catch {[punk::lib::lindex_resolve 5 end_]}] ;#should error
#lappend result [catch {[punk::lib::lindex_resolve 5 end+_1]}] ;#should error
}\
-cleanup {
}\
-result [list\
1 1 1 1 1 1
]
}

0
src/modules/test/punk/#modpod-lib-999999.0a1.0/lib-0.1.3_testsuites/tests/compat.test#..+lib+compat.test.fauxlink

0
src/modules/test/punk/#modpod-lib-999999.0a1.0/lib-0.1.3_testsuites/tests/index.test#..+lib+index_functions.test.fauxlink

211
src/modules/test/punk/#modpod-lib-999999.0a1.0/lib-999999.0a1.0.tm

@ -0,0 +1,211 @@
# -*- tcl -*-
# Maintenance Instruction: leave the 999999.xxx.x as is and use punkshell 'dev make' or bin/punkmake to update from <pkg>-buildversion.txt
# module template: shellspy/src/decktemplates/vendor/punk/modules/template_module-0.0.3.tm
#
# Please consider using a BSD or MIT style license for greatest compatibility with the Tcl ecosystem.
# Code using preferred Tcl licenses can be eligible for inclusion in Tcllib, Tklib and the punk package repository.
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
# (C) 2025
#
# @@ Meta Begin
# Application test::punk::lib 999999.0a1.0
# Meta platform tcl
# Meta license MIT
# @@ Meta End
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
# doctools header
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
#*** !doctools
#[manpage_begin shellspy_module_test::punk::lib 0 999999.0a1.0]
#[copyright "2025"]
#[titledesc {Module API}] [comment {-- Name section and table of contents description --}]
#[moddesc {-}] [comment {-- Description at end of page heading --}]
#[require test::punk::lib]
#[keywords module]
#[description]
#[para] -
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
#*** !doctools
#[section Overview]
#[para] overview of test::punk::lib
#[subsection Concepts]
#[para] -
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
## Requirements
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
#*** !doctools
#[subsection dependencies]
#[para] packages used by test::punk::lib
#[list_begin itemized]
package require Tcl 8.6-
#*** !doctools
#[item] [package {Tcl 8.6}]
#*** !doctools
#[list_end]
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
#*** !doctools
#[section API]
tcl::namespace::eval test::punk::lib {
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
# Base namespace
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
#*** !doctools
#[subsection {Namespace test::punk::lib}]
#[para] Core API functions for test::punk::lib
#[list_begin definitions]
variable PUNKARGS
variable pkg test::punk::lib
variable version
set version 999999.0a1.0
package require packageTest
packageTest::makeAPI test::punk::lib $version punk::lib; #will package provide test::punk::lib $version
package forget punk::lib
package require punk::lib
#*** !doctools
#[list_end] [comment {--- end definitions namespace test::punk::lib ---}]
}
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
# Secondary API namespace
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
# == === === === === === === === === === === === === === ===
# Sample 'about' function with punk::args documentation
# == === === === === === === === === === === === === === ===
tcl::namespace::eval test::punk::lib {
tcl::namespace::export {[a-z]*} ;# Convention: export all lowercase
variable PUNKARGS
variable PUNKARGS_aliases
lappend PUNKARGS [list {
@id -id "(package)test::punk::lib"
@package -name "test::punk::lib" -help\
"Test suites for punk::lib"
}]
namespace eval argdoc {
#namespace for custom argument documentation
proc package_name {} {
return test::punk::lib
}
proc about_topics {} {
#info commands results are returned in an arbitrary order (like array keys)
set topic_funs [info commands [namespace current]::get_topic_*]
set about_topics [list]
foreach f $topic_funs {
set tail [namespace tail $f]
lappend about_topics [string range $tail [string length get_topic_] end]
}
#Adjust this function or 'default_topics' if a different order is required
return [lsort $about_topics]
}
proc default_topics {} {return [list Description *]}
# -------------------------------------------------------------
# get_topic_ functions add more to auto-include in about topics
# -------------------------------------------------------------
proc get_topic_Description {} {
punk::args::lib::tstr [string trim {
package test::punk::lib
test suite for punk::lib
} \n]
}
proc get_topic_License {} {
return "MIT"
}
proc get_topic_Version {} {
return "$::test::punk::lib::version"
}
proc get_topic_Contributors {} {
set authors {{<julian@precisium.com> Julian Noble}}
set contributors ""
foreach a $authors {
append contributors $a \n
}
if {[string index $contributors end] eq "\n"} {
set contributors [string range $contributors 0 end-1]
}
return $contributors
}
proc get_topic_custom-topic {} {
punk::args::lib::tstr -return string {
A custom
topic
etc
}
}
# -------------------------------------------------------------
}
# we re-use the argument definition from punk::args::standard_about and override some items
set overrides [dict create]
dict set overrides @id -id "::test::punk::lib::about"
dict set overrides @cmd -name "test::punk::lib::about"
dict set overrides @cmd -help [string trim [punk::args::lib::tstr {
About test::punk::lib
}] \n]
dict set overrides topic -choices [list {*}[test::punk::lib::argdoc::about_topics] *]
dict set overrides topic -choicerestricted 1
dict set overrides topic -default [test::punk::lib::argdoc::default_topics] ;#if -default is present 'topic' will always appear in parsed 'values' dict
set newdef [punk::args::resolved_def -antiglobs -package_about_namespace -override $overrides ::punk::args::package::standard_about *]
lappend PUNKARGS [list $newdef]
proc about {args} {
package require punk::args
#standard_about accepts additional choices for topic - but we need to normalize any abbreviations to full topic name before passing on
set argd [punk::args::parse $args withid ::test::punk::lib::about]
lassign [dict values $argd] _leaders opts values _received
punk::args::package::standard_about -package_about_namespace ::test::punk::lib::argdoc {*}$opts {*}[dict get $values topic]
}
}
# end of sample 'about' function
# == === === === === === === === === === === === === === ===
# -----------------------------------------------------------------------------
# register namespace(s) to have PUNKARGS,PUNKARGS_aliases variables checked
# -----------------------------------------------------------------------------
# variable PUNKARGS
# variable PUNKARGS_aliases
namespace eval ::punk::args::register {
#use fully qualified so 8.6 doesn't find existing var in global namespace
lappend ::punk::args::register::NAMESPACES ::test::punk::lib
}
# -----------------------------------------------------------------------------
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++
## Ready
package provide test::punk::lib [tcl::namespace::eval test::punk::lib {
variable pkg test::punk::lib
variable version
set version 999999.0a1.0
}]
return
#*** !doctools
#[manpage_end]

3
src/modules/test/punk/lib-buildversion.txt

@ -0,0 +1,3 @@
0.1.3
#First line must be a semantic version number
#all other lines are ignored.

122
src/modules/textblock-999999.0a1.0.tm

@ -4531,10 +4531,10 @@ tcl::namespace::eval textblock {
-help "existing table object to use"
-action -default "append" -choices {append replace}\
-help "row insertion method if existing -table is supplied
if append is chosen the new values will always start at the first column"
if append is chosen the new values will always start at the first column"
-title -type string -help\
"Title to display overlayed on top edge of table.
Will not be visible if -show_edge is false"
Will not be visible if -show_edge is false"
-titlealign -type string -choices {left centre right}
-frametype -default "light" -type dict -choices {${$FRAMETYPES}} -choicerestricted 0\
-help "frame type or dict for custom frame"
@ -4545,32 +4545,32 @@ tcl::namespace::eval textblock {
-help "Show vertical table separators"
-show_hseps -default "" -type boolean\
-help "Show horizontal table separators
(default 0 if no existing -table supplied)"
(default 0 if no existing -table supplied)"
-colheaders -default "" -type list\
-help {list of lists. list of column header values. Outer list must match number of columns.
A table
e.g single header row: -colheaders {{column_a} {column_b} {column_c}}
e.g 2 header rows: -colheaders {{column_a "nextrow test"} {column_b} {column_c}}
Note that each element of the outer list is itself a list so:
-colheaders {"column a" "column b" "column c"}
Is likely not the right format if it was intended to have a single header row where the
column titles contain spaces.
The correct syntax for that would be:
-colheaders {{"column a"} {"column b"} {"column c"}}
For spanning header cells - use 'set t [list_as_table -return tableobject ...]'
and then something like:
$t configure_header 1 -colspans {3 0 0}; $t print
A table
e.g single header row: -colheaders {{column_a} {column_b} {column_c}}
e.g 2 header rows: -colheaders {{column_a "nextrow test"} {column_b} {column_c}}
Note that each element of the outer list is itself a list so:
-colheaders {"column a" "column b" "column c"}
Is likely not the right format if it was intended to have a single header row where the
column titles contain spaces.
The correct syntax for that would be:
-colheaders {{"column a"} {"column b"} {"column c"}}
For spanning header cells - use 'set t [list_as_table -return tableobject ...]'
and then something like:
$t configure_header 1 -colspans {3 0 0}; $t print
}
-header -default "" -type list -multiple 1\
-help "Each supplied -header argument is a header row.
The number of values for each must be <= number of columns"
The number of values for each must be <= number of columns"
-show_header -type boolean\
-help "Whether to show a header row.
Omit for unspecified/automatic,
in which case it will display only if -headers list was supplied."
Omit for unspecified/automatic,
in which case it will display only if -headers list was supplied."
-columns -default "" -type integer\
-help "Number of table columns
Will default to 2 if not using an existing -table object"
Will default to 2 if not using an existing -table object"
@values -min 0 -max 1
datalist -default {} -type list -help "flat list of table cell values which will be wrapped based on -columns value"
@ -4810,19 +4810,19 @@ tcl::namespace::eval textblock {
-choices {horizontal vertical}\
-help\
"Direction of character increments.
When rainbow is in the colour list,
the colour stripes will be oriented
in this direction.
When rainbow is in the colour list,
the colour stripes will be oriented
in this direction.
"
@values -min 0 -max 1
colour -type list -default {} -optional 1 -help\
"List of Ansi colour names
e.g. testblock -size 10 {white Red}
produces a block of character 10x10
with white text on red bacground
e.g. testblock -size 10 {white Red}
produces a block of character 10x10
with white text on red bacground
The additional pseudo-color 'rainbow'
is available.
The additional pseudo-color 'rainbow'
is available.
"
}
@ -5717,6 +5717,7 @@ tcl::namespace::eval textblock {
"
-ansiresets -type any -default auto
-- -type none -optional 0 -help "end of options marker -- is mandatory because joined blocks may easily conflict with flags"
@values
blocks -type any -multiple 1
}
@ -6095,6 +6096,7 @@ tcl::namespace::eval textblock {
proc welcome_test {} {
package require punk::ansi
package require patternpunk
set ansi [textblock::join -- " " [punk::ansi::ansicat src/testansi/publicdomain/roysac/ROY-WELC.ANS 80x8]]
# Ansi art courtesy of Carsten Cumbrowski aka Roy/SAC - roysac.com
set table [[textblock::spantest] print]
@ -6108,6 +6110,7 @@ tcl::namespace::eval textblock {
proc example {args} {
set opts [tcl::dict::create -forcecolour 0]
package require patternpunk
foreach {k v} $args {
switch -- $k {
-forcecolour {
@ -7981,12 +7984,12 @@ tcl::namespace::eval textblock {
frame -type block -ansiborder [a+ blue Red] -ansibase [a+ black Red] \"A\\nB\""
-checkargs -default 1 -type boolean\
-help "If true do extra argument checks and
provide more comprehensive error info.
As the argument parser loads around 16 default frame
samples dynamically, this can add add up as each may
take 10s of microseconds. For many-framed tables
and other applications this can add up.
Set false for performance improvement."
provide more comprehensive error info.
As the argument parser loads around 16 default frame
samples dynamically, this can add add up as each may
take 10s of microseconds. For many-framed tables
and other applications this can add up.
Set false for performance improvement."
-etabs -default 0\
-help "expanding tabs - experimental/unimplemented."
#review - -choicelabels placeholder dollarsign of textblock::frame_samples must be left aligned with -choicelabels
@ -8000,36 +8003,36 @@ tcl::namespace::eval textblock {
}\
-help "Type of border for frame."
-boxlimits -default {hl vl tlc blc trc brc} -type list -help "Limit the border box to listed elements.
passing an empty string will result in no box, but title/subtitle will still appear if supplied.
${[textblock::EG]}e.g: -frame -boxlimits {} -title things [a+ red White]my\\ncontent${[textblock::RST]}"
passing an empty string will result in no box, but title/subtitle will still appear if supplied.
${[textblock::EG]}e.g: -frame -boxlimits {} -title things [a+ red White]my\\ncontent${[textblock::RST]}"
-boxmap -default {} -type dict
-joins -default {} -type list
-title -default "" -type string -regexprefail {\n}\
-help "Frame title placed on topbar - no newlines.
May contain ANSI - no trailing reset required.
${[textblock::EG]}e.g 1: frame -title My[a+ green]Green[a]Thing
e.g 2: frame -title [a+ red underline]MyThing${[textblock::RST]}"
May contain ANSI - no trailing reset required.
${[textblock::EG]}e.g 1: frame -title My[a+ green]Green[a]Thing
e.g 2: frame -title [a+ red underline]MyThing${[textblock::RST]}"
-titlealign -default "centre" -choices {left centre right}
-subtitle -default "" -type string -regexprefail {\n}\
-help "Frame subtitle placed on bottombar - no newlines
May contain Ansi - no trailing reset required."
May contain Ansi - no trailing reset required."
-subtitlealign -default "centre" -choices {left centre right}
-width -default "" -type int\
-help "Width of resulting frame including borders.
If omitted or empty-string, the width will be determined automatically based on content."
If omitted or empty-string, the width will be determined automatically based on content."
-height -default "" -type int\
-help "Height of resulting frame including borders."
-ansiborder -default "" -type ansistring\
-help "Ansi escape sequence to set border attributes.
${[textblock::EG]}e.g 1: frame -ansiborder [a+ web-red] contents
e.g 2: frame -ansiborder \"\\x1b\\\[31m\" contents${[textblock::RST]}"
${[textblock::EG]}e.g 1: frame -ansiborder [a+ web-red] contents
e.g 2: frame -ansiborder \"\\x1b\\\[31m\" contents${[textblock::RST]}"
-ansibase -default "" -type ansistring\
-help "Default ANSI attributes within frame."
-blockalign -default centre -choices {left right centre}\
-help "Alignment of the content block within the frame."
-pad -default 1 -type boolean -help "Whether to pad within the ANSI so content background
extends within the content block inside the frame.
Has no effect if no ANSI in content."
extends within the content block inside the frame.
Has no effect if no ANSI in content."
-textalign -default left -choices {left right centre}\
-help "Alignment of text within the content block. (centre unimplemented)"
-ellipsis -default 1 -type boolean\
@ -8038,16 +8041,16 @@ tcl::namespace::eval textblock {
-buildcache -default 1 -type boolean
-crm_mode -default 0 -type boolean\
-help "Show ANSI control characters within frame contents.
(Control Representation Mode)
Frame width doesn't adapt and content may be truncated
so -width may need to be manually set to display more."
(Control Representation Mode)
Frame width doesn't adapt and content may be truncated
so -width may need to be manually set to display more."
@values -min 0 -max 1
contents -default "" -type string\
-help "Frame contents - may be a block of text containing newlines and ANSI.
Text may be 'ragged' - ie unequal line-lengths.
No trailing ANSI reset required.
${[textblock::EG]}e.g: frame \"[a+ blue White] \\nMy blue foreground text on\\nwhite background\\n\"${[textblock::RST]}"
Text may be 'ragged' - ie unequal line-lengths.
No trailing ANSI reset required.
${[textblock::EG]}e.g: frame \"[a+ blue White] \\nMy blue foreground text on\\nwhite background\\n\"${[textblock::RST]}"
}
}
@ -8916,15 +8919,16 @@ tcl::namespace::eval textblock {
}
}
punk::args::define {
@id -id ::textblock::gcross
-max_cross_size -default 0 -type integer -help "Largest size cross to use to make up the block
Only cross sizes that divide the size of the overall block will be used.
e.g if the 'size' chosen is 19 (a prime number) - only 1 or the full size of 19 can be used as the crosses to make up the block.
Whereas for a block size of 24, -max_cross_size of 1,2,3,4,6,8,12 or 24 will work. (all divisors)
If a number chosen for -max_cross_size isn't a divisor, the largest divisor below the chosen value will be used.
"
@values -min 0 -max 1
size -default 1 -type integer
@id -id ::textblock::gcross
-max_cross_size -default 0 -type integer -help\
"Largest size cross to use to make up the block
Only cross sizes that divide the size of the overall block will be used.
e.g if the 'size' chosen is 19 (a prime number) - only 1 or the full size of 19 can be used as the crosses to make up the block.
Whereas for a block size of 24, -max_cross_size of 1,2,3,4,6,8,12 or 24 will work. (all divisors)
If a number chosen for -max_cross_size isn't a divisor, the largest divisor below the chosen value will be used.
"
@values -min 0 -max 1
size -default 1 -type integer
}
proc gcross {args} {
set argd [punk::args::parse $args withid ::textblock::gcross]

Loading…
Cancel
Save