def main_switch(commands): return fun( '_stg', 'local i', 'local c=1', 'local command', '', 'while test $c -lt $COMP_CWORD; do', [ 'if test $c == 1; then', [ 'command="${COMP_WORDS[c]}"'], 'fi', 'c=$((++c))'], 'done', '', ('# Complete name of subcommand if the user has not finished' ' typing it yet.'), 'if test $c -eq $COMP_CWORD -a -z "$command"; then', [ ('COMPREPLY=($(compgen -W "help version copyright $_stg_commands" --' ' "${COMP_WORDS[COMP_CWORD]}"))'), 'return'], 'fi', '', '# Complete arguments to subcommands.', 'case "$command" in', [ 'help) ', [ ('COMPREPLY=($(compgen -W "$_stg_commands" --' ' "${COMP_WORDS[COMP_CWORD]}"))'), 'return ;;'], 'version) return ;;', 'copyright) return ;;'], [ '%s) _stg_%s ;;' % (cmd, cmd) for cmd in sorted(commands.iterkeys())], 'esac')
def command_list(commands): return ['_stg_commands="%s"\n' % ' '.join(sorted(commands.iterkeys()))]