Projects
New Ticket     Wiki     Browse Source     Timeline     Roadmap     Bug Reports     Search

Changeset 37253 for trunk/base/src

Show
Ignore:
Timestamp:
05/31/08 22:12:23 (6 months ago)
Author:
raimue@…
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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port/port.tcl

    r37251 r37253  
    11571157########################################## 
    11581158 
     1159proc action_get_usage { action } { 
     1160    global action_array cmd_args_array 
     1161 
     1162    if {[info exists action_array($action)]} { 
     1163        set cmds "" 
     1164        if {[info exists cmd_args_array($action)]} { 
     1165            foreach cmd $cmd_args_array($action) { 
     1166                set name [lindex $cmd 0] 
     1167                set argc [lindex $cmd 1] 
     1168 
     1169                append cmds " --$name" 
     1170 
     1171                for {set i 1} {$i <= $argc} {incr i} { 
     1172                    append cmds " <arg$i>" 
     1173                } 
     1174            } 
     1175        } 
     1176        set args "" 
     1177        set needed [action_needs_portlist $action] 
     1178        if {[action_args_const strings] == $needed} { 
     1179            set args " <arguments>" 
     1180        } elseif {[action_args_const strings] == $needed} { 
     1181            set args " <portlist>" 
     1182        } 
     1183 
     1184        set ret "Usage: " 
     1185        set len [string length $action] 
     1186        append ret [wrap "$action$cmds$args" [expr 80 - $len] [string repeat " " [expr 8 + $len]] 0] 
     1187        append ret "\n" 
     1188 
     1189        return $ret 
     1190    } 
     1191 
     1192    return -1 
     1193} 
     1194 
    11591195proc action_usage { action portlist opts } { 
    1160     print_usage 
    1161     return 0 
     1196    if {[llength $portlist] == 0} { 
     1197        print_usage 
     1198        return 0 
     1199    } 
     1200 
     1201    foreach topic $portlist { 
     1202        set usage [action_get_usage $topic] 
     1203        if {$usage != -1} { 
     1204           puts -nonewline stderr $usage 
     1205        } else { 
     1206            ui_error "No usage for topic $topic" 
     1207            return 1 
     1208        } 
     1209    } 
    11621210} 
    11631211 
    11641212 
    11651213proc action_help { action portlist opts } { 
    1166     global action_array cmd_args_array 
    11671214    set helpfile "$macports::prefix/var/macports/port-help.tcl" 
    11681215 
     
    11881235        } 
    11891236 
    1190         if {[info exists action_array($topic)]} { 
    1191             set cmds "" 
    1192             if {[info exists cmd_args_array($topic)]} { 
    1193                 foreach cmd $cmd_args_array($topic) { 
    1194                     append cmds " --$cmd" 
    1195                 } 
    1196             } 
    1197             set args "" 
    1198             switch -- [action_needs_portlist $topic] { 
    1199                 1 { 
    1200                     set args " <arguments>" 
    1201                 } 
    1202                 2 { 
    1203                     set args " <portlist>" 
    1204                 } 
    1205             } 
    1206  
    1207             puts -nonewline stderr "Usage: " 
    1208             set len [string length $topic] 
    1209             puts stderr [wrap "$topic$cmds$args" [expr 80 - $len] [string repeat " " [expr 8 + $len]] 0] 
     1237        set usage [action_get_usage $topic] 
     1238        if {$usage != -1} { 
     1239           puts -nonewline stderr $usage 
     1240        } else { 
     1241            ui_error "No usage for topic $topic" 
     1242            return 1 
    12101243        } 
    12111244 
     
    24112444} 
    24122445array set action_array [list \ 
    2413     usage       [list action_usage          [action_args_const none]] \ 
     2446    usage       [list action_usage          [action_args_const strings]] \ 
    24142447    help        [list action_help           [action_args_const strings]] \ 
    24152448    \