mirror of
https://github.com/httpie/cli.git
synced 2024-11-22 15:53:13 +01:00
Refactor get_formatters_grouped
This commit is contained in:
parent
4dffac7a25
commit
bd3208cf24
@ -89,6 +89,7 @@ class ConverterPlugin(BasePlugin):
|
|||||||
|
|
||||||
|
|
||||||
class FormatterPlugin(BasePlugin):
|
class FormatterPlugin(BasePlugin):
|
||||||
|
group_name = 'format'
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
from operator import attrgetter
|
||||||
from typing import Dict, List, Type
|
from typing import Dict, List, Type
|
||||||
|
|
||||||
from pkg_resources import iter_entry_points
|
from pkg_resources import iter_entry_points
|
||||||
@ -51,12 +52,11 @@ class PluginManager(list):
|
|||||||
return self.filter(FormatterPlugin)
|
return self.filter(FormatterPlugin)
|
||||||
|
|
||||||
def get_formatters_grouped(self) -> Dict[str, List[Type[FormatterPlugin]]]:
|
def get_formatters_grouped(self) -> Dict[str, List[Type[FormatterPlugin]]]:
|
||||||
groups = {}
|
return {
|
||||||
for group_name, group in groupby(
|
group_name: list(group)
|
||||||
self.get_formatters(),
|
for group_name, group
|
||||||
key=lambda p: getattr(p, 'group_name', 'format')):
|
in groupby(self.get_formatters(), key=attrgetter('group_name'))
|
||||||
groups[group_name] = list(group)
|
}
|
||||||
return groups
|
|
||||||
|
|
||||||
def get_converters(self) -> List[Type[ConverterPlugin]]:
|
def get_converters(self) -> List[Type[ConverterPlugin]]:
|
||||||
return self.filter(ConverterPlugin)
|
return self.filter(ConverterPlugin)
|
||||||
|
Loading…
Reference in New Issue
Block a user