import click
import pkg_resources

# Registered languages keyed by their names
languages = None
generators = None


def list_languages():
    """
    List all registered languages
    """
    global languages
    if languages is None:
        languages = {}
        for language in pkg_resources.iter_entry_points(
                group='textx_languages'):
            languages[language.name] = language.load()
    for language in languages.values():
        click.echo("{}({})\t\t{}".format(language.name,
                                         language.extension,
                                         language.description))


def list_generators():
    """
    List all registered generators
    """
    global generators
    if generators is None:
        generators = {}
        for generator in pkg_resources.iter_entry_points(
                group='textx_languages'):
            generator[generator.name] = generator.load()
    for generator in generators.values():
        click.echo("{}->{}\t\t{}".format(generator.language,
                                         generator.target,
                                         generator.desciption))

@@ -32,88 +32,8 @@
 es%0A%0A
-# Registered languages keyed by their names%0Alanguages = None%0Agenerators = None%0A%0A
 %0Adef
@@ -105,82 +105,8 @@
 %22%22%22%0A
-    global languages%0A    if languages is None:%0A        languages = %7B%7D%0A    
     
@@ -158,36 +158,32 @@
 ts(%0A            
-    
 group='textx_lan
@@ -200,28 +200,24 @@
         
-    
 language
 s%5Blangua
@@ -212,24 +212,8 @@
 uage
-s%5Blanguage.name%5D
  = l
@@ -231,48 +231,8 @@
 d()%0A
-    for language in languages.values():%0A
     
@@ -488,85 +488,8 @@
 %22%22%22%0A
-    global generators%0A    if generators is None:%0A        generators = %7B%7D%0A    
     
@@ -542,36 +542,32 @@
 ts(%0A            
-    
 group='textx_lan
@@ -563,33 +563,30 @@
 ='textx_
-language
+generator
 s'):%0A
-    
         
@@ -598,24 +598,8 @@
 ator
-%5Bgenerator.name%5D
  = g
@@ -618,50 +618,8 @@
 d()%0A
-    for generator in generators.values():%0A
     

Simplify list generators/languages command