## Run the subcommand try: subcommand = args.pop(0) except IndexError: # No subcommand given print "Type 'bbgun help' for usage." sys.exit(0) if subcommand in subcommands: if subcommand in help_cmds: try: command = args.pop(0) if command in move_cmds: command = 'move' elif command in help_cmds: command = 'help' else: command = 'bbgun' except IndexError: # No subcommand help requested command = 'bbgun' printHelp(command) sys.exit(0) elif subcommand in move_cmds: # A list to hold all of the move statments statements = [] if not args: # No statements given for move, so print help printHelp('move') sys.exit(0) while args: arg = args[0] if arg in move_lexicon: print "Found kw '%s'" % arg # Build a new statement when given a new target if arg == 'all': if hasattr(locals, 'statement'): statements.append(statement) statement = {} statement['target_ids'] = ['all'] args.remove(arg) print "Got 'all'" # All of what type of target? target_type = args[0] if target_type in move_targets: statement['target_type'] = target_type print "Got '%s' type" % target_type args.remove(target_type) else: print "DEBUG: bad target: %s" % target_type elif arg in move_targets: if hasattr(locals, 'statement'): statements.append(statement) statement = {} statement['target_type'] = arg args.remove(arg) print "Got '%s' type" % arg # Which ids of target_type? statement['target_ids'] = [] while args[0] not in move_lexicon: id = args.pop(0) statement['target_ids'].append(id) print "Added '%s' to target list" % id else: # A normal preposition args.remove(arg) else: print "Got argument '%s'" % arg args.remove(arg) else: # Malformed subcommand printHelp('bbgun') sys.exit(0)