def make_opt_parser():
 command_descriptions = []
 for name in sorted(commands.iterkeys()):
  command = commands[name]
  params = ' '.join(([('<%s>' % param) for param in command.required] + [('[<%s>]' % param) for param in command.optional]))
  command_descriptions.append(('%%prog [options] %s %s' % (name, params)))
 command_usage = ('usage: %s\n' % '\n       '.join(command_descriptions))
 parser = optparse.OptionParser(usage=command_usage)
 parser.add_option('-d', '--dest_dir', dest='dest_dir', default=os.getcwd(), help='Write generated files to DIR', metavar='DIR')
 parser.add_option('-f', '--force', action='store_true', dest='force', default=False, help='Force overwrite of existing files')
 return parser

def make_opt_parser ( ) : command_descriptions = [ ] for name in sorted ( commands . iterkeys ( ) ) : command = commands [ name ] params = ' ' . join ( ( [ ( '<%s>' % param ) for param in command . required ] + [ ( '[<%s>]' % param ) for param in command . optional ] ) ) command_descriptions . append ( ( '%%prog [options] %s %s' % ( name , params ) ) ) command_usage = ( 'usage: %s\n' % '\n       ' . join ( command_descriptions ) ) parser = optparse . OptionParser ( usage = command_usage ) parser . add_option ( '-d' , '--dest_dir' , dest = 'dest_dir' , default = os . getcwd ( ) , help = 'Write generated files to DIR' , metavar = 'DIR' ) parser . add_option ( '-f' , '--force' , action = 'store_true' , dest = 'force' , default = False , help = 'Force overwrite of existing files' ) return parser
create options parser with automatically generated command help .