diff options
author | gram <git@orsinium.dev> | 2023-02-28 13:25:55 +0100 |
---|---|---|
committer | gram <git@orsinium.dev> | 2023-02-28 13:25:55 +0100 |
commit | a9a436695731462eb08bed8a6255c1fd1c33023f (patch) | |
tree | de82869a8ba5685aa1c7cc7c058617e6617ab004 | |
parent | 341cafaace9654295757805a198e2fd31e15f8b8 (diff) |
basic tree impl
-rw-r--r-- | owners/commands/__init__.py | 2 | ||||
-rw-r--r-- | owners/commands/_tree.py | 30 |
2 files changed, 32 insertions, 0 deletions
diff --git a/owners/commands/__init__.py b/owners/commands/__init__.py index 730e549..a984b3b 100644 --- a/owners/commands/__init__.py +++ b/owners/commands/__init__.py @@ -5,6 +5,7 @@ from types import MappingProxyType from ._base import Command from ._owners_of import OwnersOf from ._owned_by import OwnedBy +from ._tree import Tree from ._version import Version @@ -12,6 +13,7 @@ commands: MappingProxyType[str, type[Command]] commands = MappingProxyType({ 'owned-by': OwnedBy, 'owners-of': OwnersOf, + 'tree': Tree, 'version': Version, }) diff --git a/owners/commands/_tree.py b/owners/commands/_tree.py new file mode 100644 index 0000000..2963b51 --- /dev/null +++ b/owners/commands/_tree.py @@ -0,0 +1,30 @@ +from __future__ import annotations + +from argparse import ArgumentParser +from pathlib import Path + +from ._base import Command + + +class Tree(Command): + """Show file tree with ownership info. + """ + + @staticmethod + def init_parser(parser: ArgumentParser) -> None: + Command.init_parser(parser) + + def run(self) -> int: + self._inspect(self.code_owners.root) + return 0 + + def _inspect(self, root: Path) -> None: + for path in sorted(root.iterdir()): + if not path.is_dir(): + continue + rule = self.code_owners.find_rule(path) + if rule is not None: + self.print(self.colors.green(path.name)) + continue + + self.print(self.colors.red(path.name)) |