Skip to content

Commit 15591e5

Browse files
committed
Core code for cmdModuleStashlist
Implement 'stashlist' sub-command. Rely on cmdModuleSavelist but adapt this procedure to make several behavior changes when called by cmdModuleStashlist: * elements are sorted in reverse order * element index starts at 0 * when no collection target set, only return collection without a target set
1 parent 4086735 commit 15591e5

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

tcl/subcmd.tcl.in

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -749,25 +749,50 @@ proc cmdModuleSavelist {show_oneperline show_mtime search_match args} {
749749

750750
reportDebug "list collections$targetdesc"
751751

752+
# if only stash collection are expected, start result index at 0, sort
753+
# results in reverse order (latest first) and ensure only collection from
754+
# current target (and no-target if none set) are returned.
755+
if {[getCallingProcName] eq {cmdModuleStashlist}} {
756+
set start_idx 0
757+
set sort_opts [list -dictionary -decreasing]
758+
set find_no_other_target 1
759+
set typedesc stash
760+
# no icase match as stash collections are only lowercases
761+
set icase 0
762+
} else {
763+
set start_idx 1
764+
set sort_opts [list -dictionary]
765+
set find_no_other_target 0
766+
set typedesc named
767+
set icase [isIcase]
768+
}
769+
752770
if {[llength $args] > 0} {
753-
defineModEqProc [isIcase] 0
771+
defineModEqProc $icase 0
754772
# match passed name against any part of collection names
755773
set mtest [expr {{contains} in $search_match ? {matchin} : {match}}]
756-
# prepare header message which depend if search is performed
757-
set collmsg "Matching named collection list$targetdesc:"
774+
}
775+
776+
# prepare header message which depend if search is performed (no search
777+
# considered if listing stash collections)
778+
if {[llength $args] > 0 && $typedesc ne {stash}} {
779+
set collmsg "Matching $typedesc collection list$targetdesc:"
758780
} else {
759-
set collmsg "Named collection list$targetdesc:"
781+
set collmsg "[string totitle $typedesc] collection list$targetdesc:"
760782
}
761783

762-
foreach collfile [findCollections] {
784+
foreach collfile [findCollections * glob 0 0 1 $find_no_other_target] {
763785
# remove target suffix from names to display
764786
regsub $suffix$ [file tail $collfile] {} coll
765787
set coll_arr($coll) $collfile
766788
}
767789

768790
# same header msg if no collection at all whether search is made or not
769-
set nocollmsg [expr {![array exists coll_arr] ? "No named\
770-
collection$targetdesc." : "No matching named collection$targetdesc."}]
791+
if {![array exists coll_arr] || $typedesc eq {stash}} {
792+
set nocollmsg "No $typedesc collection$targetdesc."
793+
} else {
794+
set nocollmsg "No matching $typedesc collection$targetdesc."
795+
}
771796

772797
# filter collection not matching any of the passed specification
773798
if {[llength $args] > 0} {
@@ -808,7 +833,7 @@ proc cmdModuleSavelist {show_oneperline show_mtime search_match args} {
808833
# prepare query to highlight
809834
set himatchmap [prepareMapToHightlightSubstr {*}$args]
810835

811-
foreach coll [lsort -dictionary [array names coll_arr]] {
836+
foreach coll [lsort {*}$sort_opts [array names coll_arr]] {
812837
if {$json} {
813838
lappend display_list [formatListEltToJsonDisplay $coll target s\
814839
$colltarget 1 pathname s $coll_arr($coll) 1]
@@ -2834,6 +2859,7 @@ proc cmdModuleStashclear {} {
28342859
}
28352860

28362861
proc cmdModuleStashlist {show_oneperline show_mtime} {
2862+
cmdModuleSavelist $show_oneperline $show_mtime {} stash-*
28372863
}
28382864

28392865
# ;;; Local Variables: ***

0 commit comments

Comments
 (0)