Fork me on GitHub
  ▖     
▃▀▄▄▖▄▄▖
 ▀▖     
        


#!/usr/bin/env python3
# usage: plash list-macros [ MACROLIB ]
# Lists all available macros. Pass a macro library as first parameter to list
# macros defined there.

import sys

from plash.eval import MacroError, eval, get_macros
from plash.utils import catch_and_die

try:
    import_macros = sys.argv[1]
except IndexError:
    import_macros = 'plash.macros.all'

with catch_and_die([MacroError]):
    eval([['import', import_macros]])

macros = get_macros()
prev_group = None
for name, func in sorted(
        macros.items(), key=lambda i: (i[1].__module__, i[0])):
    group = func.__module__
    if group != prev_group:
        prev_group is None or print()
        print('[{}]'.format(group))
    print('{: <16} = {}'.format(name, func.__doc__))
    prev_group = group