(describe-key-briefly): Compute interactive args
[emacs.git] / lisp / pcmpl-rpm.el
blob5855a3e5d15fa1896726887d18d42a22762ecad2
1 ;;; pcmpl-rpm.el --- functions for dealing with rpm completions
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
23 ;;; Commentary:
25 ;; These functions provide completion rules for RedHat's `rpm' tool.
27 ;;; Code:
29 (provide 'pcmpl-rpm)
31 (require 'pcomplete)
33 (defgroup pcmpl-rpm nil
34 "Functions for dealing with CVS completions."
35 :group 'pcomplete)
37 ;; Functions:
39 (defsubst pcmpl-rpm-packages ()
40 (split-string (pcomplete-process-result "rpm" "-q" "-a")))
42 (defun pcmpl-rpm-all-query (flag)
43 (message "Querying all packages with `%s'..." flag)
44 (let ((pkgs (pcmpl-rpm-packages))
45 (provs (list t)))
46 (while pkgs
47 (nconc provs (split-string
48 (pcomplete-process-result
49 "rpm" "-q" (car pkgs) flag)))
50 (setq pkgs (cdr pkgs)))
51 (pcomplete-uniqify-list (cdr provs))))
53 (defsubst pcmpl-rpm-files ()
54 (pcomplete-dirs-or-entries "\\.rpm\\'"))
56 ;;;###autoload
57 (defun pcomplete/rpm ()
58 "Completion for RedHat's `rpm' command.
59 These rules were taken from the output of `rpm --help' on a RedHat 6.1
60 system. They follow my interpretation of what followed, but since I'm
61 not a major rpm user/builder, please send me any corrections you find.
62 You can use \\[eshell-report-bug] to do so."
63 (let (mode)
64 (while (<= pcomplete-index pcomplete-last)
65 (unless mode
66 (if (pcomplete-match "^--\\(.*\\)" 0)
67 (pcomplete-here*
68 '("--addsign"
69 "--checksig"
70 "--erase"
71 "--help"
72 "--initdb"
73 "--install"
74 "--pipe"
75 "--querytags"
76 "--rebuild"
77 "--rebuilddb"
78 "--recompile"
79 "--resign"
80 "--rmsource"
81 "--setperms"
82 "--setugids"
83 "--upgrade"
84 "--verify"
85 "--version"))
86 (pcomplete-opt "vqVyiUebtK")))
87 ; -b<stage> <spec>
88 ; -t<stage> <tarball> - build package, where <stage> is one of:
89 ; p - prep (unpack sources and apply patches)
90 ; l - list check (do some cursory checks on %files)
91 ; c - compile (prep and compile)
92 ; i - install (prep, compile, install)
93 ; b - binary package (prep, compile, install, package)
94 ; a - bin/src package (prep, compile, install, package)
95 (cond
96 ((or (eq mode 'query)
97 (pcomplete-match "-[^-]*q"))
98 (setq mode 'query)
99 (if (pcomplete-match "^--\\(.*\\)" 0)
100 (progn
101 (pcomplete-here*
102 '("--changelog"
103 "--dbpath"
104 "--dump"
105 "--ftpport" ;nyi for the next four
106 "--ftpproxy"
107 "--httpport"
108 "--httpproxy"
109 "--provides"
110 "--queryformat"
111 "--rcfile"
112 "--requires"
113 "--root"
114 "--scripts"
115 "--triggeredby"
116 "--whatprovides"
117 "--whatrequires"))
118 (cond
119 ((pcomplete-test "--dbpath")
120 (pcomplete-here* (pcomplete-dirs)))
121 ((pcomplete-test "--queryformat")
122 (pcomplete-here*))
123 ((pcomplete-test "--rcfile")
124 (pcomplete-here* (pcomplete-entries)))
125 ((pcomplete-test "--root")
126 (pcomplete-here* (pcomplete-dirs)))
127 ((pcomplete-test "--scripts")
128 (if (pcomplete-match "^--\\(.*\\)" 0)
129 (pcomplete-here* '("--triggers"))))
130 ((pcomplete-test "--triggeredby")
131 (pcomplete-here* (pcmpl-rpm-packages)))
132 ((pcomplete-test "--whatprovides")
133 (pcomplete-here*
134 (pcmpl-rpm-all-query "--provides")))
135 ((pcomplete-test "--whatrequires")
136 (pcomplete-here*
137 (pcmpl-rpm-all-query "--requires")))))
138 (if (pcomplete-match "^-" 0)
139 (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR")
140 (pcomplete-here (pcmpl-rpm-packages)))))
141 ((pcomplete-test "--pipe")
142 (pcomplete-here* (funcall pcomplete-command-completion-function)))
143 ((pcomplete-test "--rmsource")
144 (pcomplete-here* (pcomplete-entries))
145 (throw 'pcomplete-completions nil))
146 ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'")
147 (pcomplete-here (pcmpl-rpm-files))
148 (throw 'pcomplete-completions nil))
149 ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'")
150 (while (pcomplete-here (pcmpl-rpm-files))))
151 ((or (eq mode 'checksig)
152 (pcomplete-test "--checksig"))
153 (setq mode 'checksig)
154 (if (pcomplete-match "^--\\(.*\\)" 0)
155 (progn
156 (pcomplete-here*
157 '("--nopgp"
158 "--nogpg"
159 "--nomd5"
160 "--rcfile"))
161 (cond
162 ((pcomplete-test "--rcfile")
163 (pcomplete-here* (pcomplete-entries)))))
164 (if (pcomplete-match "^-" 0)
165 (pcomplete-opt "v")
166 (pcomplete-here (pcmpl-rpm-files)))))
167 ((or (eq mode 'rebuilddb)
168 (pcomplete-test "--rebuilddb"))
169 (setq mode 'rebuilddb)
170 (if (pcomplete-match "^--\\(.*\\)" 0)
171 (progn
172 (pcomplete-here*
173 '("--dbpath"
174 "--root"
175 "--rcfile"))
176 (cond
177 ((pcomplete-test "--dbpath")
178 (pcomplete-here* (pcomplete-dirs)))
179 ((pcomplete-test "--root")
180 (pcomplete-here* (pcomplete-dirs)))
181 ((pcomplete-test "--rcfile")
182 (pcomplete-here* (pcomplete-entries)))))
183 (if (pcomplete-match "^-" 0)
184 (pcomplete-opt "v")
185 (pcomplete-here))))
186 ((memq mode '(install upgrade))
187 (if (pcomplete-match "^--\\(.*\\)" 0)
188 (progn
189 (pcomplete-here*
190 (append
191 '("--allfiles"
192 "--badreloc"
193 "--dbpath"
194 "--excludedocs"
195 "--excludepath"
196 "--force"
197 "--hash"
198 "--ignorearch"
199 "--ignoreos"
200 "--ignoresize"
201 "--includedocs"
202 "--justdb"
203 "--nodeps"
204 "--noorder"
205 "--noscripts"
206 "--notriggers")
207 (if (eq mode 'upgrade)
208 '("--oldpackage"))
209 '("--percent"
210 "--prefix"
211 "--rcfile"
212 "--relocate"
213 "--replacefiles"
214 "--replacepkgs"
215 "--root")))
216 (cond
217 ((pcomplete-test "--dbpath")
218 (pcomplete-here* (pcomplete-dirs)))
219 ((pcomplete-test "--relocate")
220 (pcomplete-here*))
221 ((pcomplete-test "--rcfile")
222 (pcomplete-here* (pcomplete-entries)))
223 ((pcomplete-test "--excludepath")
224 (pcomplete-here* (pcomplete-entries)))
225 ((pcomplete-test "--root")
226 (pcomplete-here* (pcomplete-dirs)))
227 ((pcomplete-test "--prefix")
228 (pcomplete-here* (pcomplete-dirs)))))
229 (if (pcomplete-match "^-" 0)
230 (pcomplete-opt "vh")
231 (pcomplete-here (pcmpl-rpm-files)))))
232 ((or (pcomplete-test "--install")
233 (pcomplete-match "-[^-]*i"))
234 (setq mode 'install))
235 ((or (pcomplete-test "--upgrade")
236 (pcomplete-match "-[^-]*U"))
237 (setq mode 'upgrade))
238 ((or (eq mode 'erase)
239 (pcomplete-test "--erase")
240 (pcomplete-match "-[^-]*e"))
241 (setq mode 'erase)
242 (if (pcomplete-match "^--\\(.*\\)" 0)
243 (progn
244 (pcomplete-here*
245 '("--allmatches"
246 "--dbpath"
247 "--justdb"
248 "--nodeps"
249 "--noorder"
250 "--noscripts"
251 "--notriggers"
252 "--rcfile"
253 "--root"))
254 (cond
255 ((pcomplete-test "--dbpath")
256 (pcomplete-here* (pcomplete-dirs)))
257 ((pcomplete-test "--rcfile")
258 (pcomplete-here* (pcomplete-entries)))
259 ((pcomplete-test "--root")
260 (pcomplete-here* (pcomplete-dirs)))))
261 (if (pcomplete-match "^-" 0)
262 (pcomplete-opt "v")
263 (pcomplete-here (pcmpl-rpm-packages)))))
264 ((or (eq mode 'verify)
265 (pcomplete-test "--verify"))
266 (setq mode 'verify)
267 (if (pcomplete-match "^--\\(.*\\)" 0)
268 (progn
269 (pcomplete-here*
270 '("--dbpath"
271 "--nodeps"
272 "--nofiles"
273 "--nomd5"
274 "--rcfile"
275 "--root"
276 "--triggeredby"
277 "--whatprovides"
278 "--whatrequires"))
279 (cond
280 ((pcomplete-test "--dbpath")
281 (pcomplete-here* (pcomplete-dirs)))
282 ((pcomplete-test "--rcfile")
283 (pcomplete-here* (pcomplete-entries)))
284 ((pcomplete-test "--root")
285 (pcomplete-here* (pcomplete-dirs)))
286 ((pcomplete-test "--triggeredby")
287 (pcomplete-here* (pcmpl-rpm-packages)))
288 ((pcomplete-test "--whatprovides")
289 (pcomplete-here*
290 (pcmpl-rpm-all-query "--provides")))
291 ((pcomplete-test "--whatrequires")
292 (pcomplete-here*
293 (pcmpl-rpm-all-query "--requires")))))
294 (if (pcomplete-match "^-" 0)
295 (pcomplete-opt "af.p(pcmpl-rpm-files)v")
296 (pcomplete-here (pcmpl-rpm-packages)))))
297 ((or (memq mode '(build test))
298 (pcomplete-match "\\`-[bt]"))
299 (setq mode (if (pcomplete-match "\\`-b")
300 'build
301 'test))
302 (if (pcomplete-match "^--\\(.*\\)" 0)
303 (progn
304 (pcomplete-here*
305 '("--buildroot"
306 "--clean"
307 "--nobuild"
308 "--rcfile"
309 "--rmsource"
310 "--short-circuit"
311 "--sign"
312 "--target"
313 "--timecheck"))
314 (cond
315 ((pcomplete-test "--buildroot")
316 (pcomplete-here* (pcomplete-dirs)))
317 ((pcomplete-test "--rcfile")
318 (pcomplete-here* (pcomplete-entries)))
319 ((pcomplete-test "--timecheck")
320 (pcomplete-here*))))
321 (if (pcomplete-match "^-" 0)
322 (pcomplete-opt "v")
323 (pcomplete-here
324 (if (eq mode 'test)
325 (pcomplete-dirs-or-entries "\\.tar\\'")
326 (pcomplete-dirs-or-entries "\\.spec\\'"))))))
328 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
330 ;;; arch-tag: 4e64b490-fecf-430e-b2b9-70a8ad64b8c1
331 ;;; pcmpl-rpm.el ends here