<s> from subcommand import Subcommand <EOL> class CommandMapApp ( object ) : <EOL> Subcommand = Subcommand <EOL> commands = { } <EOL> metavar = None <EOL> def __init__ ( self , parent ) : <EOL> self . parent = parent <EOL> self . commands = { } <EOL> def get_help ( self ) : <EOL> return "<STR_LIT>" <EOL> def get_dest ( self ) : <EOL> return '<STR_LIT>' <EOL> def get_description ( self ) : <EOL> return getattr ( self , '<STR_LIT>' , None ) <EOL> def get_title ( self ) : <EOL> return getattr ( self , '<STR_LIT:title>' , '<STR_LIT>' + getattr ( self , '<STR_LIT:title>' , self . __class__ . __name__ ) ) <EOL> def get_commands ( self ) : <EOL> return [ ] <EOL> def get_metavar ( self ) : <EOL> return self . metavar <EOL> def configure_commands ( self , parser ) : <EOL> subparsers = parser . add_subparsers ( title = self . get_title ( ) , <EOL> description = self . get_description ( ) , <EOL> help = self . get_help ( ) , <EOL> metavar = self . get_metavar ( ) , <EOL> dest = self . get_dest ( ) <EOL> ) <EOL> self . subparsers = subparsers <EOL> for ctx in self . get_commands ( ) : <EOL> self . makeSubcommand ( ctx ) <EOL> return self . commands <EOL> def selected ( self , args ) : <EOL> selected = getattr ( args , self . get_dest ( ) ) <EOL> return self . commands [ selected ] <EOL> def get ( self , name ) : <EOL> return self . commands [ name ] <EOL> def makeSubcommand ( self , ctx ) : <EOL> app = self . Subcommand ( ctx , parent = self . parent ) <EOL> parser = app . configure_subparser ( self . subparsers ) <EOL> app . configure_parser ( parser ) <EOL> self . commands [ app . name ] = app </s>
