def build_command_tree(pattern, cmd_params):
from docopt import Either, Optional, OneOrMore, Required, Option, Command, Argument<EOL>if type(pattern) in [Either, Optional, OneOrMore]:<EOL><INDENT>for child in pattern.children:<EOL><INDENT>build_command_tree(child, cmd_params)<EOL><DEDENT><DEDENT>elif type(pattern) in [Required]:<EOL><INDENT>for child in pattern.children:<EOL><INDENT>cmd_params = build_command_tree(child, cmd_params)<EOL><DEDENT><DEDENT>elif type(pattern) in [Option]:<EOL><INDENT>suffix = "<STR_LIT:=>" if pattern.argcount else "<STR_LIT>"<EOL>if pattern.short:<EOL><INDENT>cmd_params.options.append(pattern.short + suffix)<EOL><DEDENT>if pattern.long:<EOL><INDENT>cmd_params.options.append(pattern.long + suffix)<EOL><DEDENT><DEDENT>elif type(pattern) in [Command]:<EOL><INDENT>cmd_params = cmd_params.get_subcommand(pattern.name)<EOL><DEDENT>elif type(pattern) in [Argument]:<EOL><INDENT>cmd_params.arguments.append(pattern.name)<EOL><DEDENT>return cmd_params<EOL>
Recursively fill in a command tree in cmd_params according to a docopt-parsed "pattern" object.