<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def list_rulesets(debug):
 """ List available rulesets. """

    try:
        rulesets = get_rulesets()
        max_len = max([len(r[0]) for r in rulesets])
        for r in rulesets:
            click.echo('{0: <{1}} ({2})'.format(r[0], max_len, r[1]))
    except Exception as ex:
        logger.error("An error occurred: %r", ex)
        if debug:
            raise
        else:
            raise click.ClickException(str(ex))