completion scripts are very very useful, but writing them is a disorganized mess.
It would almost be easier to modify the bash source itself to read and use a regular grammar, say:
foo [-p <pid>] [-f <configfile>]
<pid>: {ps -eo pid}
<configfile>: {ls -1 *.cfg}
or maybe something even nicer with help text