<pre style='margin:0'>
Mojca Miklavec (mojca) pushed a commit to branch master
in repository macports-contrib.
</pre>
<p><a href="https://github.com/macports/macports-contrib/commit/da6e3cf4cfbb8ef2e68e3ca89bcd5db9869d1437">https://github.com/macports/macports-contrib/commit/da6e3cf4cfbb8ef2e68e3ca89bcd5db9869d1437</a></p>
<pre style="white-space: pre; background: #F8F8F8">The following commit(s) were added to refs/heads/master by this push:
<span style='display:block; white-space:pre;color:#404040;'> new da6e3cf portindex2json.tcl: Add support for supplying commit hash
</span>da6e3cf is described below
<span style='display:block; white-space:pre;color:#808000;'>commit da6e3cf4cfbb8ef2e68e3ca89bcd5db9869d1437
</span>Author: arjunsalyan <arjunsalyan@icloud.com>
AuthorDate: Mon Jul 1 16:03:04 2019 +0530
<span style='display:block; white-space:pre;color:#404040;'> portindex2json.tcl: Add support for supplying commit hash
</span>---
portindex2json/portindex2json.tcl | 75 ++++++++++++++++++++++++++++++++++++---
1 file changed, 71 insertions(+), 4 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/portindex2json/portindex2json.tcl b/portindex2json/portindex2json.tcl
</span><span style='display:block; white-space:pre;color:#808080;'>index 7557264..7a9ff70 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/portindex2json/portindex2json.tcl
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/portindex2json/portindex2json.tcl
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2,8 +2,11 @@
</span> # a list of JSON objects.
# Written by Joshua Root <jmr@macports.org>, 2017
# Requires: tclsh with the tcllib 'json' package.
<span style='display:block; white-space:pre;background:#ffe0e0;'>-# Usage: tclsh portindex2json.tcl path/to/PortIndex
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Usage:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# tclsh portindex2json.tcl path/to/PortIndex [--info <key>=<value>]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# tclsh portindex2json.tcl --help
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#
</span> # To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -64,7 +67,65 @@ proc remove_extra_braces {text} {
</span> return [regsub -all {[\{\}]} $text ""]
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-set fd [open [lindex $argv 0] r]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+proc print_usage {} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stdout ""
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stdout "Usage:"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stdout " /path/to/tclsh portindex2json.tcl \[--info <key>=<value>\] <path/to/PortIndex>"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stdout " /path/to/tclsh portindex2json.tcl --help"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stdout ""
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stdout "Each '--info <key>=<value>' combinaton adds one key-value pair to the JSON output inside the parent key: \"info\""
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stdout "You may provide any number of '--info <key>=<value>' combinations."
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stdout ""
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+proc parse_options {} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ global argc argv fd json_info
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for {set i 0} {$i < $argc} {incr i} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set arg [lindex $argv $i]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ switch -regex -- $arg {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {^-.+} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {$arg eq "--info"} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ incr i
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set argument [split [lindex $argv $i] =]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[lindex $argument 1] eq ""} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stderr "\nERROR: No value provided for the key: '[lindex $argument 0]'. The correct syntax is '--info <key>=<value>'.\n"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ exit 1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set json_info([lindex $argument 0]) [::json::write string [lindex $argument 1]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } elseif {$arg eq "-help" || $arg eq "-h" || $arg eq "--help" } {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ print_usage
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ exit 0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stderr "\nERROR: '$arg' is an invalid argument (expecting '--help' or '--info').\n"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ print_usage
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ exit 1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ default {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[info exists fd]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stderr "\nERROR: No support for more than one argument for path to the PortIndex file.\n"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ print_usage
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ exit 1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[catch {set fd [open [lindex $argv $i] r]} fid]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stderr "\nERROR: Could not open file '[lindex $argv $i]'. Make sure the path to the PortIndex file is correct.\n"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ exit 1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {![info exists fd]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts stderr "\nERROR: Path to the PortIndex file missing.\n"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ print_usage
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ exit 1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+parse_options
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> chan configure $fd -encoding utf-8
while {[gets $fd line] >= 0} {
if {[llength $line] != 2} {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -90,5 +151,11 @@ while {[gets $fd line] >= 0} {
</span> lappend objects [::json::write object {*}[array get json_portinfo]]
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+if {[array exists json_info]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set json_output(info) [::json::write object {*}[array get json_info]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+set json_output(ports) [::json::write array {*}$objects]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> chan configure stdout -encoding utf-8
<span style='display:block; white-space:pre;background:#ffe0e0;'>-puts [::json::write array {*}$objects]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+puts [::json::write object {*}[array get json_output]]
</span></pre><pre style='margin:0'>
</pre>