def _subcommand_arguments(args):
skip_site = False<EOL>for i, a in enumerate(args):<EOL><INDENT>if skip_site:<EOL><INDENT>skip_site = False<EOL>continue<EOL><DEDENT>if a.startswith('<STR_LIT:->'):<EOL><INDENT>if a == '<STR_LIT>' or a == '<STR_LIT>':<EOL><INDENT>skip_site = True<EOL><DEDENT>continue<EOL><DEDENT>if a == '<STR_LIT>':<EOL><INDENT>return _subcommand_arguments(args[:i] + ['<STR_LIT>'] + args[i + <NUM_LIT:1>:])<EOL><DEDENT>if a not in COMMANDS:<EOL><INDENT>raise DatacatsError("<STR_LIT>"<EOL>"<STR_LIT>".format(a))<EOL><DEDENT>command = a<EOL>break<EOL><DEDENT>else:<EOL><INDENT>return None, args<EOL><DEDENT>if command != '<STR_LIT>' and command != '<STR_LIT>':<EOL><INDENT>return command, args<EOL><DEDENT>remaining_positional = <NUM_LIT:2> if command == '<STR_LIT>' else <NUM_LIT:1><EOL>while i < len(args):<EOL><INDENT>a = args[i]<EOL>if a.startswith('<STR_LIT:->'):<EOL><INDENT>if a == '<STR_LIT>' or a == '<STR_LIT>':<EOL><INDENT>i += <NUM_LIT:2><EOL>continue<EOL><DEDENT>i += <NUM_LIT:1><EOL>continue<EOL><DEDENT>if remaining_positional:<EOL><INDENT>remaining_positional -= <NUM_LIT:1><EOL>i += <NUM_LIT:1><EOL>continue<EOL><DEDENT>return command, args[:i] + ['<STR_LIT>'] + args[i:]<EOL><DEDENT>return command, args<EOL>
Return (subcommand, (possibly adjusted) arguments for that subcommand)

Returns (None, args) when no subcommand is found

Parsing our arguments is hard. Each subcommand has its own docopt
validation, and some subcommands (paster and shell) have positional
options (some options passed to datacats and others passed to
commands run inside the container)