From 8a71cee12629b2dae04883f484dc0a6bd8cc2ca7 Mon Sep 17 00:00:00 2001 From: Amber Date: Thu, 22 Feb 2024 09:40:24 +0100 Subject: [PATCH] add include path --- src/cmdline_parser.py | 2 ++ src/tree_find.py | 13 ++++++++++++- vfind.py | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cmdline_parser.py b/src/cmdline_parser.py index 7c5bc1d..e93617f 100644 --- a/src/cmdline_parser.py +++ b/src/cmdline_parser.py @@ -15,6 +15,8 @@ cmd_parser.add_argument("-s", "--show-children-nodes", action="store_true") ## more than one occurrencies of -e option are appended in a list cmd_parser.add_argument("-e", "--exclude", action="append") +cmd_parser.add_argument("-i", "--include", action="append") + # start the command line parsing cmd_args = cmd_parser.parse_args() diff --git a/src/tree_find.py b/src/tree_find.py index 356eb6b..f2b1c7a 100644 --- a/src/tree_find.py +++ b/src/tree_find.py @@ -82,6 +82,18 @@ class NerdTreeFind(NerdTree): if not results: return {} + ## filter results + items_to_include= self.find_opts['items_to_include'] if self.find_opts.get('items_to_include') is not None else [] + if items_to_include: + filtered_results = [] + items_to_include_set = set(items_to_include) + for res in results: + pathset = set(path['name'] for path in res['path']) + if not items_to_include_set.intersection(pathset): + continue + filtered_results.append(res.copy()) + results = filtered_results + dont_show_children_nodes = self.find_opts['dont_show_children_nodes'] if self.find_opts.get('dont_show_children_nodes') is not None else False self.opts['dont_show_children_nodes'] = dont_show_children_nodes @@ -115,7 +127,6 @@ class NerdTreeFind(NerdTree): if not islastpath: children.append(pcopy) else : children.append(node) - # key size is lost in preceding code!!!!!!!!!!!! self.compute_aggregate_recursively(tree_struct) return tree_struct diff --git a/vfind.py b/vfind.py index 5baa88b..f3e744d 100755 --- a/vfind.py +++ b/vfind.py @@ -19,6 +19,7 @@ if __name__ == '__main__': find_opts = { 'dont_show_children_nodes': not show_children_nodes, 'type' : cmd_args.type, + 'items_to_include' : cmd_args.include or [], } ntree = NerdTreeFind(path, opts=opts)