From 45081d5f21b71b44e292b70c0f64bf9ac898eab8 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 23 Aug 2024 19:40:54 -0500 Subject: [PATCH] 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. --- flake-modules/dev/devshell.nix | 2 +- flake-modules/dev/list-plugins.py | 68 ++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/flake-modules/dev/devshell.nix b/flake-modules/dev/devshell.nix index 94665c40..ea0fe542 100644 --- a/flake-modules/dev/devshell.nix +++ b/flake-modules/dev/devshell.nix @@ -108,7 +108,7 @@ } { name = "list-plugins"; - command = "${pkgs.python3.interpreter} ${./list-plugins.py}"; + command = ''${pkgs.python3.interpreter} ${./list-plugins.py} "$@"''; help = "List plugins and get implementation infos"; } ]; diff --git a/flake-modules/dev/list-plugins.py b/flake-modules/dev/list-plugins.py index e7b4483b..6afcd950 100755 --- a/flake-modules/dev/list-plugins.py +++ b/flake-modules/dev/list-plugins.py @@ -1,10 +1,11 @@ #!/usr/bin/env python3 -from enum import Enum -from dataclasses import dataclass -from typing import Optional import glob import re +from argparse import ArgumentParser, RawTextHelpFormatter +from dataclasses import dataclass +from enum import Enum +from typing import Optional QUESTION_MARK = "❔" @@ -65,7 +66,7 @@ class Plugin: kind_icon = "\033[92m" + " " case _: assert False - deprecation_icon: str = "⚠️" if self.dep_warnings else " " + deprecation_icon: str = "⚠️ " if self.dep_warnings else " " return ( f"| {kind_icon}\033[0m | {state_icon} | {deprecation_icon} | {self.path}" @@ -129,25 +130,52 @@ def _is_excluded(path: str) -> bool: return True -if __name__ == "__main__": - paths: list[str] = glob.glob( - pathname="plugins/**/*.nix", - recursive=True, - ) - - filtered_paths: list[str] = list( - filter( - _is_excluded, - paths, - ) - ) +def main(args): + paths: list[str] = glob.glob(pathname="plugins/**/*.nix", recursive=True) + filtered_paths: list[str] = list(filter(_is_excluded, paths)) filtered_paths.sort() print("| Typ | Sty | DW | path") print("|-----|-----|----|--------------------------------------------------------") for plugin_path in filtered_paths: - plugin: Optional[Plugin] = parse_file( - path=plugin_path, - ) + plugin: Optional[Plugin] = parse_file(path=plugin_path) 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())