#!/usr/bin/python
# PYTHON_ARGCOMPLETE_OK
import argparse
import argcomplete
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='command')
parser1 = subparsers.add_parser('local')
parser1.add_argument('name', choices=['zzz', 'aaa'])
parser2 = subparsers.add_parser('lookup')
parser2.add_argument('dest', choices=['a', 'b', 'c'])
sub2 = parser2.add_subparsers(dest='type')
parser3 = sub2.add_parser('env')
parser3.add_argument('name', choices=['zzz', 'aaa'])
parser4 = sub2.add_parser('etc')
parser4.add_argument('file', choices=['my.cnf', 'apache.conf'])
argcomplete.autocomplete(parser)
data = parser.parse_args()
If you go one subparser deep, into the local branch, this works as expected. Once you fill out zzz or aaa, you're no longer offered autocomplete choices.
$ ./testcase.py local zzz [tab][tab]
$
If you go into the lookup branch and hit the second subparser, the subparser choice is presented to you as many variables deep as you care to go.
e.g.
$ ./testcase.py lookup env env env [tab][tab]
env etc -h --help
$
Interestingly, if a non subparser argument is added before the inital one, you get offered the correct choices mostly (when you hit a,b,c you get env and etc in the options as well, if you pick a, b, or c completion works properly from then on, but if you choose etc or env, it goes back into looping forever).