Merge pull request #631 from chocolate-doom/completion
Bash-Completion: First attempt at programatically creating the parame…
This commit is contained in:
commit
6ce8514c98
9 changed files with 219 additions and 59 deletions
|
|
@ -173,6 +173,7 @@ AC_DEFUN([AC_DATAROOTDIR_CHECKED])
|
|||
AC_OUTPUT([
|
||||
Makefile
|
||||
man/Makefile
|
||||
man/bash-completion/Makefile
|
||||
opl/Makefile
|
||||
opl/examples/Makefile
|
||||
pcsound/Makefile
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
SUBDIRS = bash-completion
|
||||
|
||||
MANPAGE_GEN_FILES = environ.man \
|
||||
iwad_paths.man \
|
||||
doom.template \
|
||||
|
|
|
|||
42
man/bash-completion/Makefile.am
Normal file
42
man/bash-completion/Makefile.am
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
BASH_COMPLETION_TEMPLATES = \
|
||||
doom.template \
|
||||
heretic.template \
|
||||
hexen.template \
|
||||
strife.template
|
||||
|
||||
if HAVE_PYTHON
|
||||
|
||||
BASH_COMPLETION_SCRIPTLETS = \
|
||||
@PROGRAM_PREFIX@doom \
|
||||
@PROGRAM_PREFIX@heretic \
|
||||
@PROGRAM_PREFIX@hexen \
|
||||
@PROGRAM_PREFIX@strife
|
||||
|
||||
noinst_DATA = $(BASH_COMPLETION_SCRIPTLETS)
|
||||
CLEANFILES = $(BASH_COMPLETION_SCRIPTLETS)
|
||||
|
||||
MANDIR = $(top_srcdir)/man
|
||||
DOCGEN = $(MANDIR)/docgen
|
||||
|
||||
@PROGRAM_PREFIX@doom: $(top_srcdir)/src $(DOCGEN) $(BASH_COMPLETION_TEMPLATES)
|
||||
$(DOCGEN) -g doom -b doom.template $(top_srcdir)/src $(top_srcdir)/src/doom > $@
|
||||
|
||||
@PROGRAM_PREFIX@heretic: $(top_srcdir)/src $(DOCGEN) $(BASH_COMPLETION_TEMPLATES)
|
||||
$(DOCGEN) -g heretic -b heretic.template $(top_srcdir)/src $(top_srcdir)/src/heretic > $@
|
||||
|
||||
@PROGRAM_PREFIX@hexen: $(top_srcdir)/src $(DOCGEN) $(BASH_COMPLETION_TEMPLATES)
|
||||
$(DOCGEN) -g hexen -b hexen.template $(top_srcdir)/src $(top_srcdir)/src/hexen > $@
|
||||
|
||||
@PROGRAM_PREFIX@strife: $(top_srcdir)/src $(DOCGEN) $(BASH_COMPLETION_TEMPLATES)
|
||||
$(DOCGEN) -g strife -b strife.template $(top_srcdir)/src $(top_srcdir)/src/strife > $@
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(BASH_COMPLETION_TEMPLATES) \
|
||||
$(BASH_COMPLETION_SCRIPTLETS)
|
||||
|
||||
else
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(BASH_COMPLETION_TEMPLATES)
|
||||
|
||||
endif
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
# bash completion for Chocolate Doom -*- shell-script -*-
|
||||
|
||||
_chocolate_doom()
|
||||
{
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
case $prev in
|
||||
-config|-extraconfig)
|
||||
_filedir cfg
|
||||
;;
|
||||
-episode)
|
||||
COMPREPLY=(1 2 3 4)
|
||||
;;
|
||||
-file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
|
||||
_filedir wad
|
||||
;;
|
||||
-loadgame)
|
||||
COMPREPLY=(0 1 2 3 4 5)
|
||||
;;
|
||||
-pack)
|
||||
COMPREPLY=(doom2 tnt plutonia)
|
||||
;;
|
||||
-skill)
|
||||
COMPREPLY=(1 2 3 4 5)
|
||||
;;
|
||||
-gameversion)
|
||||
COMPREPLY=(1.9 ultimate final final2 hacx chex)
|
||||
;;
|
||||
-setmen)
|
||||
COMPREPLY=(dos622 dos71 dosbox)
|
||||
;;
|
||||
-playdemo|-timedemo)
|
||||
_filedir lmp
|
||||
;;
|
||||
-deh)
|
||||
_filedir bex deh
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $cur == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '-1 -2 -3 -aa -af -altdeath -as -autojoin -avg
|
||||
-cdrom -config -connect -deathmatch -dedicated -deh -dehlump -devparm
|
||||
-donut -dumpsubstconfig -dup -episode -extraconfig -extratics -fast
|
||||
-file -fullscreen -gameversion -geometry -grabmouse -height
|
||||
-ignoreversion -iwad -left -loadgame -localsearch -longtics -maxdemo -mb
|
||||
-merge -mmap -newsync -noblit -nocheats -nodeh -nodes -nodraw
|
||||
-nograbmouse -nomonsters -nomouse -nomusic -nonovert -nosfx -nosound
|
||||
-novert -nwtmerge -pack -playdemo -port -privateserver -query -record
|
||||
-respawn -right -search -server -servername -setmem -skill -solo
|
||||
-spechit -statdump -timedemo -timer -turbo -warp -width -window
|
||||
-zonescan -zonezero ' -- "$cur" ) )
|
||||
fi
|
||||
} &&
|
||||
|
||||
complete -F _chocolate_doom chocolate-doom chocolate-heretic chocolate-hexen chocolate-strife
|
||||
|
||||
# ex: ts=4 sw=4 et filetype=sh
|
||||
39
man/bash-completion/doom.template
Normal file
39
man/bash-completion/doom.template
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# bash completion for Chocolate Doom -*- shell-script -*-
|
||||
|
||||
_chocolate_doom()
|
||||
{
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
case $prev in
|
||||
-config|-extraconfig)
|
||||
_filedir cfg
|
||||
;;
|
||||
-file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
|
||||
_filedir wad
|
||||
;;
|
||||
-pack)
|
||||
COMPREPLY=(doom2 tnt plutonia)
|
||||
;;
|
||||
-gameversion)
|
||||
COMPREPLY=(1.9 ultimate final final2 hacx chex)
|
||||
;;
|
||||
-setmen)
|
||||
COMPREPLY=(dos622 dos71 dosbox)
|
||||
;;
|
||||
-playdemo|-timedemo)
|
||||
_filedir lmp
|
||||
;;
|
||||
-deh)
|
||||
_filedir bex deh
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $cur == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '@content' -- "$cur" ) )
|
||||
fi
|
||||
} &&
|
||||
|
||||
complete -F _chocolate_doom chocolate-doom
|
||||
|
||||
# ex: ts=4 sw=4 et filetype=sh
|
||||
36
man/bash-completion/heretic.template
Normal file
36
man/bash-completion/heretic.template
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# bash completion for Chocolate Heretic -*- shell-script -*-
|
||||
|
||||
_chocolate_heretic()
|
||||
{
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
case $prev in
|
||||
-config|-extraconfig)
|
||||
_filedir cfg
|
||||
;;
|
||||
-file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
|
||||
_filedir wad
|
||||
;;
|
||||
-hhever)
|
||||
COMPREPLY=(1.0 1.2 1.3)
|
||||
;;
|
||||
-setmen)
|
||||
COMPREPLY=(dos622 dos71 dosbox)
|
||||
;;
|
||||
-playdemo|-timedemo)
|
||||
_filedir lmp
|
||||
;;
|
||||
-deh)
|
||||
_filedir hhe
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $cur == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '@content' -- "$cur" ) )
|
||||
fi
|
||||
} &&
|
||||
|
||||
complete -F _chocolate_heretic chocolate-heretic
|
||||
|
||||
# ex: ts=4 sw=4 et filetype=sh
|
||||
30
man/bash-completion/hexen.template
Normal file
30
man/bash-completion/hexen.template
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# bash completion for Chocolate Hexen -*- shell-script -*-
|
||||
|
||||
_chocolate_hexen()
|
||||
{
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
case $prev in
|
||||
-config|-extraconfig)
|
||||
_filedir cfg
|
||||
;;
|
||||
-file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
|
||||
_filedir wad
|
||||
;;
|
||||
-setmen)
|
||||
COMPREPLY=(dos622 dos71 dosbox)
|
||||
;;
|
||||
-playdemo|-timedemo)
|
||||
_filedir lmp
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $cur == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '@content' -- "$cur" ) )
|
||||
fi
|
||||
} &&
|
||||
|
||||
complete -F _chocolate_hexen chocolate-hexen
|
||||
|
||||
# ex: ts=4 sw=4 et filetype=sh
|
||||
36
man/bash-completion/strife.template
Normal file
36
man/bash-completion/strife.template
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# bash completion for Chocolate Strife -*- shell-script -*-
|
||||
|
||||
_chocolate_strife()
|
||||
{
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
case $prev in
|
||||
-config|-extraconfig)
|
||||
_filedir cfg
|
||||
;;
|
||||
-file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
|
||||
_filedir wad
|
||||
;;
|
||||
-gameversion)
|
||||
COMPREPLY=(1.2 1.31)
|
||||
;;
|
||||
-setmen)
|
||||
COMPREPLY=(dos622 dos71 dosbox)
|
||||
;;
|
||||
-playdemo|-timedemo)
|
||||
_filedir lmp
|
||||
;;
|
||||
-deh)
|
||||
_filedir seh
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $cur == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '@content' -- "$cur" ) )
|
||||
fi
|
||||
} &&
|
||||
|
||||
complete -F _chocolate_strife chocolate-strife
|
||||
|
||||
# ex: ts=4 sw=4 et filetype=sh
|
||||
34
man/docgen
34
man/docgen
|
|
@ -106,6 +106,19 @@ class Category:
|
|||
|
||||
return result
|
||||
|
||||
def completion_output(self):
|
||||
result = ""
|
||||
|
||||
self.params.sort()
|
||||
|
||||
for p in self.params:
|
||||
if p.should_show():
|
||||
result += p.completion_output(0)
|
||||
|
||||
result = result.rstrip()
|
||||
|
||||
return result
|
||||
|
||||
def manpage_output(self):
|
||||
result = ".SH " + self.description.upper() + "\n"
|
||||
|
||||
|
|
@ -278,6 +291,12 @@ class Parameter:
|
|||
|
||||
return result
|
||||
|
||||
def completion_output(self, w):
|
||||
|
||||
result = self.name + " "
|
||||
|
||||
return result
|
||||
|
||||
# Read list of wiki pages
|
||||
|
||||
def read_wikipages():
|
||||
|
|
@ -444,6 +463,15 @@ def plaintext_output(targets, template_file):
|
|||
|
||||
print_template(template_file, content)
|
||||
|
||||
def completion_output(targets, template_file):
|
||||
|
||||
content = ""
|
||||
|
||||
for t in targets:
|
||||
content += t.completion_output() + "\n"
|
||||
|
||||
print_template(template_file, content)
|
||||
|
||||
def usage():
|
||||
print("Usage: %s [-V] [-c tag] [-g game] ( -m | -w | -p ) <dir>..." \
|
||||
% sys.argv[0])
|
||||
|
|
@ -452,13 +480,14 @@ def usage():
|
|||
print(" -m : Manpage output")
|
||||
print(" -w : Wikitext output")
|
||||
print(" -p : Plaintext output")
|
||||
print(" -b : Bash-Completion output")
|
||||
print(" -V : Don't show Vanilla Doom options")
|
||||
print(" -g : Only document options for specified game.")
|
||||
sys.exit(0)
|
||||
|
||||
# Parse command line
|
||||
|
||||
opts, args = getopt.getopt(sys.argv[1:], "m:wp:c:g:V")
|
||||
opts, args = getopt.getopt(sys.argv[1:], "m:wp:b:c:g:V")
|
||||
|
||||
output_function = None
|
||||
template = None
|
||||
|
|
@ -474,6 +503,9 @@ for opt in opts:
|
|||
elif opt[0] == "-p":
|
||||
output_function = plaintext_output
|
||||
template = opt[1]
|
||||
elif opt[0] == "-b":
|
||||
output_function = completion_output
|
||||
template = opt[1]
|
||||
elif opt[0] == "-V":
|
||||
show_vanilla_options = False
|
||||
elif opt[0] == "-c":
|
||||
|
|
|
|||
Loading…
Reference in a new issue