generate bash completion scripts from XML doc files

This generates the scripts that lets bash do completion per specific tool.
It gets the options from the documentation XML files that are also the
source for the man pages and HTML.
This commit is contained in:
Hans-Christoph Steiner 2014-10-01 20:53:30 -04:00
parent 34587eac9c
commit d72324ddf5
3 changed files with 81 additions and 1 deletions

16
.gitignore vendored
View File

@ -55,6 +55,22 @@ stamp-h*
*.tmp
ChangeLog
doc/tools/cardos-tool
doc/tools/cryptoflex-tool
doc/tools/eidenv
doc/tools/iasecc-tool
doc/tools/netkey-tool
doc/tools/openpgp-tool
doc/tools/opensc-explorer
doc/tools/opensc-tool
doc/tools/piv-tool
doc/tools/pkcs11-tool
doc/tools/pkcs15-crypt
doc/tools/pkcs15-init
doc/tools/pkcs15-tool
doc/tools/sc-hsm-tool
doc/tools/westcos-tool
etc/opensc.conf.win
etc/opensc.conf
src/common/compat_getopt_main

View File

@ -10,6 +10,9 @@ man1_MANS = $(patsubst $(srcdir)/%.xml, %, $(wildcard $(srcdir)/*.1.xml))
man5_MANS = $(patsubst $(srcdir)/%.xml, %, $(wildcard $(srcdir)/*.5.xml))
endif
completion_DATA = $(patsubst $(srcdir)/%.1.xml, %, $(wildcard $(srcdir)/*.1.xml))
completiondir = $(sysconfdir)/bash_completion.d
tools.html: $(srcdir)/tools.xml $(wildcard $(srcdir)/*.1.xml) $(wildcard $(srcdir)/*.5.xml)
$(XSLTPROC) --nonet --path "$(srcdir)/..:$(xslstylesheetsdir)/html" --xinclude -o $@ html.xsl $<
@ -21,5 +24,21 @@ tools.html: $(srcdir)/tools.xml $(wildcard $(srcdir)/*.1.xml) $(wildcard $(srcdi
sed -e 's|@pkgdatadir[@]|$(pkgdatadir)|g' < $< \
| $(XSLTPROC) --nonet --path "$(srcdir)/..:$(xslstylesheetsdir)/manpages" --xinclude -o $@ man.xsl $<
%: $(srcdir)/%.1.xml
echo $< $@
cat completion-template \
| sed "s,ALLOPTS,\
$(shell sed -n 's,\s\s\s*<option>\([^<]*\)</option>.*,\1,pg' $< \
| sort -u | grep -- '^\-' | tr '\n' ' ')," \
| sed "s,OPTSWITHARGS,\
$(shell sed -n 's,\s\s\s*<option>\([^<]*\)</option>.*<replaceable>.*,\1,pg' $< \
| sort -u | grep -- '^\-' | tr '\n' '|' | sed 's,|$$,,')," \
| sed "s,FILEOPTS,\
$(shell sed -n 's,\s\s\s*<option>\([^<]*\)</option>.*<replaceable>.*filename.*,\1,pg' $< \
| sort -u | grep -- '^\-' | tr '\n' '|')," \
| sed "s,FUNCTION_NAME,$(shell echo $@ | sed s,-,_,g)," \
| sed "s,PROGRAM_NAME,$@," \
> $@
clean-local:
-rm -rf $(html_DATA) $(man1_MANS) $(man5_MANS)
-rm -rf $(html_DATA) $(man1_MANS) $(man5_MANS) $(completion_DATA)

View File

@ -0,0 +1,45 @@
# this was auto-generated by OpenSC/doc/tools/Makefile.am
_FUNCTION_NAME()
{
COMPREPLY=()
local cur prev split=false
_get_comp_words_by_ref cur prev
_split_longopt && split=true
opts="ALLOPTS"
if [ ${COMP_CWORD} -eq 1 ]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
case "${prev}" in
OPTSWITHARGS)
return 0
;;
*)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
_longopt $1
return
fi
_filedir
}
complete -F _FUNCTION_NAME PROGRAM_NAME
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh