Skip to content
Permalink
Browse files

port: -D also accepts port names

  • Loading branch information
raimue authored and neverpanic committed Apr 11, 2018
1 parent 133bb21 commit d586977ada727dd46350564d5113de9803797347
Showing with 34 additions and 9 deletions.
  1. +3 −4 doc/port.1
  2. +6 −3 doc/port.1.txt
  3. +25 −2 src/port/port.tcl
@@ -28,7 +28,7 @@ port \- Command line interface for MacPorts

.sp
.nf
\fBport\fR [\fB\-bcdfknNopqRstuvy\fR] [\fB\-D\fR \fIportdir\fR] [\fB\-F\fR \fIcmdfile\fR] [\fIaction\fR] [\fIactionflags\fR]
\fBport\fR [\fB\-bcdfknNopqRstuvy\fR] [\fB\-D\fR \fIportdir\fR|\fIportname\fR] [\fB\-F\fR \fIcmdfile\fR] [\fIaction\fR] [\fIactionflags\fR]
[[\fIportname\fR | \fIpseudo\-portname\fR | \fIport\-expressions\fR | \fIport\-url\fR]]
[[\fI@version\fR] [+/\-variant \&...] \&... [option=value \&...]]
.fi
@@ -652,13 +652,12 @@ Force mode, ignore state file

.RE
.PP
\-D \fIportdir\fR
\-D \fIportdir\fR|\fIportname\fR
.RS 4



Specfiy
\fIportdir\fR
Specify a directory to which the port command should change to before processing any actions\&. If the specified value does not contain any slashes, the value is used to look up a port and the current working directory is set to the corresponding port directory\&.

.RE
.PP
@@ -9,7 +9,7 @@ port - Command line interface for MacPorts
SYNOPSIS
--------
[cmdsynopsis]
*port* [*-bcdfknNopqRstuvy*] [*-D* 'portdir'] [*-F* 'cmdfile'] ['action'] ['actionflags']
*port* [*-bcdfknNopqRstuvy*] [*-D* 'portdir'|'portname'] [*-F* 'cmdfile'] ['action'] ['actionflags']
[['portname' | 'pseudo-portname' | 'port-expressions' | 'port-url']]
[['@version'] [+/-variant ...] ... [option=value ...]]

@@ -191,8 +191,11 @@ The port command recognizes several global flags and options.
-f::
Force mode, ignore state file
-D 'portdir'::
Specfiy 'portdir'
-D 'portdir'|'portname'::
Specify a directory to which the port command should change to before
processing any actions. If the specified value does not contain any slashes,
the value is used to look up a port and the current working directory is set
to the corresponding port directory.
-F 'cmdfile'::
Read and process the 'file' of commands specified by the argument. If the
@@ -50,7 +50,7 @@ package require Pextlib 1.0
proc print_usage {{verbose 1}} {
global cmdname
set syntax {
[-bcdfknNopqRstuvy] [-D portdir] [-F cmdfile] action [actionflags]
[-bcdfknNopqRstuvy] [-D portdir|portname] [-F cmdfile] action [actionflags]
[[portname|pseudo-portname|port-url] [@version] [+-variant]... [option=value]...]...
}

@@ -4573,7 +4573,7 @@ proc parse_options { action ui_options_name global_options_name } {
D {
advance
if {[moreargs]} {
cd [lookahead]
set global_options(ports_dir) [lookahead]
}
break
}
@@ -5693,6 +5693,29 @@ if {[catch {mportinit ui_options global_options global_variations} result]} {
fatal "Failed to initialize MacPorts, $result"
}

# Change to port directory if requested
if {[info exists global_options(ports_dir)]} {
set dir $global_options(ports_dir)
if {[string first "/" $dir] == -1} {
set portname $dir
if {[catch {mportlookup $portname} result]} {
ui_debug $::errorInfo
fatal "lookup of portname $portname failed: $result"
}
if {[llength $result] < 2} {
ui_error "port -D failed to look up $portname: no such port"
exit 1
}
array set portinfo [lindex $result 1]
set dir [macports::getportdir $portinfo(porturl)]
}
if {[catch {cd $dir} result]} {
ui_debug "cd $dir: $::errorCode"
ui_error "port -D could not change directory to $dir: [lindex $::errorCode 2]"
exit 1
}
}

# Set up some global state for our code
set current_portdir [pwd]

0 comments on commit d586977

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