mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
flake-modules/list-plugins: add extra filters
I have been using this more and wanted to create some filters to onlyoutput the information I cared about. This adds the ability to filter bykind, state, and whether a plugin has deprecation warnings.
This commit is contained in:
parent
3a04cc75e6
commit
45081d5f21
2 changed files with 49 additions and 21 deletions
|
@ -108,7 +108,7 @@
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "list-plugins";
|
name = "list-plugins";
|
||||||
command = "${pkgs.python3.interpreter} ${./list-plugins.py}";
|
command = ''${pkgs.python3.interpreter} ${./list-plugins.py} "$@"'';
|
||||||
help = "List plugins and get implementation infos";
|
help = "List plugins and get implementation infos";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from enum import Enum
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from typing import Optional
|
|
||||||
import glob
|
import glob
|
||||||
import re
|
import re
|
||||||
|
from argparse import ArgumentParser, RawTextHelpFormatter
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from enum import Enum
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
QUESTION_MARK = "❔"
|
QUESTION_MARK = "❔"
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ class Plugin:
|
||||||
kind_icon = "\033[92m" + " "
|
kind_icon = "\033[92m" + " "
|
||||||
case _:
|
case _:
|
||||||
assert False
|
assert False
|
||||||
deprecation_icon: str = "⚠️" if self.dep_warnings else " "
|
deprecation_icon: str = "⚠️ " if self.dep_warnings else " "
|
||||||
|
|
||||||
return (
|
return (
|
||||||
f"| {kind_icon}\033[0m | {state_icon} | {deprecation_icon} | {self.path}"
|
f"| {kind_icon}\033[0m | {state_icon} | {deprecation_icon} | {self.path}"
|
||||||
|
@ -129,25 +130,52 @@ def _is_excluded(path: str) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main(args):
|
||||||
paths: list[str] = glob.glob(
|
paths: list[str] = glob.glob(pathname="plugins/**/*.nix", recursive=True)
|
||||||
pathname="plugins/**/*.nix",
|
filtered_paths: list[str] = list(filter(_is_excluded, paths))
|
||||||
recursive=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
filtered_paths: list[str] = list(
|
|
||||||
filter(
|
|
||||||
_is_excluded,
|
|
||||||
paths,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
filtered_paths.sort()
|
filtered_paths.sort()
|
||||||
|
|
||||||
print("| Typ | Sty | DW | path")
|
print("| Typ | Sty | DW | path")
|
||||||
print("|-----|-----|----|--------------------------------------------------------")
|
print("|-----|-----|----|--------------------------------------------------------")
|
||||||
for plugin_path in filtered_paths:
|
for plugin_path in filtered_paths:
|
||||||
plugin: Optional[Plugin] = parse_file(
|
plugin: Optional[Plugin] = parse_file(path=plugin_path)
|
||||||
path=plugin_path,
|
|
||||||
)
|
|
||||||
if plugin is not None:
|
if plugin is not None:
|
||||||
print(plugin)
|
if (
|
||||||
|
(args.kind is None or plugin.kind.name.lower() == args.kind)
|
||||||
|
and (args.state is None or plugin.state.name.lower() == args.state)
|
||||||
|
and (not args.deprecation_warnings or plugin.dep_warnings)
|
||||||
|
):
|
||||||
|
print(plugin)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser: ArgumentParser = ArgumentParser(
|
||||||
|
description="""
|
||||||
|
Analyze Nixvim plugin files
|
||||||
|
Output formats a table showing:
|
||||||
|
If a plugin is written for Neovim or Vim.
|
||||||
|
If the plugin has been updated to latest style standards.
|
||||||
|
If a plugin contains any deprecation warnings.
|
||||||
|
""",
|
||||||
|
formatter_class=RawTextHelpFormatter,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-k",
|
||||||
|
"--kind",
|
||||||
|
choices=[k.name.lower() for k in Kind],
|
||||||
|
help="Filter plugins by kind (neovim, vim, misc, unknown)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-s",
|
||||||
|
"--state",
|
||||||
|
choices=[s.name.lower() for s in State],
|
||||||
|
help="Filter plugins by state (new, old, unknown)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-d",
|
||||||
|
"--deprecation-warnings",
|
||||||
|
action="store_true",
|
||||||
|
help="Show only plugins with deprecation warnings",
|
||||||
|
)
|
||||||
|
|
||||||
|
main(parser.parse_args())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue