data/razor.sh
author J. Ali Harlow <ali@juiblex.co.uk>
Sat Oct 04 18:12:58 2014 +0100 (2014-10-04)
changeset 454 56ff755c268c
parent 290 f2461ae87dde
permissions -rw-r--r--
Only export symbols starting with razor_ in dynamic library.

Apart from being good practice to avoid clashes with higher-level
libraries and the application, this also fixes an obscure bug: The
gnulib library is used both by librazor (the dynamic library) and
by razor (the executable). In doing so, we want to have two separate
copies of the library despite the code duplication this involves.
Without the explicit limit to export only razor_ symbols, the razor
executable under mingw64 was picking up the getopt_long function
from librazor and the optind variable from libgnu which meant that
it did not see optind changing. Hiding librazor's copy of getopt
causes the linker to find libgnu's copy and everything works.

Note that under mingw librazor-#.dll still contains undocumented
(private) razor_ symbols but these will do no harm as long as nobody
tries to use them.
richard@261
     1
__razor_commands () {
richard@261
     2
    local IFS=$'\n'
jbowes@290
     3
    COMPREPLY=($(IFS=: compgen -S' ' -W "info:list-requires:list-provides:list-files:list-file-packages:list-package-files:what-requires:what-provides:import-yum:import-rpmdb:import-rpms:validate:update:diff:install:init:download" -- $1))
richard@261
     4
}
richard@261
     5
richard@261
     6
__razor_packages () {
richard@261
     7
    local IFS=$'\n'
richard@261
     8
richard@261
     9
    COMPREPLY=($(razor list --only-names "$1*" | while read p; do echo "$p "; done))
richard@261
    10
}
richard@261
    11
richard@261
    12
__razor_upstream_packages () {
richard@261
    13
    local IFS=$'\n'
richard@261
    14
richard@310
    15
    COMPREPLY=($(RAZOR_REPO=rawhide.rzdb razor list --only-names "$1*" | while read p; do echo "$p "; done))
richard@261
    16
}
richard@261
    17
richard@261
    18
__razor_files() {
richard@261
    19
    COMPREPLY=($(razor list-files "$1*"))
richard@261
    20
}
richard@261
    21
richard@261
    22
__razor_requires() {
richard@261
    23
    COMPREPLY=($(compgen -W "$(razor list-requires)" -- $1))
richard@261
    24
}
richard@261
    25
richard@261
    26
__razor_provides() {
richard@261
    27
    COMPREPLY=($(compgen -W "$(razor list-provides)" -- $1))
richard@261
    28
}
richard@261
    29
richard@261
    30
__razor() {
richard@261
    31
    local cur="${COMP_WORDS[COMP_CWORD]}"
richard@261
    32
richard@261
    33
    if [ $COMP_CWORD = 1 ]; then
richard@261
    34
	__razor_commands $cur
richard@261
    35
    else
richard@261
    36
	case "${COMP_WORDS[1]}" in
richard@261
    37
	    info|list-requires|list-provides|list-package-files)
richard@261
    38
		__razor_packages $cur ;;
richard@261
    39
	    list-files|list-file-packages) __razor_files $cur ;;
richard@261
    40
	    what-requires) __razor_requires $cur ;;
richard@261
    41
	    what-provides) __razor_provides $cur ;;
richard@261
    42
	    install|download) __razor_upstream_packages $cur ;;
richard@261
    43
	esac
richard@261
    44
    fi
richard@261
    45
}
richard@261
    46
richard@261
    47
complete -o nospace -F __razor razor