_dnf5
21420 bytes
1#compdef dnf5
2# based on dnf-5.2.6.2
3
4# utility functions
5
6_dnf5_helper() {
7 _call_program specs $service "${(q-)@}" "${(q-)PREFIX}\*" \
8 -qC --assumeno --nogpgcheck 2>/dev/null </dev/null
9}
10
11_dnf5_repositories() {
12 # required option: -T (all|disabled|enabled)
13 local selected expl
14 zparseopts -D -E - T:=selected
15 selected=$selected[2]
16 _wanted $selected-repositories expl "$selected repository" \
17 compadd "$@" - "${(@)${(f)$(_dnf5_helper repo list --$selected)}[2,-1]%% *}"
18}
19
20_dnf5_packages() {
21 # required option: -T (all|available|installed|upgradable)
22 local selected opt expl
23 zparseopts -D -E - T:=selected
24 selected=$selected[2]
25 case $selected in
26 all) opt='' ;; # option --all does not exist
27 upgradable) opt='--upgrades' ;;
28 *) opt="--$selected" ;;
29 esac
30 _wanted $selected-packages expl "$selected package" \
31 compadd "$@" - $(_dnf5_helper repoquery $opt --qf='%{name} ')
32}
33
34_dnf5_rpm_files() {
35 local expl
36 _wanted rpm-files expl 'rpm file' _files -g '(#i)*.rpm(-.)'
37}
38
39_dnf5_packages_or_rpms() {
40 if [[ "$words[CURRENT]" = (*/*|\~*) ]]; then # if looks like a path name
41 _dnf5_rpm_files
42 else
43 _dnf5_packages "$@"
44 fi
45}
46
47_dnf5_groups() {
48 # optional option: -T (available|installed)
49 local update_policy selected line pat groups
50 zparseopts -D -E - T:=selected
51 selected=$selected[2]
52 if [[ -z $selected ]]; then
53 selected=all
54 opt= # option --all does not exist
55 else
56 opt=--$selected
57 fi
58 # XXX hidden groups are not included
59 for line in ${${(f)"$(_dnf5_helper group list $opt)"}[2,-1]}; do
60 line=( ${(z)line} )
61 groups+=( "$line[1]:$line[2,-2]" )
62 done
63 _describe -t $selected-groups "$selected group" groups
64}
65
66_dnf5_environments() {
67 local line envs
68 for line in ${${(f)"$(_dnf5_helper environment list)"}[2,-1]}; do
69 line=( ${(z)line} )
70 envs+=( "$line[1]:$line[2,-2]" )
71 done
72 _describe -t environments 'environment' envs
73}
74
75# completers for (several) dnf commands
76
77_dnf5-advisory () {
78 _arguments : \
79 $advisory_opts \
80 '--contains-pkgs=[only show advisories containing specified packages]: : _sequence _dnf5_packages -T installed' \
81 + '(with)' \
82 '--with-cve[show only advisories referencing CVE ticket]' \
83 '--with-bz[show only advisories referencing Bugzilla ticket]' \
84 + '(type)' \
85 '--all[show all advisories]' \
86 '--available[show advisories containing newer versions of installed packages (default)]' \
87 '--installed[show advisories containing equal and older version of installed packages]' \
88 '--updates[show advisories containing upgradable packages]' \
89 + args \
90 ':subcommand:(list info summary)' '*:advisory spec:'
91}
92
93_dnf5-group() {
94 local -a tmp
95 if (( CURRENT == 2 )); then
96 tmp=(
97 'list:list all matching groups'
98 'info:print detailed information about groups'
99 'install:install packages from specified groups'
100 'remove:remove removable packages in specified groups'
101 'upgrade:upgrade specified groups and packages in them'
102 )
103 _describe -t subcommands 'subcommand' tmp
104 else
105 case $words[2] in
106 list|info)
107 tmp=(
108 '(--installed)--available[show only available groups]'
109 '(--available)--installed[show only installed groups]'
110 '--hidden[show also hidden groups]'
111 '--contains-pkgs=[show only groups containing specified packages]: : _sequence _dnf5_packages -T all'
112 '*: : _dnf5_groups'
113 )
114 ;;
115 install)
116 tmp=( $common_opts
117 '--with-optional[include optional packages from the groups]'
118 '*: : _dnf5_groups -T available' )
119 ;|
120 upgrade)
121 tmp=( ${common_opts:#--skip-broken*}
122 '*: : _dnf5_groups -T installed' )
123 ;|
124 remove)
125 tmp=( $offline_opts
126 '*: : _dnf5_groups -T installed' )
127 ;|
128 install|remove)
129 tmp+=( '--no-packages[operate on groups only, not manipulate any packages]' )
130 ;|
131 install|upgrade)
132 tmp+=( $downgrade_opts )
133 ;;
134 esac
135 _arguments : $tmp
136 fi
137}
138
139_dnf5-history() {
140 local -a tmp
141 if (( CURRENT == 2 )); then
142 tmp=(
143 'list:list info about recorded transactions'
144 'info:print detailed about specific transactions'
145 'undo:revert all actions from the specified transaction'
146 'redo:repeat the specified transaction'
147 'rollback:undo all transactions performed after the specified transaction'
148 'store:store the transaction into a directory'
149 )
150 _describe -t subcommands 'subcommand' tmp
151 else
152 case $words[2] in
153 list|info)
154 tmp=( '--reverse[reverse the order of transactions in output]' )
155 ;;
156 undo|rollback|redo)
157 tmp=( '--skip-unavailable[allow skipping impossible actions]' )
158 ;|
159 undo|rollback)
160 tmp+=( $replay_opts )
161 ;;
162 store)
163 tmp=( {-o,--output=}'[directory for storing the transaction (default ./transaction)]: : _directories')
164 esac
165 _arguments : $tmp '2:transaction:( )'
166 fi
167}
168
169_dnf5-mark() {
170 local -a tmp
171 if (( CURRENT == 2 )); then
172 tmp=(
173 'user:mark the package as user-installed'
174 'dependency:mark the package as a dependency'
175 'weak:mark the package as a weak dependency'
176 'group:mark the package as installed by the specified group'
177 )
178 _describe -t subcommands 'subcommand' tmp
179 else
180 tmp=(
181 '--skip-unavailable[skip packages not installed on the system]'
182 '--store=[store the transaction in specified directory]: : _directories'
183 )
184 if [[ $words[2] = group ]]; then
185 tmp+=( '2:group-id: _dnf5_groups -T installed' )
186 fi
187 _arguments : $tmp '*: : _dnf5_packages -T installed'
188 fi
189}
190
191_dnf5-module() {
192 local -a tmp
193 if (( CURRENT == 2 )); then
194 tmp=(
195 'list:list module streams'
196 'info:print details about module streams'
197 'enable:enable module streams'
198 'disable:disable modules including all their streams'
199 "reset:reset module state so it's no longer enabled or disabled"
200 )
201 _describe -t subcommands 'subcommand' tmp
202 elif (( CURRENT == 3 )) && [[ $cur = -* ]]; then
203 case $words[2] in
204 list|info) tmp=( --enabled --disabled ) ;;
205 enable) tmp=( --skip-broken --skip-unavailable ) ;;
206 *) tmp=( --skip-unavailable ) ;;
207 esac
208 _wanted options expl 'option' compadd -a tmp
209 else
210 _message 'module spec'
211 fi
212}
213
214_dnf5-offline() { # also used by the 'system-upgrade' command
215 local -a tmp
216 if (( CURRENT == 2 )); then
217 tmp=(
218 'clean:remove any stored offline transactions and cached packages'
219 'log:list boots during which offline transaction was attempted'
220 'reboot:prepare the system for offline transaction and reboot'
221 )
222 if [[ $cmd = offline ]]; then
223 tmp+=( 'status:show status of the current offline transaction' )
224 else
225 tmp+=( 'download:download all packages needed for upgrade' )
226 fi
227 _describe -t subcommands 'subcommand' tmp && ret=0
228 else
229 case $words[2] in
230 download)
231 _arguments : \
232 '--releasever=[the version to upgrade to]:version number:' \
233 '--no-downgrade:do not install packages older than currently installed' '*: :' && ret=0
234 ;;
235 log)
236 _arguments : \
237 '--number=[show log of transaction specified by number]:transaction number:' '*: :' && ret=0
238 ;;
239 reboot)
240 _wanted options expl 'option' compadd -- --poweroff && ret=0
241 ;;
242 esac
243 fi
244}
245
246_dnf5-repoquery() {
247 local v
248 local -a opts=(
249 $advisory_opts
250 '--arch=[limit results to specified architectures]:list of archs: '
251 '--available[limit results to available packages]'
252 '--disable-modular-filtering[include packages of inactive module streams]'
253 '--duplicates[limit to installed duplicate packages]'
254 '--exactdeps[limit to packages that require capability specified by ==what{requires,depends}]'
255 '--extras[limit to installed packages that are not present in any available repository]'
256 '--file=[limit results to packages which own specified file]:list of files: _sequence _files'
257 '--installed[query installed packages]'
258 '--installonly[limit to installed installonly packages]'
259 '--latest-limit=[limit to latest packages of specified number]:number:'
260 '--leaves[limit to groups of installed packages not required by other installed packages]'
261 '--providers-of=[select packages that provide specified attribute]:attribute:(conflicts depends enhances obsoletes provides recommends requires requires_pre suggests supplement)'
262 '--recent[limit to only recently changed packages]'
263 '--recursive[make --whatrequires/--providers-of work recursively]'
264 '--security[limit to packages in security advisories]'
265 '--srpm[use the corresponding source RPM]'
266 '--unneeded[limit to unneeded installed packages]'
267 '--upgrades[limit to available packages that provide upgrade for installed packages]'
268 '--userinstalled[limit to packages that are not installed as dependencies]'
269 '--whatdepends=[limit to packages that require, enhance, recommend, suggest of supplement specified capability]:list of capability:'
270 '--whatconflicts=[limit to packages that conflicts with specified capabilities]:list of capability: '
271 )
272 for v in enhance obsolete provide recommend require suggest supplement; do
273 opts+=( "--what${v}s=[limit to packages that $v specified capabilities]:list of capability: ")
274 done
275 # mutually exclusive formatting options
276 opts+=(
277 + '(format)'
278 '--conflicts[display capabilities that the package conflicts with]'
279 '--depends[display capabilities that the package depends on, enables, recommends, suggests or supplements]'
280 '--files[show files in the package]'
281 '--requires-pre[display capabilities required to run pre/post scripts of the package]'
282 '--sourcerpm[display source RPM of the package]'
283 '--location[display location of the package]'
284 '--info[show detailed information about the package]'
285 '--changelogs[print the package changelogs]'
286 '(- *)--querytags[list tags recognized by --queryformat]'
287 '--queryformat=[specify output format]:format:'
288 )
289 for v in enhance obsolete provide recommend require suggest supplement; do
290 opts+=( "--${v}s[display capabilities ${v}ed by the package]" )
291 done
292
293 _arguments : '*: : _dnf5_packages -T all' $opts
294}
295
296# dnf commands
297
298_dnf5_commands() {
299 local -a dnf_cmds=(
300 'advisory:manage advisories'
301 'autoremove:remove unneeded packages'
302 'check:check for problems in package database'
303 'check-upgrade:check for available package upgrades'
304 'clean:remove or invalidate cached data'
305 'distro-sync:up/downgrade installed packages to the latest available'
306 'downgrade:downgrade packages'
307 'download:download packages'
308 'environment:manage comps environments'
309 'group:manage comps groups'
310 'history:manage transaction history'
311 'info:provide detailed information about packages'
312 'install:install packages'
313 'leaves:list groups of leaf packages'
314 'list:list installed or available packages'
315 'makecache:generate the metadata cache'
316 'mark:change the reason of an installed package'
317 'module:manage modules'
318 'offline:manage offline transactions'
319 'provides:find what package provides the given value'
320 'reinstall:reinstall packages'
321 'remove:remove packages'
322 'replay:replay stored transactions'
323 'repo:manage repositories'
324 'repoquery:search for packages in repositories'
325 'search:search for packages using keywords'
326 'swap:remove software and install another in the single transaction'
327 'system-upgrade:upgrade the system to a new major release'
328 'upgrade:upgrade packages'
329 'versionlock:protect packages from updates to newer versions'
330 )
331 _describe -t dnf-commands 'dnf command' dnf_cmds
332}
333
334# subcommands and options
335
336_dnf5_subcmds_opts() {
337 local cur=$words[CURRENT] cmd=$words[1] expl ret=1
338 local -a tmp
339 # common options
340 local -a offline_opts=(
341 '(--store)--offline[store the transaction to be performed offline]'
342 '(--offline)--store=[store the transaction in specified directory]: : _directories'
343 )
344 local -a common_opts=(
345 $offline_opts
346 '--allowerasing[allow erasing of installed packages]'
347 '--skip-broken[resolve dependency problems by skipping problematic packages]'
348 "--skip-unavailable[skip packages that can't be synchronized]"
349 '--downloadonly[download packages without executing transaction]'
350 )
351 local -a advisory_opts=(
352 '--advisories=[consider only specified advisories]:list of advisories:'
353 '--advisory-severities=[limit to advisories with specified severity]:severity:_sequence compadd - critical important moderate low none'
354 '--bzs=[limit to advisories that fix specified Bugzilla ID]:list of Bugzilla ID:'
355 '--cves=[limit to advisories that fix specified CVE ID]:list of CVD ID]:'
356 '--security[limit to security advisories]'
357 '--bugfix[limit to bugfix advisories]'
358 '--enhancement[limit to enhancement advisories]'
359 '--newpackage[limit to newpackage advisories]'
360 )
361 local -a downgrade_opts=(
362 '(--no-allow-downgrade)--allow-downgrade[enable downgrade of dependencies]'
363 '(--allow-downgrade)--no-allow-downgrade[disable downgrade of dependencies]'
364 )
365 local -a replay_opts=(
366 '--ignore-extras[not consider extra packages]'
367 '--ignore-installed[mismatches between installed and stored transaction are not errors]'
368 )
369 # Deal with some aliases (not comprehensive)
370 case $cmd in
371 check-updgrade) cmd=check-update;;
372 dg) cmd=downgrade;;
373 dsync) cmd=distro-sync;;
374 grp) cmd=group;;
375 if) cmd=info;;
376 in) cmd=install;;
377 ls) cmd=list;;
378 mc) cmd=makecache;;
379 rei) cmd=reinstall;;
380 rm) cmd=remove ;;
381 rq) cmd=repoquery;;
382 se) cmd=search;;
383 update|up) cmd=upgrade;;
384 esac
385 local curcontext="${curcontext%:*:*}:dnf-${cmd}:"
386
387 case $cmd in
388 advisory|group|history|mark|module|offline|repoquery)
389 _dnf5-$cmd && ret=0
390 ;;
391 system-upgrade)
392 _dnf5-offline && ret=0
393 ;;
394 autoremove)
395 _arguments : $offline_opts && ret=0
396 ;;
397 check)
398 _arguments : \
399 '--dependencies[show missing dependencies and conflicts]' \
400 '--duplicates[show duplicated packages]' \
401 '--obsoleted[show obsoleted packages]' && ret=0
402 ;;
403 check-upgrade)
404 _arguments : \
405 $advisory_opts \
406 '--changelogs[print package changelogs]' \
407 '--minimal[reports the lowest versions of packages that fix advisories]' \
408 '*: : _dnf5_packages -T installed' && ret=0
409 ;;
410 clean)
411 tmp=(
412 'dbcache:remove cache files generated from the repository metadata'
413 'expire-cache:mark the repository metadata expired'
414 'metadata:remove the repository metadata'
415 'packages:remove any cached packages'
416 'all:clean all'
417 )
418 _describe -t cache-types 'cache type' tmp && ret=0
419 ;;
420 distro-sync)
421 _arguments : $common_opts '*: : _dnf5_packages -T installed' && ret=0
422 ;;
423 downgrade)
424 _arguments : \
425 $common_opts $downgrade_opts \
426 '*: : _dnf5_packages -T installed' && ret=0
427 ;;
428 download)
429 _arguments : \
430 '--arch=[limit to packages of specified architecture]:list of architectures:' \
431 '--resolve[resolve and download needed dependencies]' \
432 '--alldeps[with --resolve, also download already installed dependencies]' \
433 '--destdir=[download to the specified directory]: : _directories' \
434 '--srpm[download the source rpm]' \
435 '--url[print the list of URLs where the rpms can be downloaded]' \
436 '*--urlprotocol=[with --url, limit to specified protocols]:protocol:_sequence compadd - http https ftp file' \
437 '*: : _dnf5_packages -T all' && ret=0
438 ;;
439 environment)
440 _arguments : \
441 '--available[show only available environments]' \
442 '--installed[show only installed environments]' \
443 ':subcommand:(list info)' \
444 '*: : _dnf5_environments' && ret=0
445 ;;
446 info|list)
447 _arguments : \
448 '--showduplicates[show all versions of the packages]' \
449 '*: : _dnf5_packages -T all' \
450 + '(type)' \
451 '--installed[list only installed packages]:*: : _dnf5_packages -T installed' \
452 '--available[list only available packages]:*: : _dnf5_packages -T available' \
453 '--extras[list only extras]' \
454 '--obsoletes[list only installed but obsoleted packages]:*: : _dnf5_packages -T installed' \
455 '--recent[list only recently added packages]' \
456 '--upgrades[list only available upgrades of installed packages]:*: : _dnf5_packages -T upgradable' \
457 '--autoremove[list only packages that will be autoremoved]:*: : _dnf5_packages -T installed' &&ret=0
458 ;;
459 install)
460 _arguments : \
461 $common_opts $downgrade_opts $advisory_opts \
462 '*: : _dnf5_packages_or_rpms -T available' && ret=0
463 ;;
464 leaves|makecache)
465 # nothing to complete
466 ;;
467 provides)
468 _files && ret=0
469 ;;
470 reinstall)
471 _arguments : \
472 $common_opts $downgrade_opts \
473 '*: : _dnf5_packages_or_rpms -T installed' && ret=0
474 ;;
475 remove)
476 _arguments : \
477 $offline_opts \
478 '--no-autoremove[not remove dependencies that are no longer used]' \
479 '*: : _dnf5_packages -T installed' && ret=0
480 ;;
481 replay)
482 _arguments : \
483 $replay_opts \
484 ':transaction path:_directories' && ret=0
485 ;;
486 repo)
487 _arguments : \
488 '--all[show info about all repositories]' \
489 '--enabled[show info only about enabled repositories]' \
490 '--disabled[show info only about disabled repositories]' \
491 ':subcommand:(list info)' && ret=0
492 ;;
493 search)
494 _arguments : \
495 '--all[search patterns also inside description and URL fields]' \
496 '--showduplicates[show all versions of packages, not only the latest ones]' \
497 '*:search pattern:' && ret=0
498 ;;
499 swap)
500 _arguments : \
501 $offline_opts \
502 '--allowerasing[allow erasing of installed packages]' \
503 ': : _dnf5_packages -T installed' \
504 ': : _dnf5_packages -T available' && ret=0
505 ;;
506 upgrade)
507 _arguments : \
508 ${common_opts:#--skip-broken*} $downgrade_opts $advisory_opts \
509 '--minimal[upgrade only to the lowest available versions that fix advisories]' \
510 '--destdir=[specify directory into which downloading packages]: : _directories' \
511 '*: : _dnf5_packages_or_rpms -T upgradable' && ret=0
512 ;;
513 versionlock)
514 _arguments : \
515 ':subcommand:(add exclude clear delete list)' \
516 '*: : _dnf5_packages -T all' && ret=0
517 ;;
518 esac
519 return ret
520}
521
522# main completer
523
524_dnf5() {
525 local curcontext="$curcontext" state state_descr line ret=1
526 typeset -A opt_args
527 local -a opts=(
528 '(-y --assumeyes)--assumeno[answer no for all questions]'
529 '--best[try the best available package version]'
530 '(-C --cacheonly)'{-C,--cacheonly}"[run entirely from system cache, don't update cache]"
531 '--comment=[add comment to transaction history]:comment:'
532 '(-c --config)'{-c+,--config=}'[specify configuration file]:config file:_files'
533 '--debugsolver[dump detailed solving results in file ./debugdata]'
534 '*--disable-plugin=[disable specified plugins]:list of plugin names:'
535 '(--repo)*--disable-repo=[disable specified repos]: : _sequence _dnf5_repositories -T enabled'
536 '--dump-main-config[print main configuration values to stdout]'
537 '*--dump-repo-config=[print repository configuration values to stdout]:repi id'
538 '--dump-variables[print variable values to stdout]'
539 '*--enable-plugin=[enable specified plugins]:list of plugin names:'
540 '*--enable-repo=[enable additional repos]: : _sequence _dnf5_repositories -T disabled'
541 '--forcearch=[force the use of the specified arch]:arch:'
542 '(-)'{-h,--help}'[show the help message]'
543 '--installroot=[set install root]: : _directories'
544 '--no-best[do not limit transactions to best candidates]'
545 '--no-docs[do not install documentation]'
546 '--no-gpgcheck[skip checking GPG signatures on packages]'
547 '--no-plugins[disable all plugins]'
548 '(-q --quiet)'{-q,--quiet}'[show just the relevant content]'
549 '--refresh[force refreshing metadata before running the command]'
550 '--releasever=[override distribution release in config files]:release ver:'
551 '(--disablerepo)*--repo=[enable just the specified repo]: : _sequence _dnf5_repositories -T all'
552 '*--repofrompath=[specify additional repos]:repository_label,path_or_url: '
553 '*--setopt=[override option in config file]:repoid.option=value:'
554 '*--setvar=[override DNF5 variable value]'
555 '--show-new-leaves[show newly installed leaf packages]'
556 '--use-host-config[use config files and variables from host system]'
557 '(- *)--version[show dnf version]'
558 '(-y --assumeyes --assumeno)'{-y,--assumeyes}'[answer yes for all questions]'
559 '*'{-x+,--exclude=}'[exclude specified packages from transaction]: : _sequence _dnf5_packages -T all'
560 )
561 _arguments -C -s : $opts ': :->command' '*:: :->cmd_args' && ret=0
562
563 case $state in
564 command) _dnf5_commands && ret=0 ;;
565 cmd_args) _dnf5_subcmds_opts && ret=0 ;;
566 esac
567 return ret
568}
569
570_dnf5 "$@"