Skip to content

Commit a37579c

Browse files
committed
Tweak Zsh completions and allow completion on ports tree
- Ensure that mutually exclusive options are not both completed. For example, in the '-a' specification for the 'bulk' action shown below, the (-f *) indicates that if '-a' has been specified, then do not complete either '-f' or a ports tree. '(-f *)-a[build the whole ports tree]' - Ensure that mandatory arguments are properly completed. For example, in the '-p' specifications show below, in the first form, the ports tree is optional and in the second form it is mandatory. -p+[specifies which ports tree to use]::tree:_poudriere_pt -p+[specifies which ports tree to use]:tree:_poudriere_pt
1 parent ef45265 commit a37579c

File tree

1 file changed

+88
-55
lines changed

1 file changed

+88
-55
lines changed

completions/zsh/_poudriere

Lines changed: 88 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,38 @@ _poudriere_pt() {
88
_values "poudriere portstrees" ${${(f)"$(${service} ports -lq)"}%% *}
99
}
1010

11+
_poudriere_direct_port() {
12+
# Find a ports tree to complete ports
13+
local prev_word=
14+
local ports_tree=
15+
local w
16+
17+
# Determine whether a tree has already been specified with -p
18+
for w in ${words[@]}; do
19+
if [[ $w == -p ]]; then
20+
prev_word=-p
21+
elif [[ $prev_word == -p ]]; then
22+
ports_tree="$w"
23+
break
24+
fi
25+
done
26+
27+
# Determine whether the default tree is present
28+
if [[ -z $ports_tree ]] && poudriere ports -l | grep -q '^default '; then
29+
ports_tree=default
30+
elif [[ -z $ports_tree ]]; then
31+
return
32+
fi
33+
34+
local ports_tree_path="$(poudriere ports -lq | awk -v tree=$ports_tree '{if (match($1, tree)) {print $5}}')"
35+
36+
# complete port
37+
_path_files -W ${ports_tree_path} -/
38+
}
39+
1140
_bulk=(
12-
'-a[build the whole ports tree]'
13-
'-f[get the list of ports to build from a file]:name of file:_files'
41+
'(-f *)-a[build the whole ports tree]'
42+
'(-a *)-f[get the list of ports to build from a file]:name of file:_files'
1443
'-b[specify what binary package branch to use]::'
1544
'-B[what buildname to use]:buildname'
1645
'-c[clean all the previously built binary packages and logs]'
@@ -25,13 +54,14 @@ _bulk=(
2554
'-T[try to build broken ports anyway]'
2655
'-F[only fetch from original master_site (skip FreeBSD mirrors)]'
2756
'-S[don\x27t recursively rebuild packages affected by other packages requiring incremental rebuild]'
28-
'-J[run n jobs in parallel, and optionally run a different number of jobs in parallel while preparing the build]::'
29-
'-j[run only on the given jail]::jail name:_poudriere_jail'
57+
'-J[run n jobs in parallel, and optionally run a different number of jobs in parallel while preparing the build]:'
58+
'-j[run only on the given jail]:jail name:_poudriere_jail'
3059
'-N[do not build package repository or INDEX when build completed]'
31-
'-p[specify on which ports tree the bulk build will be done]::tree:_poudriere_pt'
60+
'-p[specify on which ports tree the bulk build will be done]:tree:_poudriere_pt'
3261
'-v[be verbose; show more information. Use twice to enable debug output]'
3362
'-w[save WRKDIR on failed builds]'
34-
'-z[specify which SET to use]::'
63+
'-z[specify which SET to use]:'
64+
'(-a -f)*:cat/port:_poudriere_direct_port'
3565
)
3666

3767
_daemon=(
@@ -43,8 +73,8 @@ _daemon=(
4373
_distclean=(
4474
'-a[clean the whole ports tree]'
4575
'-f[get the list of ports to clean from a file]:name of file:_files'
46-
'-J[run n jobs in parallel]::'
47-
'-p[specify which ports tree to use for comparing to distfiles, can be specified multiple times]::tree:_poudriere_pt'
76+
'-J[run n jobs in parallel]:'
77+
'-p[specify which ports tree to use for comparing to distfiles, can be specified multiple times]:tree:_poudriere_pt'
4878
'-n[do not actually remove anything, just show what would be removed]::'
4979
'-v[be verbose; show more information. use twice to enable debug output]'
5080
'-y[assume yes when deleting and do not prompt for confirmation]::'
@@ -54,15 +84,15 @@ _image=(
5484
'-c[the content of the overlay directory will be copied into the image]:directory:_files'
5585
'-f[list of packages to install]:file:_files'
5686
'-h[the image hostname]:hostname:'
57-
'-j[jail]::jailname:_poudriere_jail'
87+
'-j[jail]:jailname:_poudriere_jail'
5888
'-m[build a miniroot image as well (for tar type images), and overlay this directory into the miniroot image]:directory:_files'
5989
'-n[the name of the generated image]:imagename:'
6090
'-o[image destination directory]:directory:_files'
61-
'-p[Ports tree]::tree:_poudriere_pt'
91+
'-p[Ports tree]:tree:_poudriere_pt'
6292
'-s[set the image size]:size:'
63-
'-t[type of image]::type:((iso iso+mfs iso+zmfs usb usb+mfs usb+zmfs rawdisk zrawdisk tar firmware rawfirmware))'
93+
'-t[type of image]:type:((iso iso+mfs iso+zmfs usb usb+mfs usb+zmfs rawdisk zrawdisk tar firmware rawfirmware))'
6494
'-X[file containing the list in cpdup format]:file:_files'
65-
'-z[set]::'
95+
'-z[set]:'
6696
)
6797

6898
_jail=(
@@ -73,82 +103,83 @@ _jail=(
73103
'(-c -d -i -l -k -u -r)-s[start a jail]'
74104
'(-c -d -i -l -s -u -r)-k[stop a jail]'
75105
'(-c -d -i -l -s -k -r)-u[update a jail]'
76-
'(-c -d -i -l -s -k -u)-r[rename a jail to name]::name'
106+
'(-c -d -i -l -s -k -u)-r[rename a jail to name]:name'
77107
'-b[build the OS (for use with -m src)]'
78108
'-q[quiet (do not print the header)]'
79-
'-J[run buildworld in parallel with n jobs]::'
80-
'-j[specifies the jailname]::jailname:_poudriere_jail'
81-
'-v[specify which version of FreeBSD to install in the jail]::version'
82-
'-a[indicates the TARGET_ARCH of the jail. Such as i386 or amd64]::arch:(amd64 i386)'
83-
'-f[fs name (tank/jails/myjail) if fs is "none" then do not create on ZFS]::fs:_files -/'
84-
'-K[build the jail with the kernel]::kernelname'
85-
'-M[mountpoint]::mountpoint:_files -/'
86-
'-m[when used with -c, overrides the default method for obtaining and building the jail.]::method:(allbsd ftp-archive ftp git http null src svn svn+file svn+http svn+https svn+ssh tar url)'
87-
'-P[specify a patch to apply to the source before building]::patch:_files -/'
88-
'-S[specify a path to the source tree to be used]::srcpath:_files -/'
109+
'-J[run buildworld in parallel with n jobs]:'
110+
'-j[specifies the jailname]:jailname:_poudriere_jail'
111+
'-v[specify which version of FreeBSD to install in the jail]:version'
112+
'-a[indicates the TARGET_ARCH of the jail. Such as i386 or amd64]:arch:(amd64 i386)'
113+
'-f[fs name (tank/jails/myjail) if fs is "none" then do not create on ZFS]:fs:_files -/'
114+
'-K[build the jail with the kernel]:kernelname'
115+
'-M[mountpoint]:mountpoint:_files -/'
116+
'-m[when used with -c, overrides the default method for obtaining and building the jail.]:method:(allbsd ftp-archive ftp git http null src svn svn+file svn+http svn+https svn+ssh tar url)'
117+
'-P[specify a patch to apply to the source before building]:patch:_files -/'
118+
'-S[specify a path to the source tree to be used]:srcpath:_files -/'
89119
'-D[do a full git clone without --depth]'
90-
'-t[version of FreeBSD to upgrade the jail to]::version'
91-
'-U[specify a url to fetch the sources (with method git and/or svn)]::url'
120+
'-t[version of FreeBSD to upgrade the jail to]:version'
121+
'-U[specify a url to fetch the sources (with method git and/or svn)]:url'
92122
'-x[build and setup native-xtools cross compile tools in jail when building for a different TARGET ARCH than the host]'
93-
'-C[clean remaining data existing in poudriere data folder]::clean:(all cache logs packages wrkdirs)'
94-
'-p[specify which ports tree to start/stop the jail with]::tree:_poudriere_pt'
95-
'-z[specify which SET the jail to start/stop with]::set'
123+
'-C[clean remaining data existing in poudriere data folder]:clean:(all cache logs packages wrkdirs)'
124+
'-p[specify which ports tree to start/stop the jail with]:tree:_poudriere_pt'
125+
'-z[specify which SET the jail to start/stop with]:set'
96126
)
97127

98128
_logclean=(
99129
'(-N)-a[remove all logfiles matching the filter]'
100130
'(-a)-N[how many logfiles to keep matching the filter per jail/tree/set combination]:count:'
101131
'-B[build name glob to match on]:glob:'
102-
'-j[which jail to use for log directories]::name:_poudriere_jail'
103-
'-p[specify which ports tree to use for log directories]::tree:_poudriere_pt'
132+
'-j[which jail to use for log directories]:name:_poudriere_jail'
133+
'-p[specify which ports tree to use for log directories]:tree:_poudriere_pt'
104134
'-n[do not actually remove anything, just show what would be removed]'
105135
'-v[be verbose; show more information]'
106136
'-y[assume yes when deleting and do not prompt for confirmation]'
107-
'-z[specify which SET to match for logs]::'
137+
'-z[specify which SET to match for logs]:'
108138
)
109139

110140
_options=(
111-
'-a[indicates the TARGET_ARCH if no jail is specified]::arch:(amd64 i386)'
141+
'-a[indicates the TARGET_ARCH if no jail is specified]:arch:(amd64 i386)'
112142
"(-C)-c[use 'make config' target]::"
113143
"(-c)-C[use 'make config-conditional' target]::"
114-
'-f[give the list of ports to set options]:name of file:_files'
115-
'-j[run on the given jail]::name:_poudriere_jail'
144+
'(*)-f[give the list of ports to set options]:name of file:_files'
145+
'-j[run on the given jail]:name:_poudriere_jail'
116146
'-n[do not configure/show/remove options of dependencies]::'
117-
'-p[specify on which ports tree the configuration will be done]::tree:_poudriere_pt'
147+
'-p[specify on which ports tree the configuration will be done]:tree:_poudriere_pt'
118148
'(-r)-s[show options instead of configuring them]::'
119149
'(-s)-r[show port options instead of configuring them]::'
120-
'-z[Specify which SET to use]::'
150+
'-z[Specify which SET to use]:'
151+
'(-f)*:cat/port:_poudriere_direct_port'
121152
)
122153

123154
_pkgclean=(
124155
'(-a -f)-A[remove all packages]'
125156
'(-A -f)-a[keep all known ports]'
126157
'(-A -a)-f[get the list of ports to keep from a file]:name of file:_files'
127-
'-j[which jail to use for packages]::jail name:_poudriere_jail'
128-
'-J[run n jobs in parallel]::'
158+
'-j[which jail to use for packages]:jail name:_poudriere_jail'
159+
'-J[run n jobs in parallel]:'
129160
'-n[do not actually remove anything, just show what would be removed]::'
130161
'-N[do not build the package repository when clean completed]'
131-
'-p[which ports tree to use for packages]::tree:_poudriere_pt'
162+
'-p[which ports tree to use for packages]:tree:_poudriere_pt'
132163
'-R[clean RESTRICTED packages after building]'
133164
'-v[be verbose; show more information. Use twice to enable debug output]'
134165
'-y[assume yes when deleting and do not confirm]::'
135-
'-z[specify which SET to use for packages]::'
166+
'-z[specify which SET to use for packages]:'
136167
)
137168

138169
_ports=(
139170
'(-d -u -l)-c[create a ports tree]'
140171
'(-c -u -l)-d[delete a ports tree]'
141172
'(-c -d -u)-l[lists all available ports trees]'
142173
'(-c -d -l)-u[update a ports tree]'
143-
'-U[url where to fetch the ports tree from]::'
144-
'-B[which branch to use for the svn or git methods]::'
174+
'-U[url where to fetch the ports tree from]:'
175+
'-B[which branch to use for the svn or git methods]:'
145176
'-F[When used with -c, only create the needed filesystems (for ZFS) and directories, but do not populate them.]'
146-
'-M[the path to the source of a ports tree]::path:_files -/'
147-
'-f[the name of the filesystem to create for the ports tree]::fs:_files -/'
177+
'-M[the path to the source of a ports tree]:path:_files -/'
178+
'-f[the name of the filesystem to create for the ports tree]:fs:_files -/'
148179
'-k[when used with -d, only unregister the ports tree without removing the files]'
149-
'-m[when used with -c, specify the method used to create the ports tree]::method:((git null portsnap svn svn+http svn+https svn+file svn+ssh))'
180+
'-m[when used with -c, specify the method used to create the ports tree]:method:((git null portsnap svn svn+http svn+https svn+file svn+ssh))'
150181
'-n[when used with -l, only print the name of the ports tree]'
151-
'-p[specifies the name of the ports tree to work on]::tree:_poudriere_pt'
182+
'-p[specifies the name of the ports tree to work on]:tree:_poudriere_pt'
152183
'-q[when used with -l, remove the header in the list view]'
153184
'-v[show more verbose output]'
154185
)
@@ -160,29 +191,31 @@ _status=(
160191
'-B[what buildname to use]:buildname'
161192
'-c[compact output]'
162193
'-H[do not print headers and separate fields by a single tab instead of arbitrary white space]'
163-
'-j[run on the given jail]::name:_poudriere_jail'
164-
'-p[specify on which ports tree to match for the build]::tree:_poudriere_pt'
194+
'-j[run on the given jail]:name:_poudriere_jail'
195+
'-p[specify on which ports tree to match for the build]:tree:_poudriere_pt'
165196
'-l[show logs instead of URL]'
166197
'-r[show results]'
167-
'-z[specify which SET to match for the build]::'
198+
'-z[specify which SET to match for the build]:'
168199
)
169200

170201
_testport=(
171-
'-j[run inside the given jail]::name:_poudriere_jail'
172-
'-B[What buildname to use]::'
202+
'-j[run inside the given jail]:name:_poudriere_jail'
203+
'(*)-o[Specify an origin in the portstree]:origin:_poudriere_direct_port'
204+
'-B[What buildname to use]:'
173205
'-c[run make config for the given port]::'
174206
'-i[interactive mode]'
175207
'-I[advanced interactive mode]'
176-
'-J[Run n jobs in parallel for dependencies, and optionally run a different number of jobs in parallel while preparing the build]::'
208+
'-J[Run n jobs in parallel for dependencies, and optionally run a different number of jobs in parallel while preparing the build]:'
177209
"-k[don't consider failures as fatal; find all failures]"
178210
'-n[show what will be done, but do not build any packages]'
179211
'-N[do not build package repository when build of dependencies completed]'
180-
'-p[specifies which ports tree to use]::tree:_poudriere_pt'
181-
'-P[use custom prefix]'
182212
"-S[don't recursively rebuild packages affected by other packages requiring incremental rebuild]"
213+
'-p[specifies which ports tree to use]:tree:_poudriere_pt'
214+
'-P[use custom prefix]:'
183215
'-v[be verbose; show more information]'
184216
'-w[save WRKDIR on failed builds]'
185-
'-z[specify which SET to use]::'
217+
'-z[specify which SET to use]:'
218+
'(-o *)*:cat/port:_poudriere_direct_port'
186219
)
187220

188221
_poudriere () {

0 commit comments

Comments
 (0)