You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.7 KiB
132 lines
4.7 KiB
# -*- tcl -*- |
|
# Maintenance Instruction: leave the 999999.xxx.x as is and use 'pmix make' or src/make.tcl to update from <pkg>-buildversion.txt |
|
# |
|
# 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) 2023 |
|
# |
|
# @@ Meta Begin |
|
# Application punkboot::utils 0.1.0 |
|
# Meta platform tcl |
|
# Meta license BSD |
|
# @@ Meta End |
|
|
|
|
|
|
|
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
|
## Requirements |
|
##e.g package require frobz |
|
package require Tcl 8.6- |
|
|
|
|
|
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
|
namespace eval punkboot::utils { |
|
variable version 0.1.0 |
|
namespace export parse_punkproject_version read_punkproject_version read_changelog_latest_version |
|
|
|
|
|
namespace eval argdoc { |
|
lappend PUNKARGS [list { |
|
@id -id ::punkboot::utils::parse_punkproject_version |
|
@cmd -name "::punkboot::utils::parse_punkproject_version"\ |
|
-summary\ |
|
"Parse the [project] version from TOML content string"\ |
|
-help\ |
|
"Scans TOML content for the [project] section and returns |
|
the value of the version key as a string. Returns an empty |
|
string if the section or key is not found." |
|
@leaders |
|
content -type string -optional 0 -help\ |
|
"TOML content string to parse" |
|
}] |
|
} |
|
proc parse_punkproject_version {content} { |
|
set in_project 0 |
|
foreach line [split $content \n] { |
|
set trimmed [string trim $line] |
|
if {[string index $trimmed 0] eq {[} && [string index $trimmed end] eq {]}} { |
|
set in_project [expr {$trimmed eq "\[project\]"}] |
|
continue |
|
} |
|
if {$in_project && [regexp {^version\s*=\s*"([^"]+)"} $trimmed _ v]} { |
|
return $v |
|
} |
|
} |
|
return "" |
|
} |
|
|
|
|
|
namespace eval argdoc { |
|
lappend PUNKARGS [list { |
|
@id -id ::punkboot::utils::read_punkproject_version |
|
@cmd -name "::punkboot::utils::read_punkproject_version"\ |
|
-summary\ |
|
"Read the [project] version from a TOML file"\ |
|
-help\ |
|
"Reads the file at tomlfile and returns the [project] |
|
version value as a string. Returns an empty string if the |
|
file does not exist or the version is not found." |
|
@leaders |
|
tomlfile -type string -optional 0 -help\ |
|
"Path to the TOML file to read" |
|
}] |
|
} |
|
proc read_punkproject_version {tomlfile} { |
|
if {![file exists $tomlfile]} {return ""} |
|
set fh [open $tomlfile r] |
|
try { |
|
set content [read $fh] |
|
} finally { |
|
close $fh |
|
} |
|
return [::punkboot::utils::parse_punkproject_version $content] |
|
} |
|
|
|
|
|
namespace eval argdoc { |
|
lappend PUNKARGS [list { |
|
@id -id ::punkboot::utils::read_changelog_latest_version |
|
@cmd -name "::punkboot::utils::read_changelog_latest_version"\ |
|
-summary\ |
|
"Read the latest ## [X.Y.Z] version header from a changelog file"\ |
|
-help\ |
|
"Scans the changelog file from the top and returns the |
|
version string from the first '## [X.Y.Z]' header line. |
|
Returns an empty string if the file does not exist or no |
|
matching header is found." |
|
@leaders |
|
changelogfile -type string -optional 0 -help\ |
|
"Path to the changelog file to read" |
|
}] |
|
} |
|
proc read_changelog_latest_version {changelogfile} { |
|
if {![file exists $changelogfile]} {return ""} |
|
set fh [open $changelogfile r] |
|
try { |
|
set content [read $fh] |
|
} finally { |
|
close $fh |
|
} |
|
foreach line [split $content \n] { |
|
if {[regexp {^##\s*\[([0-9][^\]]*)\]} $line _ v]} { |
|
return $v |
|
} |
|
} |
|
return "" |
|
} |
|
} |
|
|
|
namespace eval ::punk::args::register { |
|
#use fully qualified so 8.6 doesn't find existing var in global namespace |
|
lappend ::punk::args::register::NAMESPACES ::punkboot::utils ::punkboot::utils::argdoc |
|
} |
|
|
|
## Ready |
|
package provide punkboot::utils [tcl::namespace::eval punkboot::utils { |
|
variable version |
|
#- this version number, exactly 0.1.0, is a literal used in src module folders |
|
#- we refer to this sometimes as the magic version number |
|
set version 0.1.0 |
|
}] |
|
return
|
|
|