From 941735ce6fcfe9d828d580a00cffd3f338e57fbd Mon Sep 17 00:00:00 2001 From: Julian Noble Date: Fri, 1 Aug 2025 03:37:40 +1000 Subject: [PATCH] punk::args fix, dev lib.search fixes and docs --- src/modules/picalc-999999.0a1.0.tm | 21 ++++--- src/modules/punk/args-999999.0a1.0.tm | 21 +++++-- .../mix/commandset/loadedlib-999999.0a1.0.tm | 56 +++++++++++++++---- src/modules/punk/path-999999.0a1.0.tm | 37 +++++++++++- 4 files changed, 107 insertions(+), 28 deletions(-) diff --git a/src/modules/picalc-999999.0a1.0.tm b/src/modules/picalc-999999.0a1.0.tm index d5676271..b3ab820c 100644 --- a/src/modules/picalc-999999.0a1.0.tm +++ b/src/modules/picalc-999999.0a1.0.tm @@ -46,7 +46,7 @@ #[list_begin itemized] package require Tcl 8.6- -package require punk::lib +package require punk::lib package require punk::args #*** !doctools #[item] [package {Tcl 8.6}] @@ -73,10 +73,18 @@ tcl::namespace::eval picalc { # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #*** !doctools #[subsection {Namespace picalc}] - #[para] Core API functions for picalc + #[para] Core API functions for picalc #[list_begin definitions] variable PUNKARGS + variable PUNKARGS_aliases + + lappend PUNKARGS [list { + @id -id "(package)picalc" + @package -name "picalc"\ + -help\ + "A test/learning experimental package for pi calculation" + }] @@ -475,15 +483,6 @@ tcl::namespace::eval picalc::lib { # == === === === === === === === === === === === === === === tcl::namespace::eval picalc { tcl::namespace::export {[a-z]*} ;# Convention: export all lowercase - variable PUNKARGS - variable PUNKARGS_aliases - - lappend PUNKARGS [list { - @id -id "(package)picalc" - @package -name "picalc" -help\ - "Package - Description" - }] namespace eval argdoc { #namespace for custom argument documentation diff --git a/src/modules/punk/args-999999.0a1.0.tm b/src/modules/punk/args-999999.0a1.0.tm index d6a198ab..b35a0094 100644 --- a/src/modules/punk/args-999999.0a1.0.tm +++ b/src/modules/punk/args-999999.0a1.0.tm @@ -2606,11 +2606,11 @@ tcl::namespace::eval punk::args { @values {set defaults_key VALSPEC_DEFAULTS} } if {[dict exists $opt_override $type]} { - append result \n "$type [dict merge [dict get $specdict FORMS $formname LEADERSPEC_DEFAULTS] [dict get $opt_override $type]]" - dict set resultdict $type [dict merge [dict get $specdict FORMS $formname LEADERSPEC_DEFAULTS] [dict get $opt_override $type]] + append result \n "$type [dict merge [dict get $specdict FORMS $formname $defaults_key] [dict get $opt_override $type]]" + dict set resultdict $type [dict merge [dict get $specdict FORMS $formname $defaults_key] [dict get $opt_override $type]] } else { - append result \n "$type [dict get $specdict FORMS $formname LEADERSPEC_DEFAULTS]" - dict set resultdict $type [dict get $specdict FORMS $formname LEADERSPEC_DEFAULTS] + append result \n "$type [dict get $specdict FORMS $formname $defaults_key]" + dict set resultdict $type [dict get $specdict FORMS $formname $defaults_key] } } } @@ -2856,6 +2856,19 @@ tcl::namespace::eval punk::args { return $result } + lappend PUNKARGS [list { + @id -id ::punk::args::update_definitions + @cmd -name punk::args::update_definitions\ + -summary\ + ""\ + -help\ + "" + @values -min 1 + id + arglist -type list -help\ + "list containing arguments to be parsed as per the + argument specification identified by the supplied id." + }] #scanned_packages (list) #namespace_docpackages (dict) proc update_definitions {{nslist *}} { diff --git a/src/modules/punk/mix/commandset/loadedlib-999999.0a1.0.tm b/src/modules/punk/mix/commandset/loadedlib-999999.0a1.0.tm index 28b6e98a..8328ef27 100644 --- a/src/modules/punk/mix/commandset/loadedlib-999999.0a1.0.tm +++ b/src/modules/punk/mix/commandset/loadedlib-999999.0a1.0.tm @@ -35,23 +35,39 @@ namespace eval punk::mix::commandset::loadedlib { -highlight -type boolean -default 1 -help\ "Highlight which version is present with ansi underline and colour" -refresh -default 0 -type boolean -help "Re-scan the tm and library folders" - searchstrings -default * -multiple 1 -help\ + searchstring -default * -multiple 1 -help\ "Names to search for, may contain glob chars (* ?) e.g *lib* - If no glob chars are explicitly specified, the searchstring will be wrapped with star globs. - eg name -> *name* - To search for an exact name prefix it with = - e.g =name -> name - " + If no glob chars are explicitly specified, the searchstring will be wrapped with star globs. + eg name -> *name* + To search for an exact name prefix it with = + e.g =name -> name + If search is not prefixed with '=' the search is case insensitive." } proc search {args} { set argd [punk::args::get_by_id ::punk::mix::commandset::loadedlib::search $args] - set searchstrings [dict get $argd values searchstrings] + set searchstrings [dict get $argd values searchstring] set opts [dict get $argd opts] set opt_return [dict get $opts -return] set opt_highlight [dict get $opts -highlight] + set opt_refresh [dict get $opts -refresh] + + if {$opt_refresh} { + catch {package require frobznodule666} ;#ensure pkg system has loaded/searched for everything REVIEW - this doesn't result in full scans + foreach tm_path [tcl::tm::list] { + set paths_below [punk::path::subfolders -recursive $tm_path] + foreach folder $paths_below { + set tail [file tail $folder] + if {[string match #modpod-* $tail] || [string match #tarjar-* $tail]} { + continue + } + if {[string match */_build/* $folder]} {continue} + set relpath [string tolower [punk::path::relative $tm_path $folder]] + set modpath [string map {/ ::} $relpath] + catch {package require ${modpath}::flobrudder99} + } + } + } - #REVIEW - this doesn't result in full scans - catch {package require frobznodule666} ;#ensure pkg system has loaded/searched for everything set packages [package names] set matches [list] @@ -122,9 +138,25 @@ namespace eval punk::mix::commandset::loadedlib { } } } - proc loaded.search {searchstring} { - set search_result [search $searchstring] - set all_libs [split $search_result \n] + + punk::args::define { + @id -id ::punk::mix::commandset::loadedlib::loaded.search + @cmd -name "punk::mix::commandset::loadedlib loaded.search"\ + -summary\ + "Search loaded libraries."\ + -help "search all Tcl libraries currently loaded in your local interpreter. + ie those that have been loaded directly or indirectly by 'package require'." + }\ + @values\ + [punk::args::resolved_def -types values ::punk::mix::commandset::loadedlib::search searchstring] + + proc loaded.search {args} { + set argd [punk::args::parse $args withid ::punk::mix::commandset::loadedlib::loaded.search] + lassign [dict values $argd] leaders opts values + set searchstrings [dict get $values searchstring] + + set all_libs [search -return list -highlight 0 {*}$searchstrings] + set col1items [list] set col2items [list] set col3items [list] diff --git a/src/modules/punk/path-999999.0a1.0.tm b/src/modules/punk/path-999999.0a1.0.tm index cb22d0cd..965d73fc 100644 --- a/src/modules/punk/path-999999.0a1.0.tm +++ b/src/modules/punk/path-999999.0a1.0.tm @@ -99,7 +99,7 @@ package require punk::args # Base namespace # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ namespace eval punk::path { - namespace export * + namespace export {[a-z]*} #variable xyz #*** !doctools @@ -645,6 +645,41 @@ namespace eval punk::path { } return $ismatch } + punk::args::define { + @id -id ::punk::path::subfolders + @cmd -name punk::path::subfolders\ + -summary\ + "Listing of directories within supplied path."\ + -help\ + "List of folders below path. + The resulting list is unsorted." + @opts + -recursive -type none -help\ + "" + #todo -depth + @values -min 0 -max 1 + path -type directory -optional 1 -help\ + "Path of folder. If not supplied current directory is used." + } + proc subfolders {args} { + set argd [punk::args::parse $args withid ::punk::path::subfolders] + lassign [dict values $argd] leaders opts values received + set do_recursion [dict exists $received -recursive] + if {[dict exists $received path]} { + set path [dict get $values path] + } else { + set path [pwd] + } + set folders [glob -nocomplain -directory $path -types d *] + if {$do_recursion} { + foreach subdir $folders { + lappend folders {*}[subfolders -recursive $subdir] + } + } + return $folders + } + + #todo - treefolders with similar search caps as treefilenames punk::args::define { @id -id ::punk::path::treefilenames