[37253] trunk/base/src/port/port.tcl
raimue at macports.org
raimue at macports.org
Sat May 31 22:12:23 PDT 2008
Revision: 37253
http://trac.macosforge.org/projects/macports/changeset/37253
Author: raimue at macports.org
Date: 2008-05-31 22:12:23 -0700 (Sat, 31 May 2008)
Log Message:
-----------
port/port.tcl:
port usage <action> gives the basic usage as in port help <action> on the top
Removed hardcoded values and use action_args_const instead
Modified Paths:
--------------
trunk/base/src/port/port.tcl
Modified: trunk/base/src/port/port.tcl
===================================================================
--- trunk/base/src/port/port.tcl 2008-06-01 05:04:42 UTC (rev 37252)
+++ trunk/base/src/port/port.tcl 2008-06-01 05:12:23 UTC (rev 37253)
@@ -1156,14 +1156,61 @@
# Action Handlers
##########################################
+proc action_get_usage { action } {
+ global action_array cmd_args_array
+
+ if {[info exists action_array($action)]} {
+ set cmds ""
+ if {[info exists cmd_args_array($action)]} {
+ foreach cmd $cmd_args_array($action) {
+ set name [lindex $cmd 0]
+ set argc [lindex $cmd 1]
+
+ append cmds " --$name"
+
+ for {set i 1} {$i <= $argc} {incr i} {
+ append cmds " <arg$i>"
+ }
+ }
+ }
+ set args ""
+ set needed [action_needs_portlist $action]
+ if {[action_args_const strings] == $needed} {
+ set args " <arguments>"
+ } elseif {[action_args_const strings] == $needed} {
+ set args " <portlist>"
+ }
+
+ set ret "Usage: "
+ set len [string length $action]
+ append ret [wrap "$action$cmds$args" [expr 80 - $len] [string repeat " " [expr 8 + $len]] 0]
+ append ret "\n"
+
+ return $ret
+ }
+
+ return -1
+}
+
proc action_usage { action portlist opts } {
- print_usage
- return 0
+ if {[llength $portlist] == 0} {
+ print_usage
+ return 0
+ }
+
+ foreach topic $portlist {
+ set usage [action_get_usage $topic]
+ if {$usage != -1} {
+ puts -nonewline stderr $usage
+ } else {
+ ui_error "No usage for topic $topic"
+ return 1
+ }
+ }
}
proc action_help { action portlist opts } {
- global action_array cmd_args_array
set helpfile "$macports::prefix/var/macports/port-help.tcl"
if {[llength $portlist] == 0} {
@@ -1187,26 +1234,12 @@
return 1
}
- if {[info exists action_array($topic)]} {
- set cmds ""
- if {[info exists cmd_args_array($topic)]} {
- foreach cmd $cmd_args_array($topic) {
- append cmds " --$cmd"
- }
- }
- set args ""
- switch -- [action_needs_portlist $topic] {
- 1 {
- set args " <arguments>"
- }
- 2 {
- set args " <portlist>"
- }
- }
-
- puts -nonewline stderr "Usage: "
- set len [string length $topic]
- puts stderr [wrap "$topic$cmds$args" [expr 80 - $len] [string repeat " " [expr 8 + $len]] 0]
+ set usage [action_get_usage $topic]
+ if {$usage != -1} {
+ puts -nonewline stderr $usage
+ } else {
+ ui_error "No usage for topic $topic"
+ return 1
}
puts stderr $porthelp($topic)
@@ -2410,7 +2443,7 @@
}
}
array set action_array [list \
- usage [list action_usage [action_args_const none]] \
+ usage [list action_usage [action_args_const strings]] \
help [list action_help [action_args_const strings]] \
\
echo [list action_echo [action_args_const ports]] \
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080531/e1872bca/attachment.htm
More information about the macports-changes
mailing list