Skip to content
Permalink
Browse files

port-info: output fields in the order given on the command line (#103)

* port-info: output fields in the order given on the command line

Currently due to the use of 'array names', the output of
'port info --multiple-fields' are displayed in a random order.
Now, the fields are kept in a list which preserves their order they
were given on the command line.
This has the effect of also allowing duplicate fields to be displayed.

Also, the order of arguments given on the command line are available
for any action (not just info).

Closes: https://trac.macports.org/ticket/57003
  • Loading branch information
kurthindenburg committed Apr 20, 2019
1 parent db19f81 commit e115b59055a4e5ef7c669990cf86dd39be7ab9b3
Showing with 20 additions and 2 deletions.
  1. +20 −2 src/port/port.tcl
@@ -1912,7 +1912,8 @@ proc action_log { action portlist opts } {


proc action_info { action portlist opts } {
global global_variations
global global_options global_variations

set status 0
if {[require_portlist portlist]} {
return 1
@@ -2094,7 +2095,20 @@ proc action_info { action portlist opts } {

# Spin through action options, emitting information for any found
set fields {}
set opts_todo [array names options ports_info_*]

# This contains the display fields in random order
set opts_info [array names options ports_info_*]
# This contains all parameters in order given on command line
set opts_action $global_options(options_${action}_order)
# Get the display fields in order provided on command line
# ::struct::set intersect does not keep order of items
set opts_todo {}
foreach elem $opts_action {
if {$elem in $opts_info} {
lappend opts_todo $elem
}
}

set fields_tried {}
if {![llength $opts_todo]} {
set opts_todo {ports_info_heading
@@ -4468,6 +4482,8 @@ proc parse_options { action ui_options_name global_options_name } {
upvar $ui_options_name ui_options
upvar $global_options_name global_options

set options_order(${action}) {}

while {[moreargs]} {
set arg [lookahead]

@@ -4495,6 +4511,7 @@ proc parse_options { action ui_options_name global_options_name } {
set kargc [lindex $kopts 0 1]
if {$kargc == 0} {
set global_options(ports_${action}_${key}) yes
lappend options_order(${action}) ports_${action}_${key}
} else {
set args {}
while {[moreargs] && $kargc > 0} {
@@ -4591,6 +4608,7 @@ proc parse_options { action ui_options_name global_options_name } {

advance
}
set global_options(options_${action}_order) $options_order(${action})
}

# acquire exclusive registry lock for actions that need it

0 comments on commit e115b59

Please sign in to comment.
You can’t perform that action at this time.