<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_plugins(metadata):
 """ Return the registered plugins. Load and return all registered plugins. """

    plugins = load_plugins()
    if not plugins:
        raise NoPluginsError('No plugins found')

    results = []
    for p in sorted(plugins.get_all(), key=attrgetter('name')):
        if metadata:
            data = {'name': p.name, 'homepage': p.homepage}
            hints = getattr(p, 'hints', [])
            if hints:
                data['hints'] = hints
            results.append(data)
        else:
            results.append(p.name)
    return results